Bug 11397 - [3.3 Regression] weak aliases broken on Tru64 UNIX
Summary: [3.3 Regression] weak aliases broken on Tru64 UNIX
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 3.4.0
: P2 normal
Target Milestone: 3.3.3
Assignee: Not yet assigned to anyone
URL:
Keywords: patch, wrong-code
Depends on:
Blocks:
 
Reported: 2003-07-01 20:48 UTC by Rainer Orth
Modified: 2004-01-12 19:56 UTC (History)
1 user (show)

See Also:
Host:
Target: alpha-dec-osf5.1
Build:
Known to work:
Known to fail:
Last reconfirmed: 2003-07-18 22:45:08


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Rainer Orth 2003-07-01 20:48:41 UTC
Consider the following input files:

m.i:

int a (void);

int
main (void)
{
  return a ();
}

wa.i:

int a (void) __attribute__ ((weak, alias ("__a")));

int
__a (void)
{
  return 0;
}

With both 3.3 and current mainline, this fails to link:

> ./xgcc -B./ -v -o m m.i wa.i
Reading specs from ./specs
Configured with: /vol/gnu/src/gcc/gcc-dist/configure --prefix=/vol/gcc --with-local-prefix=/vol/gcc --disable-nls alpha-dec-osf5.1
Thread model: single
gcc version 3.4 20030626 (experimental)
 ./cc1 -fpreprocessed m.i -quiet -dumpbase m.i -auxbase m -version -o /tmp//cccnWQFq.s
GNU C version 3.4 20030626 (experimental) (alpha-dec-osf5.1)
        compiled by GNU C version 3.4 20030626 (experimental).
GGC heuristics: --param ggc-min-expand=38 --param ggc-min-heapsize=16384
 as -g -oldas -c -nocpp -O0 -o /tmp//ccdvLGmI.o /tmp//cccnWQFq.s
 ./mips-tfile -v -o /tmp//ccdvLGmI.o /tmp//cccnWQFq.s
mips-tfile (GCC) 3.4 20030626 (experimental)
 ./cc1 -fpreprocessed wa.i -quiet -dumpbase wa.i -auxbase wa -version -o /tmp//cccnWQFq.s
GNU C version 3.4 20030626 (experimental) (alpha-dec-osf5.1)
        compiled by GNU C version 3.4 20030626 (experimental).
GGC heuristics: --param ggc-min-expand=38 --param ggc-min-heapsize=16384
 as -g -oldas -c -nocpp -O0 -o /tmp//ccjaZJjD.o /tmp//cccnWQFq.s
 ./mips-tfile -v -o /tmp//ccjaZJjD.o /tmp//cccnWQFq.s
mips-tfile (GCC) 3.4 20030626 (experimental)
 ./collect2 -G 8 -O1 -S -call_shared -o m /usr/lib/cmplrs/cc/crt0.o -L. -L/usr/lib/cmplrs/cc -L/vol/gcc/lib /tmp//ccdvLGmI.o /tmp//ccjaZJjD.o -lgcc -lgcc_eh -lc -lgcc -lgcc_eh
a
collect2: ld returned 1 exit status

whereas it links successfully with gcc 3.1:

> gcc -v -o m m.i wa.i
Reading specs from /vol/gnu/lib/gcc-lib/alpha-dec-osf5.1/3.1/specs
Configured with: /vol/gnu/src/gcc/gcc-3.1/configure --prefix=/vol/gnu --with-local-prefix=/vol/gnu --disable-nls alpha-dec-osf5.1
Thread model: single
gcc version 3.1
 /vol/gnu/lib/gcc-lib/alpha-dec-osf5.1/3.1/cc1 -fpreprocessed m.i -quiet -dumpbase m.i -version -o /tmp//ccDh0jFF.s
GNU CPP version 3.1 (cpplib)
GNU C version 3.1 (alpha-dec-osf5.1)
        compiled by GNU C version 3.1.
 as -g -oldas -c -nocpp -O0 -o /tmp//ccLhc2lX.o /tmp//ccDh0jFF.s
 /vol/gnu/lib/gcc-lib/alpha-dec-osf5.1/3.1/mips-tfile -v -o /tmp//ccLhc2lX.o /tmp//ccDh0jFF.s
mips-tfile version 3.1
 /vol/gnu/lib/gcc-lib/alpha-dec-osf5.1/3.1/cc1 -fpreprocessed wa.i -quiet -dumpbase wa.i -version -o /tmp//ccDh0jFF.s
GNU CPP version 3.1 (cpplib)
GNU C version 3.1 (alpha-dec-osf5.1)
        compiled by GNU C version 3.1.
 as -g -oldas -c -nocpp -O0 -o /tmp//ccRGHlct.o /tmp//ccDh0jFF.s
 /vol/gnu/lib/gcc-lib/alpha-dec-osf5.1/3.1/mips-tfile -v -o /tmp//ccRGHlct.o /tmp//ccDh0jFF.s
mips-tfile version 3.1
 /vol/gnu/lib/gcc-lib/alpha-dec-osf5.1/3.1/collect2 -G 8 -O1 -S -call_shared -o m /usr/lib/cmplrs/cc/crt0.o -L/vol/gnu/lib/gcc-lib/alpha-dec-osf5.1/3.1 -L/usr/lib/cmplrs/cc -L/vol/gnu/lib/gcc-lib/alpha-dec-osf5.1/3.1/../../.. /tmp//ccLhc2lX.o /tmp//ccRGHlct.o -lgcc -lgcc_eh -lc -lgcc -lgcc_eh

Environment:
System: OSF1 bartok V5.1 732 alpha
Machine: alpha
	
host: alpha-dec-osf5.1
build: alpha-dec-osf5.1
target: alpha-dec-osf5.1
configured with: /vol/gnu/src/gcc/gcc-dist/configure --prefix=/vol/gcc --with-local-prefix=/vol/gcc --disable-nls alpha-dec-osf5.1

How-To-Repeat:
Compile/link the test files above.
Comment 1 Rainer Orth 2003-07-01 20:48:41 UTC
Fix:
Examining the assembler output for both compiler versions, I find that gcc
3.4 emits an additional (and superfluous) .weakext pseudo-opcode:

--- wa.s31      Tue Jul  1 22:43:18 2003
+++ wa.s34      Tue Jul  1 22:43:26 2003
@@ -0,0 +1 @@
+       .file   1 "wa.i"
@@ -6 +6,0 @@
-       .file   1 "wa.i"
@@ -22,2 +22 @@
-       bis $31,$31,$1
-       bis $31,$1,$0
+       bis $31,$31,$0
@@ -29,0 +29,2 @@
+       .globl a
+       .weakext        a

It now contains two of those:

        .weakext        a __a
        .weakext        a

Removing the additional one fixes the problem.  The second .weakext is
emitted by varasm.c (weak_finish), while the first (correct) one is from
varasm.c (globalize_decl).  That function should have removed it from
weak_decls, but fails for some reason.
Comment 2 Dara Hazeghi 2003-07-18 22:45:08 UTC
Confirmed with 3.3 branch.
Comment 3 Andrew Pinski 2003-11-10 08:36:35 UTC
Rainer, do you know if this still exist?
Comment 4 roger 2003-12-07 03:04:53 UTC
The sequence of events appears to be that we call declare_weak with the
function decl of "a", which then gets added to the weak_decls list.
Next we call assemble_alias with the same decl for "a", which calls
make_decl_rtl which sets the DECL's assember name to "a" and it is this
function, not globalize_decl which generates the ".weakext a __a".
At this point, from what I can see a's decl doesn't mention __a!

Next we call globalize_decl on the decl for __a, which doesn't have the
DECL_WEAK flag set!  Even if it did its' assembler name is "__a" and
the only entry on the weak_decls list has an assembler name of "a", so
they don't match.  Either way the decl for "a" is left on the weak_decls
list.

Finally, we call weak_finish, which discovers that the weak_decls list
contains a single decl, "a", which it writes out without alias information.
Hence the second ".weakent a" which screws things up.

I have absolutely no idea what the intended sequence of events and data
structure invariants is supposed to be, but I'm happy to provide
alphaev67-dec-osf5.1 feedback to anyone who does!
Comment 5 Gabriel Dos Reis 2003-12-21 20:27:05 UTC
Is anyone interested in Roger's offer?
Comment 6 Jim Wilson 2004-01-06 07:52:57 UTC
See http://gcc.gnu.org/ml/gcc/2004-01/msg00329.html for a response to Roger's
analysis.
Comment 7 Andrew Pinski 2004-01-12 06:02:58 UTC
Patch here: <http://gcc.gnu.org/ml/gcc-patches/2004-01/msg00931.html>.
Comment 8 CVS Commits 2004-01-12 17:22:17 UTC
Subject: Bug 11397

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	sayle@gcc.gnu.org	2004-01-12 17:22:12

Modified files:
	gcc            : ChangeLog varasm.c 
	gcc/testsuite  : ChangeLog 
	gcc/testsuite/gcc.dg/special: wkali-2.c 

Log message:
	PR middle-end/11397
	* varasm.c (assemble_alias): Remove weak aliases from weak_decls.
	
	* gcc.dg/special/wkali-2.c: Add dg-require-alias.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.2241&r2=2.2242
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/varasm.c.diff?cvsroot=gcc&r1=1.402&r2=1.403
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.3364&r2=1.3365
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/special/wkali-2.c.diff?cvsroot=gcc&r1=1.4&r2=1.5

Comment 9 Andrew Pinski 2004-01-12 17:32:44 UTC
Only a 3.3.3 regression now.
Comment 10 CVS Commits 2004-01-12 18:23:17 UTC
Subject: Bug 11397

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_3-branch
Changes by:	sayle@gcc.gnu.org	2004-01-12 18:23:14

Modified files:
	gcc            : ChangeLog varasm.c 

Log message:
	PR middle-end/11397
	* varasm.c (assemble_alias): Remove weak aliases from weak_decls.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.16114.2.876&r2=1.16114.2.877
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/varasm.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.324.2.9&r2=1.324.2.10

Comment 11 Andrew Pinski 2004-01-12 19:56:50 UTC
Fixed also for 3.3.3.