Bug 29943 - [4.2/4.3 Regression] gcc generate incorrect alias symbols for PPC
Summary: [4.2/4.3 Regression] gcc generate incorrect alias symbols for PPC
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.2.0
: P1 normal
Target Milestone: 4.2.0
Assignee: Alan Modra
URL:
Keywords:
: 30796 (view as bug list)
Depends on:
Blocks:
 
Reported: 2006-11-22 16:40 UTC by Khem Raj
Modified: 2007-02-20 01:29 UTC (History)
8 users (show)

See Also:
Host:
Target: powerpc-*-linux-gnu
Build:
Known to work: 4.1.2 4.1.1
Known to fail: 4.2.0
Last reconfirmed: 2007-02-20 01:28:56


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Khem Raj 2006-11-22 16:40:09 UTC
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.
Comment 1 Alan Modra 2006-11-22 22:21:39 UTC
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
Comment 2 Alan Modra 2006-11-22 22:27:13 UTC
Removing __attribute__ ((section (".data.rel.ro"))) from _dl_argv_internal also generates good code.
Comment 3 Andrew Pinski 2006-11-22 22:30:52 UTC
.data.rel.ro, isn't that a special section?
Comment 4 Alan Modra 2006-11-22 22:41:37 UTC
Not particularly.  s/.data.rel.ro/.mysect/ does the same thing.
Comment 5 David Edelsohn 2006-11-23 02:31:00 UTC
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.
Comment 6 richard@codesourcery.com 2006-11-23 05:04:51 UTC
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
Comment 7 Alan Modra 2006-11-23 08:01:31 UTC
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.
Comment 8 patchapp@dberlin.org 2006-11-23 12:45:27 UTC
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
Comment 9 Andreas Schwab 2007-01-15 13:38:39 UTC
Any news on this one?  AFAICS Richard Sandiford was ok with the patch.
Comment 10 Arkadiusz Miskiewicz 2007-02-14 20:25:20 UTC
*** Bug 30796 has been marked as a duplicate of this bug. ***
Comment 11 Mark Mitchell 2007-02-19 20:45:24 UTC
Alan --

This patch is OK.  Would you please apply to 4.2 and mainline?

Thanks,

-- Mark
Comment 12 Alan Modra 2007-02-20 01:25:51 UTC
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

Comment 13 Alan Modra 2007-02-20 01:28:11 UTC
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

Comment 14 Alan Modra 2007-02-20 01:29:27 UTC
Patch applied