diff mbox

[1-3] New configure option to enable Position independent executable as default.

Message ID 2766864.K73NFjqEQA@laptop1.gw.ume.nu
State New
Headers show

Commit Message

Magnus Granberg Nov. 13, 2013, 10:28 p.m. UTC
Hi
This patchset will add a new configure options --enable-default-pie.
With the new option enable will make it pass -fPIE and -pie from the gcc and 
g++ frontend. Have only add the support for two targets but should work on
more targes. In configure.ac we add the new option. We can't compile the 
compiler or the crt stuff with -fPIE it will brake the PCH and the crtbegin and
crtend files. The disabling is done in the Makefiles. The needed spec is added 
to DRIVER_SELF_SPECS. We disable all the profiling test for the linking will 
fail.Tested on x86_64 linux (Gentoo).

/Magnus Granberg

Changlog

2013-11-10  Magnus Granberg  <zorry@gentoo.org>

	/gcc
	* config/gnu-user.h: Define PIE_DRIVER_SELF_SPECS for PIE 
	as default and GNU_DRIVER_SELF_SPECS.
	* config/i386/gnu-user-common.h: Define DRIVER_SELF_SPECS
	* configure.ac: Add new option that enable PIE as default.
	* configure, config.in: Rebuild.
	* Makefile.in: Disable PIE when building the compiler.
	* doc/install.texi: Add the new configure option default PIE.
	* doc/invoke.texi: Add note for the new configure option default PIE.
	* testsuite/gcc/default-pie.c: New test for new configure option
	--enale-default-pie
	* testsuite/gcc.dg/other/anon5.C: Add skip test as it fail to link
	on effective_target default_pie.
	* testsuite/lib/target-supports.exp (check_profiling_available):
	We can't use profiling on effective target default_pie. 
	(check_effective_target_pie): Add check_effective_target_default_pie.

	/libgcc
	* Makefile.in: Disable PIE when building the crtbegin/end files.

----

Comments

Mike Stump Nov. 13, 2013, 11:23 p.m. UTC | #1
On Nov 13, 2013, at 2:28 PM, Magnus Granberg <zorry@gentoo.org> wrote:
> This patchset will add a new configure options --enable-default-pie.

Ick.  Would be nice to figure out on what systems one can do this and just do it without the configure option.  Is there some reason that we need an option for it?
Ian Lance Taylor Nov. 14, 2013, 1:14 a.m. UTC | #2
On Wed, Nov 13, 2013 at 3:23 PM, Mike Stump <mikestump@comcast.net> wrote:
> On Nov 13, 2013, at 2:28 PM, Magnus Granberg <zorry@gentoo.org> wrote:
>> This patchset will add a new configure options --enable-default-pie.
>
> Ick.  Would be nice to figure out on what systems one can do this and just do it without the configure option.  Is there some reason that we need an option for it?

I either don't understand the patch description or I don't understand
your comment.  I think the patch is making -fPIE the default.  It is
not normally the default.  This option would change the default
behaviour of the compiler, so it doesn't really make sense to ask
whether we can just do it without the configure option.

Ian
Mike Stump Nov. 14, 2013, 4:07 a.m. UTC | #3
On Nov 13, 2013, at 5:14 PM, Ian Lance Taylor <iant@google.com> wrote:
> On Wed, Nov 13, 2013 at 3:23 PM, Mike Stump <mikestump@comcast.net> wrote:
>> On Nov 13, 2013, at 2:28 PM, Magnus Granberg <zorry@gentoo.org> wrote:
>>> This patchset will add a new configure options --enable-default-pie.
>> 
>> Ick.  Would be nice to figure out on what systems one can do this and just do it without the configure option.  Is there some reason that we need an option for it?
> 
> I either don't understand the patch description or I don't understand
> your comment.  I think the patch is making -fPIE the default.

No, what the patch does is 'New configure option'.  What I prefer is, the patch titled, 'make pie default'.  The difference is the word option.

> It is not normally the default.  This option would change the default
> behaviour of the compiler, so it doesn't really make sense to ask
> whether we can just do it without the configure option.

Sure it does.  Explain how the default can't be changed otherwise.

For example, we can change the default for -O, to be -O2.

int optimize = 2;

instead of

int optimize = 0;

One can add a configure option to select the default for -O, but, it isn't necessary to merely change the default.
Ian Lance Taylor Nov. 14, 2013, 4:24 a.m. UTC | #4
On Wed, Nov 13, 2013 at 8:07 PM, Mike Stump <mikestump@comcast.net> wrote:
> On Nov 13, 2013, at 5:14 PM, Ian Lance Taylor <iant@google.com> wrote:
>> On Wed, Nov 13, 2013 at 3:23 PM, Mike Stump <mikestump@comcast.net> wrote:
>>> On Nov 13, 2013, at 2:28 PM, Magnus Granberg <zorry@gentoo.org> wrote:
>>>> This patchset will add a new configure options --enable-default-pie.
>>>
>>> Ick.  Would be nice to figure out on what systems one can do this and just do it without the configure option.  Is there some reason that we need an option for it?
>>
>> I either don't understand the patch description or I don't understand
>> your comment.  I think the patch is making -fPIE the default.
>
> No, what the patch does is 'New configure option'.  What I prefer is, the patch titled, 'make pie default'.  The difference is the word option.

OK, I didn't understand your comment.

I don't think we should make -fPIE the default for all users.

Ian
Marek Polacek Nov. 14, 2013, 10:48 a.m. UTC | #5
On Wed, Nov 13, 2013 at 08:24:34PM -0800, Ian Lance Taylor wrote:
> I don't think we should make -fPIE the default for all users.

Yeah, definitely not.

	Marek
Ryan Hill Nov. 17, 2013, 2:37 a.m. UTC | #6
On Wed, 13 Nov 2013 23:28:45 +0100
Magnus Granberg <zorry@gentoo.org> wrote:

> Hi
> This patchset will add a new configure options --enable-default-pie.
> With the new option enable will make it pass -fPIE and -pie from the gcc and 
> g++ frontend. Have only add the support for two targets but should work on
> more targes. In configure.ac we add the new option. We can't compile the 
> compiler or the crt stuff with -fPIE it will brake the PCH and the crtbegin
> and crtend files. The disabling is done in the Makefiles. The needed spec is
> added to DRIVER_SELF_SPECS. We disable all the profiling test for the linking
> will fail.Tested on x86_64 linux (Gentoo).
> 
> /Magnus Granberg

Hey Magnus.  Some nits:

> --- a/gcc/configure.ac	2013-09-25 18:10:35.000000000 +0200
> +++ b/gcc/configure.ac	2013-10-22 21:26:56.287602139 +0200
> @@ -5434,6 +5434,31 @@ if test x"${LINKER_HASH_STYLE}" != x; th
>                                           [The linker hash style])
>  fi
>  
> +# Check whether --enable-default-pie was given and target have the support.
> +AC_ARG_ENABLE(default-pie,
> +[AS_HELP_STRING([--enable-default-pie], [Enable Position independent executable as default.

Help strings begin with a lowercase letter and do not end with a period. "enable
Position Independent Executables by default".

> +                 If we have suppot for it when compiling and linking.
> +                 Linux targets supported i?86 and x86_64.])],

I would drop these lines.

> +enable_default_pie=$enableval,
> +enable_default_pie=no)
> +if test x$enable_default_pie = xyes; then
> +  AC_MSG_CHECKING(if $target support to default with -fPIE and link with -pie as default)

"if $target supports default PIE"

> +  enable_default_pie=no
> +  case $target in
> +    i?86*-*-linux* | x86_64*-*-linux*)
> +      enable_default_pie=yes
> +      ;;
> +    *)
> +      ;;
> +    esac
> +  AC_MSG_RESULT($enable_default_pie)
> +fi
> +if test x$enable_default_pie == xyes ; then
> +  AC_DEFINE(ENABLE_DEFAULT_PIE, 1,
> +      [Define if your target support default-pie and you have enable it.])

"supports default PIE and it is enabled."

> +fi
> +AC_SUBST([enable_default_pie])
> +
>  # Configure the subdirectories
>  # AC_CONFIG_SUBDIRS($subdirs)
>  
> --- a/gcc/doc/install.texi	2013-10-01 19:29:40.000000000 +0200
> +++ b/gcc/doc/install.texi	2013-11-09 15:40:20.831402110 +0100
> @@ -1421,6 +1421,11 @@ do a @samp{make -C gcc gnatlib_and_tools
>  Specify that the run-time libraries for stack smashing protection
>  should not be built.
>  
> +@item --enable-default-pie
> +We will turn on @option{-fPIE} and @option{-pie} as default when
> +compileing and linking if the support is there. We only support 
> +i?86-*-linux* and x86-64-*-linux* as target for now.

"Turn on @option{-fPIE} and @option{-pie} by default if supported.  
Currently supported targets are i?86-*-linux* and x86-64-*-linux*."

Also two spaces between sentences.

> --- a/gcc/doc/invoke.texi	2012-03-01 10:57:59.000000000 +0100
> +++ b/gcc/doc/invoke.texi	2012-07-30 00:57:03.766847851 +0200
> @@ -9457,6 +9480,12 @@ For predictable results, you must also s
>  that were used to generate code (@option{-fpie}, @option{-fPIE},
>  or model suboptions) when you specify this option.
>  
> +NOTE: With configure --enable-default-pie  this option is enabled by default 

Extra space (also in the hunk for fPIE).

> +for C, C++, ObjC, ObjC++, if none of @option{-fno-PIE}, @option{-fno-pie}, 
> +@option{-fPIC}, @option{-fpic}, @option{-fno-PIC}, @option{-fno-pic}, 
> +@option{-nostdlib}, @option{-nostartfiles}, @option{-shared}, 
> +@option{-nodefaultlibs}, nor @option{static} are found.

Looks like nodefaultlibs is missing from PIE_DRIVER_SELF_SPECS or this needs
to be updated.

Thanks!
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,12 @@ 
+/* { dg-do compile { target *-*-linux* *-*-gnu* } } */
+/* { 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/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
@@ -474,6 +474,11 @@  proc check_profiling_available { test_wh
 	}
     }
 
+    # Profiling don'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
@@ -839,6 +844,14 @@  proc check_effective_target_pie { } {
     return 0
 }
 
+# Return 1 if -pie, -fPIE are default enable, 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 { } {