Subject: toolchain/16848: gcc bug on sparc
To: None <gnats-bugs@gnats.netbsd.org>
From: None <dmcmahill@netbsd.org>
List: netbsd-bugs
Date: 05/16/2002 16:57:31
>Number:         16848
>Category:       toolchain
>Synopsis:       gcc bug on sparc
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    toolchain-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu May 16 13:58:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Dan McMahill
>Release:        1.4, 1.5, and -current (may 2002)<NetBSD-current source date>
>Organization:

>Environment:
	
System: NetBSD torricelli 1.5.1_ALPHA NetBSD 1.5.1_ALPHA (TORR) #5: Sun Apr 8 10:08:37 EDT 2001 mcmahill@torricelli:/usr/cvs/syssrc/sys/arch/sparc/compile/TORR sparc


>Description:

gcc on sparc appears to have a stack corrupting bug.  The symptom is that I have a package
which creates a shared library and then links to it.  I get segfaults on sparc's.  I've
tried this on 1.4.3, 1.5.1, and someone else verified on -current sparc.  I have no problems
on alpha, arm32, i386, mipsel, m68k, ppc.

If the library is statically linked (and compiled without -fPIC) instead, no segfaults.
If the library is compiled -O0 (instead of -O2), no segfaults.
If I add a printf in the code, no segfaults.
If I make one of my local variables be static, no segfaults.


The file in question produces:

a.out version
-------------

ic_microstrip.lo:     file format a.out-sparc-netbsd

Disassembly of section .text:

00000000 <___gnu_compiled_c>:
       0:       81 c3 e0 08 ae 03 c0 17                             ........

00000008 <_ic_microstrip_calc>:
       8:       9d e3 bf 00     save  %sp, -256, %sp
       c:       25 00 00 00     sethi  %hi(0), %l2
      10:       a4 14 a0 00     mov  %l2, %l2   ! 0 <___gnu_compiled_c>
      14:       e4 05 c0 12     ld  [ %l7 + %l2 ], %l2      

                                      ^^^^^^ l7 used uninitialized here

      18:       13 00 00 00     sethi  %hi(0), %o1
      1c:       d5 1c 80 00     ldd  [ %l2 ], %f10
      20:       2f 00 00 00     sethi  %hi(0), %l7


Elf version:
------------

ic_microstrip.lo:     file format elf32-sparc

Disassembly of section .text:

00000000 <.LLtext0>:
       0:       81 c3 e0 08     retl 
       4:       ae 03 c0 17     add  %o7, %l7, %l7

00000008 <ic_microstrip_calc>:
       8:       9d e3 bf 00     save  %sp, -256, %sp
       c:       25 00 00 00     sethi  %hi(0), %l2
      10:       a4 14 a0 00     mov  %l2, %l2   ! 0 <.LLtext0>
      14:       e4 05 c0 12     ld  [ %l7 + %l2 ], %l2

                                      ^^^^^^ l7 used uninitialized here

      18:       13 00 00 00     sethi  %hi(0), %o1
      1c:       d5 1c 80 00     ldd  [ %l2 ], %f10
      20:       2f 00 00 00     sethi  %hi(0), %l7




	
>How-To-Repeat:

download nbftp:/home/dmcmahill/wcalc-0.3.tar.gz (I didn't put it in
a location accessible to the general public since I'm not ready to
release all of the code in there yet.  Other pieces need more work).

Extract it and configure with:

./configure --disable-gtk --disable-cgi --without-scilab --without-matlab
gmake
./libwcalc/ic_microstrip_test

You'll get a segfault.  Then try

./configure CFLAGS="-g" --disable-gtk --disable-cgi --without-scilab --without-matlab
touch libwcalc/ic_microstrip.c
gmake
./libwcalc/ic_microstrip_test


now no segfault.  You can also try making mu0 and e0 on line 107 of ic_microstrip.c be static doubles.

	
>Fix:
workaround:  declare mu0,e0 as static or reduce optimization level for that file
on sparc.

fix: unknown
	
>Release-Note:
>Audit-Trail:
>Unformatted: