The following example(reduced from glibc) compiles differently for ppc target when using gcc 4.2 as compared to gcc 4.1 It generates the alias symbol as a real symbol instead of creating it as alias. I get this correct using gcc 4.2 for arm so the problem seems to be affecting only ppc. This also works ok with gcc 4.1 to reproduce compile the example with -O2 testcase.c ======================================================== extern char **_dl_argv __attribute__ ((section (".data.rel.ro"))) ; extern char **_dl_argv_internal __attribute__ ((visibility ("hidden"))) __attribute__ ((section (".data.rel.ro"))) ; char **_dl_argv __attribute__ ((section (".data.rel.ro"))) = ((void *)0); extern __typeof (_dl_argv) _dl_argv_internal __attribute__ ((alias ("_dl_argv"))); char* foo (){ return _dl_argv_internal[0]; } ===================================== glibc segfaults in ld.so currently when compiled with gcc 4.2 for ppc due to this issue.
relevant -O2 assembly is .globl _dl_argv .globl _dl_argv_internal .hidden _dl_argv_internal .set _dl_argv_internal,_dl_argv .section .data.rel.ro,"aw",@progbits .align 2 .set .LANCHOR0,. + 0 .type _dl_argv_internal, @object .size _dl_argv_internal, 4 _dl_argv_internal: .zero 4 .type _dl_argv, @object .size _dl_argv, 4 _dl_argv: .zero 4 -fno-section-anchors generates good code
Removing __attribute__ ((section (".data.rel.ro"))) from _dl_argv_internal also generates good code.
.data.rel.ro, isn't that a special section?
Not particularly. s/.data.rel.ro/.mysect/ does the same thing.
If GCC is not creating the alias correctly, that is a bug. However, we previously agreed in PR 28598 that changing sections behind GCC's back is not guaranteed to work.
Subject: Re: [4.2/4.3 Regression] gcc generate incorrect alias symbols for PPC "amodra at bigpond dot net dot au" <gcc-bugzilla@gcc.gnu.org> writes: > AssignedTo|unassigned at gcc dot gnu |amodra at bigpond dot net > |dot org |dot au Thanks for taking this Alan. I'm happy to look at it if you like though. If it's section-anchor related, then it's my bug. Richard
This is the simple patch I've bootstrapped and am currently regression testing. Index: varasm.c =================================================================== --- varasm.c (revision 119100) +++ varasm.c (working copy) @@ -981,6 +981,10 @@ use_blocks_for_decl_p (tree decl) if (DECL_INITIAL (decl) == decl) return false; + /* If this decl is an alias, then we don't want to emit a definition. */ + if (lookup_attribute ("alias", DECL_ATTRIBUTES (decl))) + return false; + return true; } Another possibility is to check for named sections in handle_alias_attribute (and alias attributes in handle_section_attribute), possibly giving a diagnostic. It's clear that code like extern int a __attribute__ ((section (".sec1"))); extern int b __attribute__ ((section (".sec2"))) __attribute__ ((alias ("a"))); is invalid; b can't alias a and be in a different section. However, from the previous discussion over 28598 I gather we don't want to go down the path of checking section attributes.
Subject: Bug number PR29943 A patch for this bug has been added to the patch tracker. The mailing list url for the patch is http://gcc.gnu.org/ml/gcc-patches/2006-11/msg01613.html
Any news on this one? AFAICS Richard Sandiford was ok with the patch.
*** Bug 30796 has been marked as a duplicate of this bug. ***
Alan -- This patch is OK. Would you please apply to 4.2 and mainline? Thanks, -- Mark
Subject: Bug 29943 Author: amodra Date: Tue Feb 20 01:25:41 2007 New Revision: 122148 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=122148 Log: PR target/29943 * varasm.c (use_blocks_for_decl_p): Return false for decls with alias attribute. Modified: trunk/gcc/ChangeLog trunk/gcc/varasm.c
Subject: Bug 29943 Author: amodra Date: Tue Feb 20 01:28:01 2007 New Revision: 122149 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=122149 Log: PR target/29943 * varasm.c (use_blocks_for_decl_p): Return false for decls with alias attribute. Modified: branches/gcc-4_2-branch/gcc/ChangeLog branches/gcc-4_2-branch/gcc/varasm.c
Patch applied