Patchwork pass -no_pie to LINK_GCC_C_SEQUENCE_SPEC on darwin

login
register
mail settings
Submitter Jack Howarth
Date Dec. 4, 2011, 7 p.m.
Message ID <20111204190020.GA4873@bromo.med.uc.edu>
Download mbox | patch
Permalink /patch/129190/
State New
Headers show

Comments

Jack Howarth - Dec. 4, 2011, 7 p.m.
On Sun, Dec 04, 2011 at 09:28:55AM -0800, Mike Stump wrote:
> On Dec 4, 2011, at 9:09 AM, Jack Howarth <howarth@bromo.med.uc.edu> wrote:
> > On Sat, Dec 03, 2011 at 10:45:18PM -0800, Mike Stump wrote:
> >> On Dec 3, 2011, at 7:25 AM, Jack Howarth wrote:
> >>> FSF gcc currently doesn't handle -fno-pie and friends properly under Lion.
> >>> The darwin11 linker now defaults to -pie
> >> 
> >>> Okay for gcc trunk and backports to gcc-4_5-branch/gcc-4_6-branch?
> >> 
> >> Ok.
> > 
> > Mike,
> >   Thanks for the commit. This leaves us with the boehm-gc testsuite failures...
> > 
> > FAIL: boehm-gc.c/gctest.c -O2 execution test
> > FAIL: boehm-gc.c/leak_test.c -O2 execution test
> > FAIL: boehm-gc.c/thread_leak_test.c -O2 execution test
> > FAIL: boehm-gc.lib/staticrootstest.c -O2 execution test
> > 
> > at -m32/-m64 on x86_64-apple-darwin11 due to the -pie linker default. Iain had wanted
> > to leave these in place to encourage boehm-gc to be fixed but I doubt that is a realistic
> > goal in the near/middle term. Perhaps we could patch boehm-gc/testsuite/lib/boehm-gc.exp
> > to pass -fno-pie on darwin (now that it is functional)?
> 
> I think we should just find a way to add -fno-pie...  Are there any flags that are added because we are doing gc that we can key off of?

Mike,
   The simple approach would be...


which yields...

		=== boehm-gc tests ===

Schedule of variations:
    unix/-m32
    unix/-m64

Running target unix/-m32
Using /sw/share/dejagnu/baseboards/unix.exp as board description file for target.
Using /sw/share/dejagnu/config/unix.exp as generic interface file for target.
Using /sw/src/fink.build/gcc47-4.7.0-1/gcc-4.7-20111202/boehm-gc/testsuite/config/default.exp as tool-and-target-specific interface file.
Running /sw/src/fink.build/gcc47-4.7.0-1/gcc-4.7-20111202/boehm-gc/testsuite/boehm-gc.c/c.exp ...
Running /sw/src/fink.build/gcc47-4.7.0-1/gcc-4.7-20111202/boehm-gc/testsuite/boehm-gc.lib/lib.exp ...

		=== boehm-gc Summary for unix/-m32 ===

# of expected passes		12
# of unsupported tests		1
Running target unix/-m64
Using /sw/share/dejagnu/baseboards/unix.exp as board description file for target.
Using /sw/share/dejagnu/config/unix.exp as generic interface file for target.
Using /sw/src/fink.build/gcc47-4.7.0-1/gcc-4.7-20111202/boehm-gc/testsuite/config/default.exp as tool-and-target-specific interface file.
Running /sw/src/fink.build/gcc47-4.7.0-1/gcc-4.7-20111202/boehm-gc/testsuite/boehm-gc.c/c.exp ...
Running /sw/src/fink.build/gcc47-4.7.0-1/gcc-4.7-20111202/boehm-gc/testsuite/boehm-gc.lib/lib.exp ...

		=== boehm-gc Summary for unix/-m64 ===

# of expected passes		12
# of unsupported tests		1

		=== boehm-gc Summary ===

# of expected passes		24
# of unsupported tests		2

I would argue that this is useful in that it reminds the developers that boehm-gc isn't PIE friendly
and needs to be fixed.
             Jack
Jakub Jelinek - Dec. 4, 2011, 7:18 p.m.
On Sun, Dec 04, 2011 at 02:00:20PM -0500, Jack Howarth wrote:
> > > at -m32/-m64 on x86_64-apple-darwin11 due to the -pie linker default. Iain had wanted
> > > to leave these in place to encourage boehm-gc to be fixed but I doubt that is a realistic
> > > goal in the near/middle term. Perhaps we could patch boehm-gc/testsuite/lib/boehm-gc.exp
> > > to pass -fno-pie on darwin (now that it is functional)?
> > 
> > I think we should just find a way to add -fno-pie...  Are there any
> > flags that are added because we are doing gc that we can key off of?

-f{pic,PIC,pie,PIE,no-pic} aren't option that should have any effect on how
are binaries/shared libraries linked, these options control solely
compilation.  -shared, -pie or lack of these options determines how are
things linked.  So, either you should pass -no-pie or whatever linker option
you need to generate position dependent binaries by default, unless -shared
or -pie is specified, or you should add -no-pie or something similar, but
IMHO it shouldn't be -fno-pie, that is a compilation option/too similar to
them.

	Jakub
Jack Howarth - Dec. 4, 2011, 8:19 p.m.
On Sun, Dec 04, 2011 at 08:18:32PM +0100, Jakub Jelinek wrote:
> On Sun, Dec 04, 2011 at 02:00:20PM -0500, Jack Howarth wrote:
> > > > at -m32/-m64 on x86_64-apple-darwin11 due to the -pie linker default. Iain had wanted
> > > > to leave these in place to encourage boehm-gc to be fixed but I doubt that is a realistic
> > > > goal in the near/middle term. Perhaps we could patch boehm-gc/testsuite/lib/boehm-gc.exp
> > > > to pass -fno-pie on darwin (now that it is functional)?
> > > 
> > > I think we should just find a way to add -fno-pie...  Are there any
> > > flags that are added because we are doing gc that we can key off of?
> 
> -f{pic,PIC,pie,PIE,no-pic} aren't option that should have any effect on how
> are binaries/shared libraries linked, these options control solely
> compilation.  -shared, -pie or lack of these options determines how are
> things linked.  So, either you should pass -no-pie or whatever linker option
> you need to generate position dependent binaries by default, unless -shared
> or -pie is specified, or you should add -no-pie or something similar, but
> IMHO it shouldn't be -fno-pie, that is a compilation option/too similar to
> them.

Jakub,
   This isn't really an option on darwin11 and later since the linker defaults to
-pie and this results in warnings from the linker of the form...

ld: warning: PIE disabled. Absolute addressing (perhaps -mdynamic-no-pic) not allowed in code signed PIE, but used in _f from /var/tmp//ccVNy9V9.o. To fix this warning, don't compile with -mdynamic-no-pic or link with -Wl,-no_pie

Author: mrs
Date: Sun Dec  4 07:09:56 2011
New Revision: 181982

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=181982
Log:
2011-12-03  Jack Howarth  <howarth@bromo.med.uc.edu>

       * config/darwin10.h (LINK_GCC_C_SEQUENCE_SPEC):
         Pass -no_pie for non-PIC code when targeting 10.7 or later.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/darwin10.h

is designed to inhibit this linker noise by explicitly disabling pie linkage. Also, FSF gcc previously wasn't
honoring -fno-pie since this didn't inhibit the darwin11 linker from creating a PIE executable. 
   Unfortunately the linker option -no_pie isn't recognized by earlier darwin linkers which makes -fno-pie
preferred since it only passes -no_pie to the linker when targeting 10.7 or later. So we may have to make
the change darwin-specific.
        Jack


> 
> 	Jakub
IainS - Dec. 4, 2011, 8:35 p.m.
On 4 Dec 2011, at 20:19, Jack Howarth wrote:

> On Sun, Dec 04, 2011 at 08:18:32PM +0100, Jakub Jelinek wrote:
>> On Sun, Dec 04, 2011 at 02:00:20PM -0500, Jack Howarth wrote:
>>>>> at -m32/-m64 on x86_64-apple-darwin11 due to the -pie linker  
>>>>> default. Iain had wanted
>>>>> to leave these in place to encourage boehm-gc to be fixed but I  
>>>>> doubt that is a realistic
>>>>> goal in the near/middle term. Perhaps we could patch boehm-gc/ 
>>>>> testsuite/lib/boehm-gc.exp
>>>>> to pass -fno-pie on darwin (now that it is functional)?
>>>>
>>>> I think we should just find a way to add -fno-pie...  Are there any
>>>> flags that are added because we are doing gc that we can key off  
>>>> of?
>>
>> -f{pic,PIC,pie,PIE,no-pic} aren't option that should have any  
>> effect on how
>> are binaries/shared libraries linked, these options control solely
>> compilation.  -shared, -pie or lack of these options determines how  
>> are
>> things linked.  So, either you should pass -no-pie or whatever  
>> linker option
>> you need to generate position dependent binaries by default, unless  
>> -shared
>> or -pie is specified, or you should add -no-pie or something  
>> similar, but
>> IMHO it shouldn't be -fno-pie, that is a compilation option/too  
>> similar to
>> them.
>
> Jakub,
>   This isn't really an option on darwin11 and later since the linker  
> defaults to
> -pie and this results in warnings from the linker of the form...
>
> ld: warning: PIE disabled. Absolute addressing (perhaps -mdynamic-no- 
> pic) not allowed in code signed PIE, but used in _f from /var/tmp// 
> ccVNy9V9.o. To fix this warning, don't compile with -mdynamic-no-pic  
> or link with -Wl,-no_pie

perhaps the question should be "why is this particualr code being  
built with non-default options?".
x86 darwin code should default to fPIC - so someone must be passing - 
mdynamic-no-pic or -fno-PIC etc.

(perhaps derived from the bootstrap usage of the "-mdynamic-no-pic"  
option - which suggests that this should be disabled for Darwin >= 11).

Iain
Jack Howarth - Dec. 4, 2011, 8:46 p.m.
On Sun, Dec 04, 2011 at 08:35:07PM +0000, Iain Sandoe wrote:
>
> On 4 Dec 2011, at 20:19, Jack Howarth wrote:
>
>> On Sun, Dec 04, 2011 at 08:18:32PM +0100, Jakub Jelinek wrote:
>>> On Sun, Dec 04, 2011 at 02:00:20PM -0500, Jack Howarth wrote:
>>>>>> at -m32/-m64 on x86_64-apple-darwin11 due to the -pie linker  
>>>>>> default. Iain had wanted
>>>>>> to leave these in place to encourage boehm-gc to be fixed but I 
>>>>>> doubt that is a realistic
>>>>>> goal in the near/middle term. Perhaps we could patch boehm-gc/ 
>>>>>> testsuite/lib/boehm-gc.exp
>>>>>> to pass -fno-pie on darwin (now that it is functional)?
>>>>>
>>>>> I think we should just find a way to add -fno-pie...  Are there any
>>>>> flags that are added because we are doing gc that we can key off  
>>>>> of?
>>>
>>> -f{pic,PIC,pie,PIE,no-pic} aren't option that should have any effect 
>>> on how
>>> are binaries/shared libraries linked, these options control solely
>>> compilation.  -shared, -pie or lack of these options determines how  
>>> are
>>> things linked.  So, either you should pass -no-pie or whatever  
>>> linker option
>>> you need to generate position dependent binaries by default, unless  
>>> -shared
>>> or -pie is specified, or you should add -no-pie or something  
>>> similar, but
>>> IMHO it shouldn't be -fno-pie, that is a compilation option/too  
>>> similar to
>>> them.
>>
>> Jakub,
>>   This isn't really an option on darwin11 and later since the linker  
>> defaults to
>> -pie and this results in warnings from the linker of the form...
>>
>> ld: warning: PIE disabled. Absolute addressing (perhaps -mdynamic-no- 
>> pic) not allowed in code signed PIE, but used in _f from /var/tmp// 
>> ccVNy9V9.o. To fix this warning, don't compile with -mdynamic-no-pic  
>> or link with -Wl,-no_pie
>
> perhaps the question should be "why is this particualr code being built 
> with non-default options?".
> x86 darwin code should default to fPIC - so someone must be passing - 
> mdynamic-no-pic or -fno-PIC etc.

Iain,
   I was only pointing out that we are in a unique situation when targeting
darwin11 and later since we are the only target currently creating PIE by
default. However unlike linux, darwin doesn't require or even encourage the
use of -fpie/-fPIE to do this but silently relies on the default -fPIC. Also, the
warning cited above was from gcc.dg/20020312-2.c which previously failed its
excessive error test since it passed -fno-pic which triggered the warning.
        Jack

>
> (perhaps derived from the bootstrap usage of the "-mdynamic-no-pic"  
> option - which suggests that this should be disabled for Darwin >= 11).
>
> Iain

Patch

Index: boehm-gc/testsuite/boehm-gc.c/c.exp
===================================================================
--- boehm-gc/testsuite/boehm-gc.c/c.exp	(revision 181993)
+++ boehm-gc/testsuite/boehm-gc.c/c.exp	(working copy)
@@ -17,6 +17,6 @@ 
 dg-init
 boehm-gc-init
 
-boehm-gc-dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.c]] "-O2" ""
+boehm-gc-dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.c]] "-O2 -fno-pie" ""
 
 dg-finish
Index: boehm-gc/testsuite/boehm-gc.lib/lib.exp
===================================================================
--- boehm-gc/testsuite/boehm-gc.lib/lib.exp	(revision 181993)
+++ boehm-gc/testsuite/boehm-gc.lib/lib.exp	(working copy)
@@ -21,6 +21,6 @@  boehm-gc-init
 set tests [lsort [glob -nocomplain $srcdir/$subdir/*.c]]
 set tests [prune $tests $srcdir/$subdir/*lib.c]
 
-boehm-gc-dg-runtest $tests "-O2" ""
+boehm-gc-dg-runtest $tests "-O2 -fno-pie" ""
 
 dg-finish