diff mbox

[PING,1-3] New configure options that make the compiler use -fPIE and -pie as default option

Message ID 1625902.vd5h90ZESU@laptop1.gw.ume.nu
State New
Headers show

Commit Message

Magnus Granberg Dec. 30, 2014, 9:23 p.m. UTC
fredag 14 november 2014 23.31.48 skrev  Magnus Granberg:
> måndag 10 november 2014 21.26.39 skrev  Magnus Granberg:
> > > 	Rainer
> > 
> > Thanks Rainer for the nits and comments.
> > Have updated the patches and Changelogs.
> > But i still use PIE_DRIVER_SELF_SPECS, do you have a ide where move it so
> > i don't need to duplicate that stuff or how to do it?
> > 
> > Magnus G
> > 
> > 2014-11-10  Magnus Granberg  <zorry@gentoo.org>
> > 
> > 	/gcc
> > 	* config/gnu-user.h (PIE_DRIVER_SELF_SPECS) and
> > 	(GNU_DRIVER_SELF_SPECS): Define.
> > 	* config/i386/gnu-user-common.h (DRIVER_SELF_SPECS): Define
> > 	* configure.ac: Add new option.
> > 	* configure, config.in: Rebuild.
> > 	* Makefile.in (ALL_CFLAGS) and (ALL_CXXFLAGS): Disable PIE.
> > 	* doc/install.texi: New configure option.
> > 	* doc/invoke.texi: Add note to PIE.
> > 	* doc/sourcebuild.texi: New effective target.
> > 	gcc/testsuite
> > 	* gcc/default-pie.c: New test
> > 	* gcc.dg/tree-ssa/ssa-store-ccp-3.c: Skip if default_pie
> > 	* g++.dg/other/anon5.C: Skip if default_pie
> > 	* lib/target-supports.exp (check_effective_target_default_pie):
> > 	New proc.
> > 	/libgcc
> > 	* Makefile.in (CRTSTUFF_CFLAGS): Disable PIE.
> 
> Can this be included for GCC 5 ?
> 
> /Magnus G.
One more ping on this. The patches where sent before stage 1 closed but i 
did't get any feed back from it
Have updete the patchses for gcc 5.0 20141228 snapshot.
Bootstrapped and tested on x86_64-unknown-linux-gnu (Gentoo)
/Magnus

2014-12-30  Magnus Granberg  <zorry@gentoo.org>

/gcc
	* config/gnu-user.h (PIE_DRIVER_SELF_SPECS): Define.
	* config/i386/gnu-user-common.h (DRIVER_SELF_SPECS): Define and
	add PIE_DRIVER_SELF_SPECS.
	* configure.ac: Add new option.
	* configure, config.in: Rebuild.
	* Makefile.in (ALL_CFLAGS) and (ALL_CXXFLAGS): Disable PIE.
	* doc/install.texi: New configure option.
	* doc/invoke.texi: Add note to PIE.
	* doc/sourcebuild.texi: New effective target.
gcc/testsuite
	* gcc/default-pie.c: New test
	* gcc.dg/tree-ssa/ssa-store-ccp-3.c: Skip if default_pie
	* g++.dg/other/anon5.C: Skip if default_pie
	* lib/target-supports.exp (check_effective_target_default_pie):
	New proc.
/libgcc
	* Makefile.in (CRTSTUFF_CFLAGS): Disable PIE.

Comments

Allan McRae Jan. 9, 2015, 4:31 a.m. UTC | #1
On 31/12/14 07:23, Magnus Granberg wrote:
> fredag 14 november 2014 23.31.48 skrev  Magnus Granberg:
>> måndag 10 november 2014 21.26.39 skrev  Magnus Granberg:
>>>> 	Rainer
>>>
>>> Thanks Rainer for the nits and comments.
>>> Have updated the patches and Changelogs.
>>> But i still use PIE_DRIVER_SELF_SPECS, do you have a ide where move it so
>>> i don't need to duplicate that stuff or how to do it?
>>>
>>> Magnus G
>>>
>>> 2014-11-10  Magnus Granberg  <zorry@gentoo.org>
>>>
>>> 	/gcc
>>> 	* config/gnu-user.h (PIE_DRIVER_SELF_SPECS) and
>>> 	(GNU_DRIVER_SELF_SPECS): Define.
>>> 	* config/i386/gnu-user-common.h (DRIVER_SELF_SPECS): Define
>>> 	* configure.ac: Add new option.
>>> 	* configure, config.in: Rebuild.
>>> 	* Makefile.in (ALL_CFLAGS) and (ALL_CXXFLAGS): Disable PIE.
>>> 	* doc/install.texi: New configure option.
>>> 	* doc/invoke.texi: Add note to PIE.
>>> 	* doc/sourcebuild.texi: New effective target.
>>> 	gcc/testsuite
>>> 	* gcc/default-pie.c: New test
>>> 	* gcc.dg/tree-ssa/ssa-store-ccp-3.c: Skip if default_pie
>>> 	* g++.dg/other/anon5.C: Skip if default_pie
>>> 	* lib/target-supports.exp (check_effective_target_default_pie):
>>> 	New proc.
>>> 	/libgcc
>>> 	* Makefile.in (CRTSTUFF_CFLAGS): Disable PIE.
>>
>> Can this be included for GCC 5 ?
>>
>> /Magnus G.
> One more ping on this. The patches where sent before stage 1 closed but i 
> did't get any feed back from it
> Have updete the patchses for gcc 5.0 20141228 snapshot.
> Bootstrapped and tested on x86_64-unknown-linux-gnu (Gentoo)
> /Magnus
> 

I'm giving this a further ping as my distribution has interest in these
patches.

Thanks!


> 2014-12-30  Magnus Granberg  <zorry@gentoo.org>
> 
> /gcc
> 	* config/gnu-user.h (PIE_DRIVER_SELF_SPECS): Define.
> 	* config/i386/gnu-user-common.h (DRIVER_SELF_SPECS): Define and
> 	add PIE_DRIVER_SELF_SPECS.
> 	* configure.ac: Add new option.
> 	* configure, config.in: Rebuild.
> 	* Makefile.in (ALL_CFLAGS) and (ALL_CXXFLAGS): Disable PIE.
> 	* doc/install.texi: New configure option.
> 	* doc/invoke.texi: Add note to PIE.
> 	* doc/sourcebuild.texi: New effective target.
> gcc/testsuite
> 	* gcc/default-pie.c: New test
> 	* gcc.dg/tree-ssa/ssa-store-ccp-3.c: Skip if default_pie
> 	* g++.dg/other/anon5.C: Skip if default_pie
> 	* lib/target-supports.exp (check_effective_target_default_pie):
> 	New proc.
> /libgcc
> 	* Makefile.in (CRTSTUFF_CFLAGS): Disable PIE.
>
Richard Biener Jan. 9, 2015, 12:58 p.m. UTC | #2
On Tue, Dec 30, 2014 at 10:23 PM, Magnus Granberg <zorry@gentoo.org> wrote:
> fredag 14 november 2014 23.31.48 skrev  Magnus Granberg:
>> måndag 10 november 2014 21.26.39 skrev  Magnus Granberg:
>> > >   Rainer
>> >
>> > Thanks Rainer for the nits and comments.
>> > Have updated the patches and Changelogs.
>> > But i still use PIE_DRIVER_SELF_SPECS, do you have a ide where move it so
>> > i don't need to duplicate that stuff or how to do it?
>> >
>> > Magnus G
>> >
>> > 2014-11-10  Magnus Granberg  <zorry@gentoo.org>
>> >
>> >     /gcc
>> >     * config/gnu-user.h (PIE_DRIVER_SELF_SPECS) and
>> >     (GNU_DRIVER_SELF_SPECS): Define.
>> >     * config/i386/gnu-user-common.h (DRIVER_SELF_SPECS): Define
>> >     * configure.ac: Add new option.
>> >     * configure, config.in: Rebuild.
>> >     * Makefile.in (ALL_CFLAGS) and (ALL_CXXFLAGS): Disable PIE.
>> >     * doc/install.texi: New configure option.
>> >     * doc/invoke.texi: Add note to PIE.
>> >     * doc/sourcebuild.texi: New effective target.
>> >     gcc/testsuite
>> >     * gcc/default-pie.c: New test
>> >     * gcc.dg/tree-ssa/ssa-store-ccp-3.c: Skip if default_pie
>> >     * g++.dg/other/anon5.C: Skip if default_pie
>> >     * lib/target-supports.exp (check_effective_target_default_pie):
>> >     New proc.
>> >     /libgcc
>> >     * Makefile.in (CRTSTUFF_CFLAGS): Disable PIE.
>>
>> Can this be included for GCC 5 ?
>>
>> /Magnus G.
> One more ping on this. The patches where sent before stage 1 closed but i
> did't get any feed back from it
> Have updete the patchses for gcc 5.0 20141228 snapshot.
> Bootstrapped and tested on x86_64-unknown-linux-gnu (Gentoo)
> /Magnus

Looking at the actual implementation I wonder why it's not similar
to how darwin gets at it default (not sure how it does).  Also
looking at how DRIVER_SELF_SPECS is used I wonder if the
functionality can be enabled with a simple

--with-specs="%{pie|fpic|fPIC|fpie|fPIE|fno-pic|fno-PIC|fno-pie|fno-PIE|shared|static|nostdlib|nodefaultlibs|nostartfiles:;:-fPIE
-pie}"

at configure time (using CONFIGURE_SPECS).

I have no idea if the above is really the proper spec to use - why
do you include static, nostdlib, nodefaultlibs and nostartfiles
for example?  Similar, if I say

 gcc -pie -c t.c

we will end up with a non-PIE object, and linking with -fPIE will
end up with a DYN_EXEC object.

I believe you want to treat link and compile arguments separately
(and adjust the link spec for linking).  I also would have said that
elfos.h is more appropriate than gnu-user.h, but ...

That said, the patch looks more like a hack (and see above how
to achieve the same without a patch(?)), not like a proper implementation
of a PIE default.

Joseph may have an idea where the proper place for a spec-wise
default PIE is.

Thanks,
Richard.

> 2014-12-30  Magnus Granberg  <zorry@gentoo.org>
>
> /gcc
>         * config/gnu-user.h (PIE_DRIVER_SELF_SPECS): Define.
>         * config/i386/gnu-user-common.h (DRIVER_SELF_SPECS): Define and
>         add PIE_DRIVER_SELF_SPECS.
>         * configure.ac: Add new option.
>         * configure, config.in: Rebuild.
>         * Makefile.in (ALL_CFLAGS) and (ALL_CXXFLAGS): Disable PIE.
>         * doc/install.texi: New configure option.
>         * doc/invoke.texi: Add note to PIE.
>         * doc/sourcebuild.texi: New effective target.
> gcc/testsuite
>         * gcc/default-pie.c: New test
>         * gcc.dg/tree-ssa/ssa-store-ccp-3.c: Skip if default_pie
>         * g++.dg/other/anon5.C: Skip if default_pie
>         * lib/target-supports.exp (check_effective_target_default_pie):
>         New proc.
> /libgcc
>         * Makefile.in (CRTSTUFF_CFLAGS): Disable PIE.
>
Daniel Micay Jan. 9, 2015, 2:10 p.m. UTC | #3
On 09/01/15 07:58 AM, Richard Biener wrote:
> 
> Looking at the actual implementation I wonder why it's not similar
> to how darwin gets at it default (not sure how it does).  Also
> looking at how DRIVER_SELF_SPECS is used I wonder if the
> functionality can be enabled with a simple
> 
> --with-specs="%{pie|fpic|fPIC|fpie|fPIE|fno-pic|fno-PIC|fno-pie|fno-PIE|shared|static|nostdlib|nodefaultlibs|nostartfiles:;:-fPIE
> -pie}"
> 
> at configure time (using CONFIGURE_SPECS).
> 
> I have no idea if the above is really the proper spec to use - why
> do you include static, nostdlib, nodefaultlibs and nostartfiles
> for example?  Similar, if I say

PIE isn't supported for static executables by binutils, etc. so it
does need to exclude that. The checks for nostdlib, nodefaultlibs
and nostartfiles do seem unnecessary. I think distributions include
those in the existing wrapper scripts and GCC patches because it
avoids the need for patching build systems for kernel / freestanding
code to include -fno-pie, but it's more correct to leave these out.
 
>  gcc -pie -c t.c
> 
> we will end up with a non-PIE object, and linking with -fPIE will
> end up with a DYN_EXEC object.
> 
> I believe you want to treat link and compile arguments separately
> (and adjust the link spec for linking).  I also would have said that
> elfos.h is more appropriate than gnu-user.h, but ...

Handling it separately is what the existing wrapper scripts for this do:

    -fno-PIC|-fno-pic|-fno-PIE|-fno-pie|-static|--static|-shared|--shared)
      force_fPIE=0
      force_pie=0
      ;;
    -fPIC|-fpic|-fPIE|-fpie)
      force_fPIE=0
      ;;
    -c|-E|-S)
      force_pie=0
      ;;

I think it's appropriate for it to 
 
> That said, the patch looks more like a hack (and see above how
> to achieve the same without a patch(?)), not like a proper implementation
> of a PIE default.

I don't think it can be considered a hack if it's handling all of the cases
correctly, so it might need some changes from the current implementation but
that doesn't make it a dead end. Is it actually done in a significantly
different way for OS X?

If it can be done by passing --with-specs to configure then that could be a
viable alternative for distributions that do not want to add GCC patches or
use wrapper scripts (Arch Linux) but I'm not sure that it will fly.
Joseph Myers Jan. 9, 2015, 5:49 p.m. UTC | #4
On Fri, 9 Jan 2015, Daniel Micay wrote:

> > --with-specs="%{pie|fpic|fPIC|fpie|fPIE|fno-pic|fno-PIC|fno-pie|fno-PIE|shared|static|nostdlib|nodefaultlibs|nostartfiles:;:-fPIE
> > -pie}"
> > 
> > at configure time (using CONFIGURE_SPECS).
> > 
> > I have no idea if the above is really the proper spec to use - why
> > do you include static, nostdlib, nodefaultlibs and nostartfiles
> > for example?  Similar, if I say
> 
> PIE isn't supported for static executables by binutils, etc. so it
> does need to exclude that. The checks for nostdlib, nodefaultlibs

Well - that would indicate excluding -pie if one of the link-time options 
conflicting with it is used, -fPIE if one of the compile-time options 
conflicting with it is used.  That way, "gcc -static file.c" would still 
have the same effect as "gcc -c file.c; gcc -static file.o" (building a 
PIE object, linking it into a non-PIE static executable), which makes 
logical sense to me (although there may be no great benefit either way).
Daniel Micay Jan. 9, 2015, 6 p.m. UTC | #5
On 09/01/15 12:49 PM, Joseph Myers wrote:
> On Fri, 9 Jan 2015, Daniel Micay wrote:
> 
>>> --with-specs="%{pie|fpic|fPIC|fpie|fPIE|fno-pic|fno-PIC|fno-pie|fno-PIE|shared|static|nostdlib|nodefaultlibs|nostartfiles:;:-fPIE
>>> -pie}"
>>>
>>> at configure time (using CONFIGURE_SPECS).
>>>
>>> I have no idea if the above is really the proper spec to use - why
>>> do you include static, nostdlib, nodefaultlibs and nostartfiles
>>> for example?  Similar, if I say
>>
>> PIE isn't supported for static executables by binutils, etc. so it
>> does need to exclude that. The checks for nostdlib, nodefaultlibs
> 
> Well - that would indicate excluding -pie if one of the link-time options 
> conflicting with it is used, -fPIE if one of the compile-time options 
> conflicting with it is used.  That way, "gcc -static file.c" would still 
> have the same effect as "gcc -c file.c; gcc -static file.o" (building a 
> PIE object, linking it into a non-PIE static executable), which makes 
> logical sense to me (although there may be no great benefit either way).

Sure, I agree. It should have separate lists of exceptions for both of
these.
Magnus Granberg Jan. 9, 2015, 8:12 p.m. UTC | #6
fredag 09 januari 2015 13.00.14 skrev  Daniel Micay:
> On 09/01/15 12:49 PM, Joseph Myers wrote:
> > On Fri, 9 Jan 2015, Daniel Micay wrote:
> >>> --with-specs="%{pie|fpic|fPIC|fpie|fPIE|fno-pic|fno-PIC|fno-pie|fno-PIE|
> >>> shared|static|nostdlib|nodefaultlibs|nostartfiles:;:-fPIE -pie}"
> >>> 
> >>> at configure time (using CONFIGURE_SPECS).
DRIVER_SELF_SPECS is checkt before CONFIGURE_SPECS. On mips it will have added 
-mno-shared before it check CONFIGURE_SPECS. I want to support more targets 
later on. Can move the spec to elfos.h.
> >>> 
> >>> I have no idea if the above is really the proper spec to use - why
> >>> do you include static, nostdlib, nodefaultlibs and nostartfiles
> >>> for example?  Similar, if I say
> >> 
> >> PIE isn't supported for static executables by binutils, etc. so it
> >> does need to exclude that. The checks for nostdlib, nodefaultlibs
> > 
> > Well - that would indicate excluding -pie if one of the link-time options
> > conflicting with it is used, -fPIE if one of the compile-time options
> > conflicting with it is used.  That way, "gcc -static file.c" would still
> > have the same effect as "gcc -c file.c; gcc -static file.o" (building a
> > PIE object, linking it into a non-PIE static executable), which makes
> > logical sense to me (although there may be no great benefit either way).
> 
> Sure, I agree. It should have separate lists of exceptions for both of
> these.
I can separete it to compile and linke sections and remove the nostdlib, 
nodefaultlibs and nostartfiles. But how do we not pass -pie to the linker when
we don't pass static or shared and don't link it with -pie? For only the gold 
linker support -no-pie.

/Magnus G.
H.J. Lu Jan. 10, 2015, 1:56 a.m. UTC | #7
On Fri, Jan 9, 2015 at 12:12 PM, Magnus Granberg <zorry@gentoo.org> wrote:
> fredag 09 januari 2015 13.00.14 skrev  Daniel Micay:
>> On 09/01/15 12:49 PM, Joseph Myers wrote:
>> > On Fri, 9 Jan 2015, Daniel Micay wrote:
>> >>> --with-specs="%{pie|fpic|fPIC|fpie|fPIE|fno-pic|fno-PIC|fno-pie|fno-PIE|
>> >>> shared|static|nostdlib|nodefaultlibs|nostartfiles:;:-fPIE -pie}"
>> >>>
>> >>> at configure time (using CONFIGURE_SPECS).
> DRIVER_SELF_SPECS is checkt before CONFIGURE_SPECS. On mips it will have added
> -mno-shared before it check CONFIGURE_SPECS. I want to support more targets
> later on. Can move the spec to elfos.h.
>> >>>
>> >>> I have no idea if the above is really the proper spec to use - why
>> >>> do you include static, nostdlib, nodefaultlibs and nostartfiles
>> >>> for example?  Similar, if I say
>> >>
>> >> PIE isn't supported for static executables by binutils, etc. so it
>> >> does need to exclude that. The checks for nostdlib, nodefaultlibs
>> >
>> > Well - that would indicate excluding -pie if one of the link-time options
>> > conflicting with it is used, -fPIE if one of the compile-time options
>> > conflicting with it is used.  That way, "gcc -static file.c" would still
>> > have the same effect as "gcc -c file.c; gcc -static file.o" (building a
>> > PIE object, linking it into a non-PIE static executable), which makes
>> > logical sense to me (although there may be no great benefit either way).
>>
>> Sure, I agree. It should have separate lists of exceptions for both of
>> these.
> I can separete it to compile and linke sections and remove the nostdlib,
> nodefaultlibs and nostartfiles. But how do we not pass -pie to the linker when
> we don't pass static or shared and don't link it with -pie? For only the gold
> linker support -no-pie.
>
> /Magnus G.
>
>

Please try hjl/pie branch:

https://gcc.gnu.org/git/?p=gcc.git;a=summary

and let know if it works for you.
H.J. Lu Jan. 10, 2015, 3:07 p.m. UTC | #8
On Fri, Jan 9, 2015 at 5:56 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Fri, Jan 9, 2015 at 12:12 PM, Magnus Granberg <zorry@gentoo.org> wrote:
>> fredag 09 januari 2015 13.00.14 skrev  Daniel Micay:
>>> On 09/01/15 12:49 PM, Joseph Myers wrote:
>>> > On Fri, 9 Jan 2015, Daniel Micay wrote:
>>> >>> --with-specs="%{pie|fpic|fPIC|fpie|fPIE|fno-pic|fno-PIC|fno-pie|fno-PIE|
>>> >>> shared|static|nostdlib|nodefaultlibs|nostartfiles:;:-fPIE -pie}"
>>> >>>
>>> >>> at configure time (using CONFIGURE_SPECS).
>> DRIVER_SELF_SPECS is checkt before CONFIGURE_SPECS. On mips it will have added
>> -mno-shared before it check CONFIGURE_SPECS. I want to support more targets
>> later on. Can move the spec to elfos.h.
>>> >>>
>>> >>> I have no idea if the above is really the proper spec to use - why
>>> >>> do you include static, nostdlib, nodefaultlibs and nostartfiles
>>> >>> for example?  Similar, if I say
>>> >>
>>> >> PIE isn't supported for static executables by binutils, etc. so it
>>> >> does need to exclude that. The checks for nostdlib, nodefaultlibs
>>> >
>>> > Well - that would indicate excluding -pie if one of the link-time options
>>> > conflicting with it is used, -fPIE if one of the compile-time options
>>> > conflicting with it is used.  That way, "gcc -static file.c" would still
>>> > have the same effect as "gcc -c file.c; gcc -static file.o" (building a
>>> > PIE object, linking it into a non-PIE static executable), which makes
>>> > logical sense to me (although there may be no great benefit either way).
>>>
>>> Sure, I agree. It should have separate lists of exceptions for both of
>>> these.
>> I can separete it to compile and linke sections and remove the nostdlib,
>> nodefaultlibs and nostartfiles. But how do we not pass -pie to the linker when
>> we don't pass static or shared and don't link it with -pie? For only the gold
>> linker support -no-pie.
>>
>> /Magnus G.
>>
>>
>
> Please try hjl/pie branch:
>
> https://gcc.gnu.org/git/?p=gcc.git;a=summary
>
> and let know if it works for you.
>

I updated the branch with some fixes.
diff mbox

Patch

--- a/gcc/testsuite/gcc.dg/default-pie.c	2013-11-09 21:07:16.741479728 +0100
+++ b/gcc/testsuite/gcc.dg/default-pie.c	2013-11-09 21:05:07.801479218 +0100
@@ -0,0 +1,11 @@ 
+/* { dg-require-effective-target default_pie } */
+/* { dg-options "-O2" } */
+int foo (void);
+
+int
+main (void)
+{
+	return foo ();
+}
+
+/* { dg-final { scan-assembler "foo@PLT" } } */
--- a/gcc/testsuite/gcc.dg/tree-ssa/ssa-store-ccp-3.c	2012-03-14 17:33:37.000000000 +0100
+++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-store-ccp-3.c	2014-07-29 00:55:17.421086416 +0200
@@ -2,6 +2,7 @@ 
 /* Skipped on MIPS GNU/Linux target because __PIC__ can be
    defined for executables as well as shared libraries.  */
 /* { dg-skip-if "" { *-*-darwin* hppa*64*-*-* mips*-*-linux* *-*-mingw* } { "*" } { "" } } */
+/* { dg-skip-if "" { default_pie } { "*" } { "" } }  */
 /* { dg-options "-O2 -fno-common -fdump-tree-optimized" } */
 
 const int conststaticvariable;
--- a/gcc/testsuite/g++.dg/other/anon5.C	2012-11-10 15:34:42.000000000 +0100
+++ b/gcc/testsuite/g++.dg/other/anon5.C	2013-11-09 14:49:52.281390127 +0100
@@ -1,5 +1,6 @@ 
 // PR c++/34094
 // { dg-do link { target { ! { *-*-darwin* *-*-hpux* *-*-solaris2.* } } } }
+// { dg-skip-if "" { default_pie } { "*" } { "" } }
 // { dg-options "-g" }
 // Ignore additional message on powerpc-ibm-aix
 // { dg-prune-output "obtain more information" } */
--- a/gcc/testsuite/lib/target-supports.exp	2013-10-01 11:18:30.000000000 +0200
+++ b/gcc/testsuite/lib/target-supports.exp	2013-10-25 22:01:46.743388469 +0200
@@ -475,6 +475,11 @@  proc check_profiling_available { test_wh
 	}
     }
 
+    # Profiling doesn't work with default -fPIE -pie.
+    if { [check_effective_target_default_pie] } {
+      return 0
+    }
+
     # Support for -p on solaris2 relies on mcrt1.o which comes with the
     # vendor compiler.  We cannot reliably predict the directory where the
     # vendor compiler (and thus mcrt1.o) is installed so we can't
@@ -927,6 +927,14 @@  proc check_effective_target_pie { } {
     return 0
 }
 
+# Return 1 if -pie, -fPIE are enable by default, 0 otherwise.
+
+proc check_effective_target_default_pie { } {
+    global ENABLE_DEFAULT_PIE
+    return [info exists ENABLE_DEFAULT_PIE]
+    return 0
+}
+
 # Return true if the target supports -mpaired-single (as used on MIPS).
 
 proc check_effective_target_mpaired_single { } {