Bug 6123 - __pic__/__PIC__ not defined when -fpic/-fPIC is specified
Summary: __pic__/__PIC__ not defined when -fpic/-fPIC is specified
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 3.1
: P3 enhancement
Target Milestone: 4.0.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on: 18382
Blocks:
  Show dependency treegraph
 
Reported: 2002-04-01 10:36 UTC by Kaveh Ghazi
Modified: 2010-10-27 16:51 UTC (History)
5 users (show)

See Also:
Host: sparc-sun-solaris2.*
Target: sparc-sun-solaris2.*
Build: sparc-sun-solaris2.*
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kaveh Ghazi 2002-04-01 10:36:00 UTC
When running the testsuite with -fPIC/-fpic I get this additional failure:

FAIL: gcc.dg/20020312-2.c (test for excess errors)
Excess errors:
/tmp/.foo/branch/egcc-3.1-CVS20020401/gcc/testsuite/gcc.dg/20020312-2.c:129: Internal compiler error in verify_local_live_at_start, at flow.c:609

(I'm not sure if you need checking enabled for verify_local_live_at_start to be called.)

Anyway, its obvious from the testcase that it wasn't meant to be run with -fpic or -fPIC and it specifically passes -fno-pic.  But apparently the extra pass flags are appended to the command line so they override -fno-pic.  Nevertheless I think there should be someway to work around the error such as checking for __PIC__/__pic__, but only some platforms define these macros with -fpic/-fPIC.  Its very inconsistent...

Release:
gcc version 3.1 20020331 (prerelease)

Environment:
sparc-sun-solaris2.7 native as/ld

How-To-Repeat:
Bootstrap on solaris2.7 and run the testsuite with -fpic or -fPIC
Comment 1 Kaveh Ghazi 2002-04-01 10:36:00 UTC
Fix:
A partial fix was applied by adjusting the testcase to check __pic__/__PIC__:
http://gcc.gnu.org/ml/gcc-patches/2002-04/msg00114.html
However solaris2 and many other platforms don't define them (yet.)
Comment 2 Jakub Jelinek 2002-04-04 12:37:25 UTC
From: jakub@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: c/6123
Date: 4 Apr 2002 12:37:25 -0000

 CVSROOT:	/cvs/gcc
 Module name:	egcs
 Branch: 	gcc-3_1-branch
 Changes by:	jakub@gcc.gnu.org	2002-04-04 04:37:25
 
 Modified files:
 	gcc/testsuite  : ChangeLog 
 	gcc/testsuite/gcc.dg: 20020312-2.c 
 
 Log message:
 	PR c/6123
 	* gcc.dg/20020312-2.c: Do not declare global register variable
 	if __PIC__ or __pic__ is defined.
 
 Patches:
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/egcs/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_1-branch&r1=1.1672.2.74&r2=1.1672.2.75
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/egcs/gcc/testsuite/gcc.dg/20020312-2.c.diff?cvsroot=gcc&only_with_tag=gcc-3_1-branch&r1=1.1.2.3&r2=1.1.2.4
 

Comment 3 Jakub Jelinek 2002-04-04 12:47:48 UTC
From: jakub@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: c/6123
Date: 4 Apr 2002 12:47:48 -0000

 CVSROOT:	/cvs/gcc
 Module name:	egcs
 Changes by:	jakub@gcc.gnu.org	2002-04-04 04:47:46
 
 Modified files:
 	gcc/testsuite  : ChangeLog 
 	gcc/testsuite/gcc.dg: 20020312-2.c 
 
 Log message:
 	PR c/6123
 	* gcc.dg/20020312-2.c: Do not declare global register variable
 	if __PIC__ or __pic__ is defined.
 
 Patches:
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/egcs/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.1784&r2=1.1785
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/egcs/gcc/testsuite/gcc.dg/20020312-2.c.diff?cvsroot=gcc&r1=1.5&r2=1.6
 

Comment 4 Wolfgang Bangerth 2002-11-26 07:33:54 UTC
State-Changed-From-To: open->analyzed
State-Changed-Why: Christian confirmed this with a small testcase.
    
    I am a little bit confused, though: the audit trail shows
    patches have been applied. Yet, the problem still exists?
    What is the status of these patches?
Comment 5 Christian Ehrhardt 2002-11-26 13:19:28 UTC
From: "Christian Ehrhardt" <ehrhardt@mathematik.uni-ulm.de>
To: gcc-gnats@gcc.gnu.org, gcc-prs@gcc.gnu.org, gcc-bugs@gcc.gnu.org,
  nobody@gcc.gnu.org, ghazi@caip.rutgers.edu
Cc:  
Subject: Re: c/6123: sparc-sun-solaris2.7 gcc-3.1 C testsuite failure in verify_local_live_at_start w/-fpic|-fPIC on gcc.dg/20020312-2.c
Date: Tue, 26 Nov 2002 13:19:28 +0100

 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=6123
 
 Hi,
 
 I can confirm this on sparc with GNU-ld and on linux. A minimal example
 for the sparc i386 case is this (compile with gcc -O -fpic to get the ICE):
 
 register void *reg __asm__("ebx");
 
 void f (void)
 {
   goto *(&&bar);
     foo:
       reg = (void *) 1;
       if (!reg)
         goto bar;
       reg = &&foo;
 
  bar:
  baz:
   reg = 0;
 }
 
 Replace ebx with l7 on sparc.
 
     regards   Christian
 
 -- 
 THAT'S ALL FOLKS!
Comment 6 Kaveh Ghazi 2002-11-26 23:01:39 UTC
From: "Kaveh R. Ghazi" <ghazi@caip.rutgers.edu>
To: bangerth@dealii.org, ehrhardt@mathematik.uni-ulm.de, gcc-bugs@gcc.gnu.org,
        gcc-gnats@gcc.gnu.org, gcc-prs@gcc.gnu.org, jakub@gcc.gnu.org,
        nobody@gcc.gnu.org
Cc:  
Subject: Re: c/6123: sparc-sun-solaris2.7 gcc-3.1 C testsuite failure in verify_local_live_at_start w/-fpic|-fPIC on gcc.dg/20020312-2.c
Date: Tue, 26 Nov 2002 23:01:39 -0500 (EST)

  > From: bangerth@dealii.org
  > 
  >     I am a little bit confused, though: the audit trail shows
  >     patches have been applied. Yet, the problem still exists?
  >     What is the status of these patches?
 
 Jakub's patch (which was installed) fixes the error if the target
 platform defines __pic__/__PIC__ when -fpic/-fPIC is enabled.  Most
 targets don't.  I suggested that we should do this globally here:
 http://gcc.gnu.org/ml/gcc-patches/2002-04/msg00168.html
 
 In another discussion, rth suggested we should do this also:
 http://gcc.gnu.org/ml/gcc-patches/2002-06/msg00093.html
 
 I agree and patches to accomplish this would be much appreciated.
 
 		--Kaveh
 --
 Kaveh R. Ghazi			ghazi@caip.rutgers.edu

Comment 7 Christian Ehrhardt 2002-11-27 10:42:15 UTC
From: "Christian Ehrhardt" <ehrhardt@mathematik.uni-ulm.de>
To: "Kaveh R. Ghazi" <ghazi@caip.rutgers.edu>
Cc: bangerth@dealii.org, gcc-bugs@gcc.gnu.org, gcc-gnats@gcc.gnu.org,
  gcc-prs@gcc.gnu.org, jakub@gcc.gnu.org, nobody@gcc.gnu.org
Subject: Re: c/6123: sparc-sun-solaris2.7 gcc-3.1 C testsuite failure in verify_local_live_at_start w/-fpic|-fPIC on gcc.dg/20020312-2.c
Date: Wed, 27 Nov 2002 10:42:15 +0100

 On Tue, Nov 26, 2002 at 11:01:39PM -0500, Kaveh R. Ghazi wrote:
 >  > From: bangerth@dealii.org
 >  > 
 >  >     I am a little bit confused, though: the audit trail shows
 >  >     patches have been applied. Yet, the problem still exists?
 >  >     What is the status of these patches?
 > 
 > Jakub's patch (which was installed) fixes the error if the target
 > platform defines __pic__/__PIC__ when -fpic/-fPIC is enabled.  Most
 
 To get this straight: These patches are about fixing the testcase to
 not produce an ICE if it is compiled with flags that it wasn't supposed
 to be compiled with. IMHO the right solution is to fix the compiler ;-)
 
     regards   Christian
 
 -- 
 THAT'S ALL FOLKS!

Comment 8 Kaveh Ghazi 2002-11-27 21:27:55 UTC
From: "Kaveh R. Ghazi" <ghazi@caip.rutgers.edu>
To: ehrhardt@mathematik.uni-ulm.de
Cc: bangerth@dealii.org, gcc-bugs@gcc.gnu.org, gcc-gnats@gcc.gnu.org,
        gcc-prs@gcc.gnu.org, jakub@gcc.gnu.org, nobody@gcc.gnu.org
Subject: Re: c/6123: sparc-sun-solaris2.7 gcc-3.1 C testsuite failure in verify_local_live_at_start w/-fpic|-fPIC on gcc.dg/20020312-2.c
Date: Wed, 27 Nov 2002 21:27:55 -0500 (EST)

  > From: "Christian Ehrhardt" <ehrhardt@mathematik.uni-ulm.de>
  > 
  > To get this straight: These patches are about fixing the testcase to
  > not produce an ICE if it is compiled with flags that it wasn't supposed
  > to be compiled with. IMHO the right solution is to fix the compiler ;-)
 
 Yes, and that "fix" is to globally define __pic__ or __PIC__ in the
 compiler for all targets when using -fpic or -fPIC.
 
 True, the testcase isn't supposed to work with -fpic/-fPIC, but we
 should have a graceful way in the compiler to detect and elide this so
 we can run -fpic/-fPIC testsuite passes without getting noise.
 
 It's very important that -fpic/-fPIC be as reliable as possible given
 how much GNU systems rely on shared libraries, etc.
 
 		--Kaveh
 --
 Kaveh R. Ghazi			ghazi@caip.rutgers.edu
Comment 9 Dara Hazeghi 2003-06-05 03:37:51 UTC
Confirmed with gcc 3.2. With gcc 3.3 (branch) on i686-linux and Christian's testcase, I get:

/tmp/ccS0QCPS.s: Assembler messages:
/tmp/ccS0QCPS.s:20: Error: suffix or operands invalid for `lea'

With mainline, the testcase compiles and assembles fine.

On cross-compiler to SPARC, Christian's testcase compiles fine with gcc 3.3 branch and mainline 
(20030604).

Does this mean this bug has been fixed? Thanks,

Dara

Comment 10 Kaveh Ghazi 2003-06-09 05:57:27 UTC
The problem persists.
http://gcc.gnu.org/ml/gcc-testresults/2003-06/msg00487.html
Comment 11 Eric Botcazou 2004-07-10 20:00:34 UTC
Corrected summary to advertise a more accurate description.
Comment 12 Andrew Pinski 2004-10-09 00:31:16 UTC
This is a target problem.
Comment 13 Zack Weinberg 2004-11-08 20:37:04 UTC
I've filed bug 18382 for the general solution to this problem.
Comment 14 kghazi@verizon.net 2004-11-08 20:45:21 UTC
Subject: Re:  __pic__/__PIC__ not defined when -fpic/-fPIC is specified

I submitted a patch to fix this back in April:

http://gcc.gnu.org/ml/gcc-patches/2004-04.argh/msg00168.html

Comment 15 Zack Weinberg 2004-11-08 21:23:58 UTC
Subject: Re:  __pic__/__PIC__ not defined when -fpic/-fPIC is specified


Ah.  This is why I thought it had already been done.  Maybe you want
to poke Alan Modra about the research he said he would do?

zw
Comment 16 Alan Modra 2004-11-10 05:07:38 UTC
I made the following reply the day after I said I'd poke around.  Somehow it
seems to be missing from the gcc-patches archive.  Anyway, here it is again:


I grepped through the entire slackware linux source base for occurrences
of __PIC__, and found that all those that might affect PowerPC64 were
testing for (b).  There were only three occurrences, all in glibc!  Many
more for x86 which I didn't pay much attention to, but the few I did
look at were actually testing for (a).  This isn't so surprising, since
on x86 we want different assembly for PIC code, regardless of whether
PIC code is for shared libs (most likely) or otherwise.  OTOH, the
only sensible test of __PIC__ on PowerPC64 can be for (b), since we
are (a) all the time.

Because we currently define __PIC__ all the time, the three occurrences
affecting PowerPC64 Linux result in missed optimizations for non-shared
lib code.

This suggests that powerpc64-linux-gcc should only define __PIC__ when
-fPIC is given, and that Kaveh's patch is OK.
Comment 17 Alan Modra 2004-11-10 05:13:27 UTC
No, actually not the next day, but a few days later.  Incidentally, the (a) and
(b) are from an earlier reply of mine on this subject:

On most other targets, -fpic, ie. flag_pic, means two things:
a) generate PIC code, and
b) generate code suitable for ELF shared libraries.
I'll not argue the wisdom of -fpic meaning two things, but that's just
how things evolved.  On PowerPC64, code generation is always PIC, but we
don't want the overhead of meeting shared library run-time symbol
resolution requirements when generating application code.  Thus, we
don't want to set flag_pic all the time.

Comment 18 CVS Commits 2004-11-16 22:42:33 UTC
Subject: Bug 6123

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	jsm28@gcc.gnu.org	2004-11-16 22:42:21

Modified files:
	gcc            : ChangeLog 
	gcc/config     : sol2.h 

Log message:
	2004-11-16  Daniel Jacobowitz  <dan@codesourcery.com>
	Mark Mitchell  <mark@codesourcery.com>
	
	PR target/6123
	* config/sol2.h (TARGET_OS_CPP_BUILTINS): Define __PIC__ and
	__pic__ if PIC.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.6367&r2=2.6368
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/sol2.h.diff?cvsroot=gcc&r1=1.15&r2=1.16

Comment 19 Eric Botcazou 2005-01-03 21:03:39 UTC
This will be fixed on Solaris in the upcoming 4.0.0.