NetBSD Problem Report #5248

Received: (qmail 6208 invoked from network); 3 Apr 1998 04:32:53 -0000
Message-Id: <199804030419.NAA00974@lpux0.pdd.ssd.ricoh.co.jp>
Date: Fri, 3 Apr 1998 13:19:44 +0900 (JST)
From: Noriyuki Shiota <shiota@pdd.ssd.ricoh.co.jp>
Reply-To: shiota@pdd.ssd.ricoh.co.jp
To: gnats-bugs@gnats.netbsd.org
Subject: user profiling is broken on mips
X-Send-Pr-Version: 3.95

>Number:         5248
>Category:       port-mips
>Synopsis:       user profiling is broken on mips
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    port-mips-maintainer
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Apr 02 20:35:00 +0000 1998
>Closed-Date:    Fri Jan 04 22:07:37 +0000 2002
>Last-Modified:  Fri Jan 04 22:07:37 +0000 2002
>Originator:     Noriyuki Shiota
>Release:        1.3
>Organization:
Ricoh Co., Ltd.
>Environment:
original port based on NetBSD-1.3-pmax
>Description:
	Profiled object dumps core.
>How-To-Repeat:
	Excute object compiled with -pg and linked with gcrt0.o.
>Fix:
On profiling, gcc inserts the following code at the beginning of procedure:

	move	$at, $ra
	jal	_mcount
	subu	$sp, $sp, 8

"subu" instruction is placed on the delayed slot of "jal".
But gas produces the following for "jal _mcount" on .abicalls case:

	lw	$t9, -32680($gp)	; _mcount
	nop
	jalr	$t9
	nop
	lw	$gp,16($sp)
	nop

In this case, "jalr" and "subu" are not excuted in intended order.

*** gnu/usr.bin/gcc/arch/mips/mips.h	1998/02/20 13:15:16	1.1
--- gnu/usr.bin/gcc/arch/mips/mips.h	1998/02/20 13:15:35
***************
*** 2070,2082 ****
    fprintf (FILE, "\t.set\tnoat\n");					\
    fprintf (FILE, "\tmove\t%s,%s\t\t# save current return address\n",	\
  	   reg_names[GP_REG_FIRST + 1], reg_names[GP_REG_FIRST + 31]);	\
-   fprintf (FILE, "\tjal\t_mcount\n");					\
    fprintf (FILE,							\
  	   "\t%s\t%s,%s,%d\t\t# _mcount pops 2 words from  stack\n",	\
  	   TARGET_64BIT ? "dsubu" : "subu",				\
  	   reg_names[STACK_POINTER_REGNUM],				\
  	   reg_names[STACK_POINTER_REGNUM],				\
  	   TARGET_LONG64 ? 16 : 8);					\
    fprintf (FILE, "\t.set\treorder\n");					\
    fprintf (FILE, "\t.set\tat\n");					\
  }
--- 2070,2083 ----
    fprintf (FILE, "\t.set\tnoat\n");					\
    fprintf (FILE, "\tmove\t%s,%s\t\t# save current return address\n",	\
  	   reg_names[GP_REG_FIRST + 1], reg_names[GP_REG_FIRST + 31]);	\
    fprintf (FILE,							\
  	   "\t%s\t%s,%s,%d\t\t# _mcount pops 2 words from  stack\n",	\
  	   TARGET_64BIT ? "dsubu" : "subu",				\
  	   reg_names[STACK_POINTER_REGNUM],				\
  	   reg_names[STACK_POINTER_REGNUM],				\
  	   TARGET_LONG64 ? 16 : 8);					\
+   fprintf (FILE, "\tjal\t_mcount\n");					\
+   fprintf (FILE, "\tnop\n");						\
    fprintf (FILE, "\t.set\treorder\n");					\
    fprintf (FILE, "\t.set\tat\n");					\
  }
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: gnats-admin->port-mips-maintainer 
Responsible-Changed-By: fair 
Responsible-Changed-When: Mon Dec 28 12:00:15 PST 1998 
Responsible-Changed-Why:  
This PR is the responsibility of the portmaster, 
not the GNATS database administrator. 

From: Jonathan Stone <jonathan@DSG.Stanford.EDU>
To: gnats-bugs@netbsd.org
Cc:  Subject: port-mips/5248
Date: Tue, 26 Jan 1999 18:16:00 -0800

 hi,

 Thank you for the problem report.   The description and anaylsis
 are very clear.

 I think the fundamental problem is that the instructions emitted by
 that fragment of C code had been hand-scheduled, back when we did only
 static linking and we weren't using abicalls.

 The simplest answer is to put them back into the "natural" order, and
 either put in the nop (as you did).

 Or, perhaps,, leave ".set reorder" in effect for the fragment. (i dont
 know if gas could move code in front of the _mcount call: that would
 skew statistics).

 Could you please try that and confirm that it works?
 I'd like to get this fixed for the 1.3.4 release.
 thanks

 --Jonathan
State-Changed-From-To: open->closed 
State-Changed-By: thorpej 
State-Changed-When: Fri Jan 4 14:07:11 PST 2002 
State-Changed-Why:  
Fixed in new-toolchain. 
>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.