public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH][1-3] New configure options that make the compiler use -fPIE and -pie as default option
@ 2014-07-31 20:32 Magnus Granberg
  2014-08-01  8:52 ` Rainer Orth
  0 siblings, 1 reply; 20+ messages in thread
From: Magnus Granberg @ 2014-07-31 20:32 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 1822 bytes --]

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).

More and more Linux/gnu distributions compile binary with PIE with this you
could allmost compile all binary with PIE as we do on Gentoo Hardened.
This patches have bin posted before on the list.
https://gcc.gnu.org/ml/gcc-patches/2013-11/msg01515.html


/Magnus Granberg

Changlog

2014-07-31  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.

----

[-- Attachment #2: gcc410_default_pie_main.patch --]
[-- Type: text/x-patch, Size: 5424 bytes --]

--- a/gcc/config/gnu-user.h	2013-08-20 10:31:40.000000000 +0200
+++ b/gcc/config/gnu-user.h	2013-10-23 22:01:42.337238981 +0200
@@ -126,3 +126,17 @@ see the files COPYING3 and COPYING.RUNTI
   LD_STATIC_OPTION " --whole-archive -ltsan --no-whole-archive " \
   LD_DYNAMIC_OPTION "}}%{!static-libtsan:-ltsan}"
 #endif
+
+/* We use this to make the compiler use -fPIE as default and link
+   with -pie.  */
+#ifdef ENABLE_DEFAULT_PIE
+#define PIE_DRIVER_SELF_SPECS \
+"%{pie|fpic|fPIC|fpie|fPIE|fno-pic|fno-PIC|fno-pie|fno-PIE| \
+  shared|static|nostdlib|nodefaultlibs|nostartfiles:;:-fPIE -pie}"
+#else
+#define PIE_DRIVER_SELF_SPECS ""
+#endif
+
+#ifndef GNU_DRIVER_SELF_SPECS
+#define GNU_DRIVER_SELF_SPECS PIE_DRIVER_SELF_SPECS
+#endif
--- a/gcc/config/i386/gnu-user-common.h	2013-01-10 21:38:27.000000000 +0100
+++ b/gcc/config/i386/gnu-user-common.h	2013-10-23 17:37:45.432767049 +0200
@@ -70,3 +70,8 @@ along with GCC; see the file COPYING3.
 
 /* Static stack checking is supported by means of probes.  */
 #define STACK_CHECK_STATIC_BUILTIN 1
+
+/* Use GNU_DRIVER_SELF_SPECS.  */
+#ifndef DRIVER_SELF_SPECS
+#define DRIVER_SELF_SPECS GNU_DRIVER_SELF_SPECS
+#endif
--- a/gcc/configure.ac	2014-04-28 16:01:40.000000000 +0200
+++ b/gcc/configure.ac	2014-05-08 02:42:30.900883247 +0200
@@ -5671,6 +5671,36 @@ 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])],
+enable_default_pie=$enableval,
+enable_default_pie=no)
+if test x$enable_default_pie = xyes; then
+  AC_MSG_CHECKING(if $target supports default PIE)
+  enable_default_pie=no
+  case $target in
+    i?86*-*-linux* | x86_64*-*-linux*)
+      saved_LDFLAGS="$LDFLAGS"
+      saved_CFLAGS="$CFLAGS"
+      CFLAGS="$CFLAGS -fPIE"
+      LDFLAGS="$LDFLAGS -fPIE -pie"
+      AC_TRY_LINK(,,[enable_default_pie=yes],)
+      LDFLAGS="$saved_LDFLAGS"
+      CFLAGS="$saved_CFLAGS"
+      ;;
+    *)
+      ;;
+    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 supports default PIE and it is enabled.])
+fi
+AC_SUBST([enable_default_pie])
+
 # Configure the subdirectories
 # AC_CONFIG_SUBDIRS($subdirs)
 
--- a/gcc/Makefile.in	2013-10-02 21:52:27.000000000 +0200
+++ b/gcc/Makefile.in	2013-10-24 17:46:22.055357122 +0200
@@ -968,14 +968,23 @@ CONTEXT_H = context.h
 # cross compiler which does not use the native headers and libraries.
 INTERNAL_CFLAGS = -DIN_GCC $(PICFLAG) @CROSS@
 
+# We don't want to compile the compiler with -fPIE, it make PCH fail.
+enable_default_pie = @enable_default_pie@
+ifeq ($(enable_default_pie),yes)
+NOPIE_CFLAGS = -fno-PIE
+else
+NOPIE_CFLAGS=
+endif
+
 # This is the variable actually used when we compile. If you change this,
 # you probably want to update BUILD_CFLAGS in configure.ac
-ALL_CFLAGS = $(T_CFLAGS) $(CFLAGS-$@) \
+ALL_CFLAGS = $(NOPIE_CFLAGS) $(T_CFLAGS) $(CFLAGS-$@) \
   $(CFLAGS) $(INTERNAL_CFLAGS) $(COVERAGE_FLAGS) $(WARN_CFLAGS) @DEFS@
 
 # The C++ version.
-ALL_CXXFLAGS = $(T_CFLAGS) $(CFLAGS-$@) $(CXXFLAGS) $(INTERNAL_CFLAGS) \
-  $(COVERAGE_FLAGS) $(NOEXCEPTION_FLAGS) $(WARN_CXXFLAGS) @DEFS@
+ALL_CXXFLAGS = $(NOPIE_CFLAGS) $(T_CFLAGS) $(CFLAGS-$@) $(CXXFLAGS) \
+  $(INTERNAL_CFLAGS) $(COVERAGE_FLAGS) $(NOEXCEPTION_FLAGS) \
+  $(WARN_CXXFLAGS) @DEFS@
 
 # Likewise.  Put INCLUDES at the beginning: this way, if some autoconf macro
 # puts -I options in CPPFLAGS, our include files in the srcdir will always
@@ -1831,6 +1831,7 @@ libgcc.mvars: config.status Makefile spe
 	echo GCC_CFLAGS = '$(GCC_CFLAGS)' >> tmp-libgcc.mvars
 	echo INHIBIT_LIBC_CFLAGS = '$(INHIBIT_LIBC_CFLAGS)' >> tmp-libgcc.mvars
 	echo TARGET_SYSTEM_ROOT = '$(TARGET_SYSTEM_ROOT)' >> tmp-libgcc.mvars
+	echo enable_default_pie = '$(enable_default_pie)' >> tmp-libgcc.mvars
 
 	mv tmp-libgcc.mvars libgcc.mvars
 
@@ -3536,6 +3536,9 @@ site.exp: ./config.status Makefile
 	@if test "@enable_lto@" = "yes" ; then \
 	  echo "set ENABLE_LTO 1" >> ./site.tmp; \
 	fi
+	@if test "@enable_default_pie@" = "yes" ; then \
+	  echo "set ENABLE_DEFAULT_PIE 1" >> ./site.tmp; \
+	fi
 # If newlib has been configured, we need to pass -B to gcc so it can find
 # newlib's crt0.o if it exists.  This will cause a "path prefix not used"
 # message if it doesn't, but the testsuite is supposed to ignore the message -
--- a/libgcc/Makefile.in	2011-11-22 04:01:02.000000000 +0100
+++ b/libgcc/Makefile.in	2012-06-29 00:15:04.534016511 +0200
@@ -279,11 +279,17 @@ override CFLAGS := $(filter-out -fprofil
 INTERNAL_CFLAGS = $(CFLAGS) $(LIBGCC2_CFLAGS) $(HOST_LIBGCC2_CFLAGS) \
 		  $(INCLUDES) @set_have_cc_tls@ @set_use_emutls@
 
+#Don't use -fPIE when compiling crtbegin/end.
+ifeq ($(enable_default_pie),yes)
+NOPIE_CFLAGS = -fno-PIE
+else
+NOPIE_CFLAGS=
+endif
 # Options to use when compiling crtbegin/end.
 CRTSTUFF_CFLAGS = -O2 $(GCC_CFLAGS) $(INCLUDES) $(MULTILIB_CFLAGS) -g0 \
   -finhibit-size-directive -fno-inline -fno-exceptions \
   -fno-zero-initialized-in-bss -fno-toplevel-reorder -fno-tree-vectorize \
-  -fno-stack-protector \
+  -fno-stack-protector $(NOPIE_CFLAGS) \
   $(INHIBIT_LIBC_CFLAGS)
 
 # Extra flags to use when compiling crt{begin,end}.o.

[-- Attachment #3: gcc410_default_pie_testsuite.patch --]
[-- Type: text/x-patch, Size: 2499 bytes --]

--- 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/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,9 @@
 /* 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* } { "*" } { "" } } */
+/* Skipped on default_pie targets because __PIC__ is
+   defined for executables.  */
+/* { 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
@@ -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
@@ -856,6 +856,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 { } {

[-- Attachment #4: gcc410_default_pie_doc.patch --]
[-- Type: text/x-patch, Size: 1999 bytes --]

--- a/gcc/doc/install.texi	2013-10-01 19:29:40.000000000 +0200
+++ b/gcc/doc/install.texi	2013-11-17 16:13:20.474144921 +0100
@@ -1455,6 +1455,10 @@ 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
+Turn on @option{-fPIE} and @option{-pie} by default if supported.
+Currently supported targets are i?86-*-linux* and x86-64-*-linux*.
+
 @item --disable-libquadmath
 Specify that the GCC quad-precision math library should not be built.
 On some systems, the library is required to be linkable when building
--- a/gcc/doc/invoke.texi	2013-10-03 19:13:50.000000000 +0200
+++ b/gcc/doc/invoke.texi	2013-11-17 21:30:02.784220111 +0100
@@ -10535,6 +10535,12 @@ For predictable results, you must also s
 used for compilation (@option{-fpie}, @option{-fPIE},
 or model suboptions) when you specify this linker option.
 
+NOTE: With configure --enable-default-pie this option is enabled by default
+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.
+
 @item -rdynamic
 @opindex rdynamic
 Pass the flag @option{-export-dynamic} to the ELF linker, on targets
@@ -22476,6 +22476,12 @@ used during linking.
 @code{__pie__} and @code{__PIE__}.  The macros have the value 1
 for @option{-fpie} and 2 for @option{-fPIE}.
 
+NOTE: With configure --enable-default-pie this option is enabled by default
+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.
+
 @item -fno-jump-tables
 @opindex fno-jump-tables
 Do not use jump tables for switch statements even where it would be

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH][1-3] New configure options that make the compiler use -fPIE and -pie as default option
  2014-07-31 20:32 [PATCH][1-3] New configure options that make the compiler use -fPIE and -pie as default option Magnus Granberg
@ 2014-08-01  8:52 ` Rainer Orth
  2014-08-31 15:49   ` Gerald Pfeifer
  2014-11-10 20:33   ` Magnus Granberg
  0 siblings, 2 replies; 20+ messages in thread
From: Rainer Orth @ 2014-08-01  8:52 UTC (permalink / raw)
  To: Magnus Granberg; +Cc: gcc-patches

Hi Magnus,

a couple of comments, mostly nits.

> 2014-07-31  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.

Many of those entries are mis-formatted.  See other examples and the GNU
Coding Standards for details.  E.g. the first would be

	* config/gnu-user.h (PIE_DRIVER_SELF_SPECS): Define.

In general, you need to mention which macro, variable, manual section
you change.  Emacs' add-change-log-entry does the basics for you.
Besides, you only state what changed, not why.

Apart from that, I don't think defining PIE_DRIVER_SELF_SPECS in
gnu-user.h is a good idea.  This way, every other target supporting the
option would have to duplicate that stuff.

	* testsuite/gcc/default-pie.c: New test for new configure option
	--enale-default-pie

gcc/testsuite has its own ChangeLog file.  Typo for --enale-...

	* testsuite/gcc.dg/other/anon5.C: Add skip test as it fail to link
	on effective_target default_pie.

should be

	* g++.dg/other/anon5.C: Skip if default_pie.

No explanations in ChangeLog entries; they belong into the code.
Besides, you had the first dir component wrong.  Again, Emacs does this
for you.

	* 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.

Wrong: should be

	* lib/target-supports.exp (check_effective_target_default_pie):
        New proc.

The new default_pic effective-target keyword needs to be documented in
doc/sourcebuild.texi.

--- 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 } */

Why restrict to Linux, GNU?  default_pie should be enough once other
targets add this.

--- 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,9 @@
 /* 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* } { "*" } { "" } } */
+/* Skipped on default_pie targets because __PIC__ is
+   defined for executables.  */
+/* { dg-skip-if "" { default_pie } { "*" } { "" } }  */

Emit those default args, they're unnecessary.  Also in g++.dg/other/anon5.C.

--- 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 } { "*" } { "" } }

The first arg to dg-skip-if should explain why you're skipping the test.

--- 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.

Grammar: "doesn't work".

+# Return 1 if -pie, -fPIE are default enable, 0 otherwise.
+
+proc check_effective_target_default_pie { } {

Hard to understand, perhaps

# Return 1 if -pie -fPIE are enabled by default, 0 otherwise.

--- a/gcc/doc/invoke.texi	2013-10-03 19:13:50.000000000 +0200
+++ b/gcc/doc/invoke.texi	2013-11-17 21:30:02.784220111 +0100
@@ -10535,6 +10535,12 @@ For predictable results, you must also s
 used for compilation (@option{-fpie}, @option{-fPIE},
 or model suboptions) when you specify this linker option.
 
+NOTE: With configure --enable-default-pie this option is enabled by default

With the @option{--enable-default-pie} configure option, ...

+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.

@option{-static}.

	Rainer

-- 
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH][1-3] New configure options that make the compiler use -fPIE and -pie as default option
  2014-08-01  8:52 ` Rainer Orth
@ 2014-08-31 15:49   ` Gerald Pfeifer
  2014-11-10 20:33   ` Magnus Granberg
  1 sibling, 0 replies; 20+ messages in thread
From: Gerald Pfeifer @ 2014-08-31 15:49 UTC (permalink / raw)
  To: Magnus Granberg, Rainer Orth; +Cc: gcc-patches

On Fri, 1 Aug 2014, Rainer Orth wrote:
> +NOTE: With configure --enable-default-pie this option is enabled by default
> 
> With the @option{--enable-default-pie} configure option, ...

And just "Note: " or perhaps "@emph{Note}:" as in many other cases.

Gerald

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH][1-3] New configure options that make the compiler use -fPIE and -pie as default option
  2014-08-01  8:52 ` Rainer Orth
  2014-08-31 15:49   ` Gerald Pfeifer
@ 2014-11-10 20:33   ` Magnus Granberg
  2014-11-14 23:19     ` Magnus Granberg
  2015-01-09 10:48     ` [PATCH][1-3] " Marcus Meissner
  1 sibling, 2 replies; 20+ messages in thread
From: Magnus Granberg @ 2014-11-10 20:33 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 5878 bytes --]

fredag 01 augusti 2014 10.52.27 skrev  Rainer Orth:
> Hi Magnus,
> 
> a couple of comments, mostly nits.
> 
> > 2014-07-31  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.
> 
> Many of those entries are mis-formatted.  See other examples and the GNU
> Coding Standards for details.  E.g. the first would be
> 
> 	* config/gnu-user.h (PIE_DRIVER_SELF_SPECS): Define.
> 
> In general, you need to mention which macro, variable, manual section
> you change.  Emacs' add-change-log-entry does the basics for you.
> Besides, you only state what changed, not why.
> 
> Apart from that, I don't think defining PIE_DRIVER_SELF_SPECS in
> gnu-user.h is a good idea.  This way, every other target supporting the
> option would have to duplicate that stuff.
> 
> 	* testsuite/gcc/default-pie.c: New test for new configure option
> 	--enale-default-pie
> 
> gcc/testsuite has its own ChangeLog file.  Typo for --enale-...
> 
> 	* testsuite/gcc.dg/other/anon5.C: Add skip test as it fail to link
> 	on effective_target default_pie.
> 
> should be
> 
> 	* g++.dg/other/anon5.C: Skip if default_pie.
> 
> No explanations in ChangeLog entries; they belong into the code.
> Besides, you had the first dir component wrong.  Again, Emacs does this
> for you.
> 
> 	* 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.
> 
> Wrong: should be
> 
> 	* lib/target-supports.exp (check_effective_target_default_pie):
>         New proc.
> 
> The new default_pic effective-target keyword needs to be documented in
> doc/sourcebuild.texi.
> 
> --- 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 } */
> 
> Why restrict to Linux, GNU?  default_pie should be enough once other
> targets add this.
> 
> --- 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,9 @@
>  /* 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* } {
> "*" } { "" } } */ +/* Skipped on default_pie targets because __PIC__ is
> +   defined for executables.  */
> +/* { dg-skip-if "" { default_pie } { "*" } { "" } }  */
> 
> Emit those default args, they're unnecessary.  Also in g++.dg/other/anon5.C.
> 
> --- 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 } { "*" } { "" } }
> 
> The first arg to dg-skip-if should explain why you're skipping the test.
> 
> --- 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.
> 
> Grammar: "doesn't work".
> 
> +# Return 1 if -pie, -fPIE are default enable, 0 otherwise.
> +
> +proc check_effective_target_default_pie { } {
> 
> Hard to understand, perhaps
> 
> # Return 1 if -pie -fPIE are enabled by default, 0 otherwise.
> 
> --- a/gcc/doc/invoke.texi	2013-10-03 19:13:50.000000000 +0200
> +++ b/gcc/doc/invoke.texi	2013-11-17 21:30:02.784220111 +0100
> @@ -10535,6 +10535,12 @@ For predictable results, you must also s
>  used for compilation (@option{-fpie}, @option{-fPIE},
>  or model suboptions) when you specify this linker option.
> 
> +NOTE: With configure --enable-default-pie this option is enabled by default
> 
> With the @option{--enable-default-pie} configure option, ...
> 
> +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.
> 
> @option{-static}.
> 
> 	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.

[-- Attachment #2: gcc50_default_pie_doc.patch --]
[-- Type: text/x-patch, Size: 2479 bytes --]

--- a/gcc/doc/install.texi	2013-10-01 19:29:40.000000000 +0200
+++ b/gcc/doc/install.texi	2013-11-17 16:13:20.474144921 +0100
@@ -1455,6 +1455,10 @@ 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
+Turn on @option{-fPIE} and @option{-pie} by default if supported.
+Currently supported targets are i?86-*-linux* and x86-64-*-linux*.
+
 @item --disable-libquadmath
 Specify that the GCC quad-precision math library should not be built.
 On some systems, the library is required to be linkable when building
--- a/gcc/doc/invoke.texi	2013-10-03 19:13:50.000000000 +0200
+++ b/gcc/doc/invoke.texi	2013-11-17 21:30:02.784220111 +0100
@@ -10535,6 +10535,13 @@ For predictable results, you must also s
 used for compilation (@option{-fpie}, @option{-fPIE},
 or model suboptions) when you specify this linker option.
 
+@emph{Note}: With the @option{--enable-default-pie} configure option, this
+options is enabled by default 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.
+
 @item -rdynamic
 @opindex rdynamic
 Pass the flag @option{-export-dynamic} to the ELF linker, on targets
@@ -22476,6 +22476,13 @@ used during linking.
 @code{__pie__} and @code{__PIE__}.  The macros have the value 1
 for @option{-fpie} and 2 for @option{-fPIE}.
 
+@emph{Note}: With the @option{--enable-default-pie} configure option, this
+options is enabled by default 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.
+
 @item -fno-jump-tables
 @opindex fno-jump-tables
 Do not use jump tables for switch statements even where it would be
--- a/gcc/doc/sourcebuild.texi	2014-08-20 17:56:45.000000000 +0200
+++ b/gcc/doc/sourcebuild.texi	2014-11-09 23:43:06.254817553 +0100
@@ -1881,6 +1881,9 @@ Target supports @option{-mpe-aligned-com
 @item pie
 Target supports @option{-pie}, @option{-fpie} and @option{-fPIE}.
 
+@item default_pie
+Target enable @option{-pie}, and @option{-fPIE} as default.
+
 @item section_anchors
 Target supports section anchors.
 

[-- Attachment #3: gcc50_default_pie_main.patch --]
[-- Type: text/x-patch, Size: 5453 bytes --]

--- a/gcc/config/gnu-user.h	2013-08-20 10:31:40.000000000 +0200
+++ b/gcc/config/gnu-user.h	2013-10-23 22:01:42.337238981 +0200
@@ -126,3 +126,17 @@ see the files COPYING3 and COPYING.RUNTI
   LD_STATIC_OPTION " --whole-archive -ltsan --no-whole-archive " \
   LD_DYNAMIC_OPTION "}}%{!static-libtsan:-ltsan}"
 #endif
+
+/* We use this to make the compiler use -fPIE as default and link
+   with -pie.  */
+#ifdef ENABLE_DEFAULT_PIE
+#define PIE_DRIVER_SELF_SPECS \
+"%{pie|fpic|fPIC|fpie|fPIE|fno-pic|fno-PIC|fno-pie|fno-PIE| \
+  shared|static|nostdlib|nodefaultlibs|nostartfiles:;:-fPIE -pie}"
+#else
+#define PIE_DRIVER_SELF_SPECS ""
+#endif
+
+#ifndef GNU_DRIVER_SELF_SPECS
+#define GNU_DRIVER_SELF_SPECS PIE_DRIVER_SELF_SPECS
+#endif
--- a/gcc/config/i386/gnu-user-common.h	2013-01-10 21:38:27.000000000 +0100
+++ b/gcc/config/i386/gnu-user-common.h	2013-10-23 17:37:45.432767049 +0200
@@ -70,3 +70,8 @@ along with GCC; see the file COPYING3.
 
 /* Static stack checking is supported by means of probes.  */
 #define STACK_CHECK_STATIC_BUILTIN 1
+
+/* Use GNU_DRIVER_SELF_SPECS.  */
+#ifndef DRIVER_SELF_SPECS
+#define DRIVER_SELF_SPECS GNU_DRIVER_SELF_SPECS
+#endif
--- a/gcc/configure.ac	2014-04-28 16:01:40.000000000 +0200
+++ b/gcc/configure.ac	2014-05-08 02:42:30.900883247 +0200
@@ -5671,6 +5671,36 @@ 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])],
+enable_default_pie=$enableval,
+enable_default_pie=no)
+if test x$enable_default_pie = xyes; then
+  AC_MSG_CHECKING(if $target supports default PIE)
+  enable_default_pie=no
+  case $target in
+    i?86*-*-linux* | x86_64*-*-linux*)
+      saved_LDFLAGS="$LDFLAGS"
+      saved_CFLAGS="$CFLAGS"
+      CFLAGS="$CFLAGS -fPIE"
+      LDFLAGS="$LDFLAGS -fPIE -pie"
+      AC_TRY_LINK(,,[enable_default_pie=yes],)
+      LDFLAGS="$saved_LDFLAGS"
+      CFLAGS="$saved_CFLAGS"
+      ;;
+    *)
+      ;;
+    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 supports default PIE and it is enabled.])
+fi
+AC_SUBST([enable_default_pie])
+
 # Configure the subdirectories
 # AC_CONFIG_SUBDIRS($subdirs)
 
--- a/gcc/Makefile.in	2013-10-02 21:52:27.000000000 +0200
+++ b/gcc/Makefile.in	2013-10-24 17:46:22.055357122 +0200
@@ -968,14 +968,23 @@ CONTEXT_H = context.h
 # cross compiler which does not use the native headers and libraries.
 INTERNAL_CFLAGS = -DIN_GCC $(PICFLAG) @CROSS@
 
+# We don't want to compile the compiler with -fPIE, it make PCH fail.
+enable_default_pie = @enable_default_pie@
+ifeq ($(enable_default_pie),yes)
+NOPIE_CFLAGS = -fno-PIE
+else
+NOPIE_CFLAGS=
+endif
+
 # This is the variable actually used when we compile. If you change this,
 # you probably want to update BUILD_CFLAGS in configure.ac
-ALL_CFLAGS = $(T_CFLAGS) $(CFLAGS-$@) \
+ALL_CFLAGS = $(NOPIE_CFLAGS) $(T_CFLAGS) $(CFLAGS-$@) \
   $(CFLAGS) $(INTERNAL_CFLAGS) $(COVERAGE_FLAGS) $(WARN_CFLAGS) @DEFS@
 
 # The C++ version.
-ALL_CXXFLAGS = $(T_CFLAGS) $(CFLAGS-$@) $(CXXFLAGS) $(INTERNAL_CFLAGS) \
-  $(COVERAGE_FLAGS) $(NOEXCEPTION_FLAGS) $(WARN_CXXFLAGS) @DEFS@
+ALL_CXXFLAGS = $(NOPIE_CFLAGS) $(T_CFLAGS) $(CFLAGS-$@) $(CXXFLAGS) \
+  $(INTERNAL_CFLAGS) $(COVERAGE_FLAGS) $(NOEXCEPTION_FLAGS) \
+  $(WARN_CXXFLAGS) @DEFS@
 
 # Likewise.  Put INCLUDES at the beginning: this way, if some autoconf macro
 # puts -I options in CPPFLAGS, our include files in the srcdir will always
@@ -1831,6 +1831,7 @@ libgcc.mvars: config.status Makefile spe
 	echo GCC_CFLAGS = '$(GCC_CFLAGS)' >> tmp-libgcc.mvars
 	echo INHIBIT_LIBC_CFLAGS = '$(INHIBIT_LIBC_CFLAGS)' >> tmp-libgcc.mvars
 	echo TARGET_SYSTEM_ROOT = '$(TARGET_SYSTEM_ROOT)' >> tmp-libgcc.mvars
+	echo enable_default_pie = '$(enable_default_pie)' >> tmp-libgcc.mvars
 
 	mv tmp-libgcc.mvars libgcc.mvars
 
@@ -3536,6 +3536,9 @@ site.exp: ./config.status Makefile
 	@if test "@enable_lto@" = "yes" ; then \
 	  echo "set ENABLE_LTO 1" >> ./site.tmp; \
 	fi
+	@if test "@enable_default_pie@" = "yes" ; then \
+	  echo "set ENABLE_DEFAULT_PIE 1" >> ./site.tmp; \
+	fi
 # If newlib has been configured, we need to pass -B to gcc so it can find
 # newlib's crt0.o if it exists.  This will cause a "path prefix not used"
 # message if it doesn't, but the testsuite is supposed to ignore the message -
--- a/libgcc/Makefile.in	2014-10-30 18:28:30.000000000 +0100
+++ b/libgcc/Makefile.in	2014-11-08 20:37:04.462496763 +0100
@@ -281,11 +281,19 @@ override CFLAGS := $(filter-out -fprofil
 INTERNAL_CFLAGS = $(CFLAGS) $(LIBGCC2_CFLAGS) $(HOST_LIBGCC2_CFLAGS) \
 		  $(INCLUDES) @set_have_cc_tls@ @set_use_emutls@
 
+#Don't use -fPIE when compiling crtbegin/end.
+ifeq ($(enable_default_pie),yes)
+NOPIE_CFLAGS = -fno-PIE
+else
+NOPIE_CFLAGS=
+endif
+
 # Options to use when compiling crtbegin/end.
 CRTSTUFF_CFLAGS = -O2 $(GCC_CFLAGS) $(INCLUDES) $(MULTILIB_CFLAGS) -g0 \
   -finhibit-size-directive -fno-inline -fno-exceptions \
   -fno-zero-initialized-in-bss -fno-toplevel-reorder -fno-tree-vectorize \
   -fbuilding-libgcc -fno-stack-protector $(FORCE_EXPLICIT_EH_REGISTRY) \
+  $(NOPIE_CFLAGS) \
   $(INHIBIT_LIBC_CFLAGS)
 
 # Extra flags to use when compiling crt{begin,end}.o.

[-- Attachment #4: gcc50_default_pie_testsuite.patch --]
[-- Type: text/x-patch, Size: 2361 bytes --]

--- 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
@@ -474,6 +474,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
@@ -856,6 +856,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 { } {

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH][1-3] New configure options that make the compiler use -fPIE and -pie as default option
  2014-11-10 20:33   ` Magnus Granberg
@ 2014-11-14 23:19     ` Magnus Granberg
  2014-12-30 22:04       ` [PING][PATCH][1-3] " Magnus Granberg
  2015-01-09 10:48     ` [PATCH][1-3] " Marcus Meissner
  1 sibling, 1 reply; 20+ messages in thread
From: Magnus Granberg @ 2014-11-14 23:19 UTC (permalink / raw)
  To: gcc-patches

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.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PING][PATCH][1-3] New configure options that make the compiler use -fPIE and -pie as default option
  2014-11-14 23:19     ` Magnus Granberg
@ 2014-12-30 22:04       ` Magnus Granberg
  2015-01-09  4:31         ` Allan McRae
  2015-01-09 13:04         ` Richard Biener
  0 siblings, 2 replies; 20+ messages in thread
From: Magnus Granberg @ 2014-12-30 22:04 UTC (permalink / raw)
  To: gcc-patches, danielmicay

[-- Attachment #1: Type: text/plain, Size: 2284 bytes --]

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.


[-- Attachment #2: gcc50_default_pie_doc.patch --]
[-- Type: text/x-patch, Size: 2479 bytes --]

--- a/gcc/doc/install.texi	2013-10-01 19:29:40.000000000 +0200
+++ b/gcc/doc/install.texi	2013-11-17 16:13:20.474144921 +0100
@@ -1583,6 +1583,10 @@ 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
+Turn on @option{-fPIE} and @option{-pie} by default if supported.
+Currently supported targets are i?86-*-linux* and x86-64-*-linux*.
+
 @item --disable-libquadmath
 Specify that the GCC quad-precision math library should not be built.
 On some systems, the library is required to be linkable when building
--- a/gcc/doc/invoke.texi	2013-10-03 19:13:50.000000000 +0200
+++ b/gcc/doc/invoke.texi	2013-11-17 21:30:02.784220111 +0100
@@ -10898,6 +10898,13 @@ For predictable results, you must also s
 used for compilation (@option{-fpie}, @option{-fPIE},
 or model suboptions) when you specify this linker option.
 
+@emph{Note}: With the @option{--enable-default-pie} configure option, this
+options is enabled by default 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.
+
 @item -rdynamic
 @opindex rdynamic
 Pass the flag @option{-export-dynamic} to the ELF linker, on targets
@@ -23071,6 +23071,13 @@ used during linking.
 @code{__pie__} and @code{__PIE__}.  The macros have the value 1
 for @option{-fpie} and 2 for @option{-fPIE}.
 
+@emph{Note}: With the @option{--enable-default-pie} configure option, this
+options is enabled by default 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.
+
 @item -fno-jump-tables
 @opindex fno-jump-tables
 Do not use jump tables for switch statements even where it would be
--- a/gcc/doc/sourcebuild.texi	2014-08-20 17:56:45.000000000 +0200
+++ b/gcc/doc/sourcebuild.texi	2014-11-09 23:43:06.254817553 +0100
@@ -1890,6 +1890,9 @@ Target supports @option{-mpe-aligned-com
 @item pie
 Target supports @option{-pie}, @option{-fpie} and @option{-fPIE}.
 
+@item default_pie
+Target enable @option{-pie}, and @option{-fPIE} as default.
+
 @item section_anchors
 Target supports section anchors.
 

[-- Attachment #3: gcc50_default_pie_main.patch --]
[-- Type: text/x-patch, Size: 5352 bytes --]

--- a/gcc/config/gnu-user.h	2013-08-20 10:31:40.000000000 +0200
+++ b/gcc/config/gnu-user.h	2013-10-23 22:01:42.337238981 +0200
@@ -131,3 +131,13 @@ see the files COPYING3 and COPYING.RUNTI
   LD_STATIC_OPTION " --whole-archive -llsan --no-whole-archive " \
   LD_DYNAMIC_OPTION "}}%{!static-liblsan:-llsan}"
 #endif
+
+/* We use this to make the compiler use -fPIE as default and link
+   with -pie.  */
+#ifdef ENABLE_DEFAULT_PIE
+#define PIE_DRIVER_SELF_SPECS \
+"%{pie|fpic|fPIC|fpie|fPIE|fno-pic|fno-PIC|fno-pie|fno-PIE| \
+  shared|static|nostdlib|nodefaultlibs|nostartfiles:;:-fPIE -pie}"
+#else
+#define PIE_DRIVER_SELF_SPECS ""
+#endif
--- a/gcc/config/i386/gnu-user-common.h	2013-01-10 21:38:27.000000000 +0100
+++ b/gcc/config/i386/gnu-user-common.h	2013-10-23 17:37:45.432767049 +0200
@@ -70,3 +70,8 @@ along with GCC; see the file COPYING3.
 #if HAVE_GAS_CFI_PERSONALITY_DIRECTIVE
 #define TARGET_CAN_SPLIT_STACK
 #endif
+
+/* include PIE_DRIVER_SELF_SPECS.  */
+#ifndef DRIVER_SELF_SPECS
+#define DRIVER_SELF_SPECS PIE_DRIVER_SELF_SPECS
+#endif
--- a/gcc/configure.ac	2014-04-28 16:01:40.000000000 +0200
+++ b/gcc/configure.ac	2014-05-08 02:42:30.900883247 +0200
@@ -5754,6 +5754,36 @@ if test x"${LINKER_HASH_STYLE}" != x; th
 #define GCC_DRIVER_NAME "${target_noncanonical}-gcc-${gcc_BASEVER}${exeext}"
 EOF
 
+# 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])],
+enable_default_pie=$enableval,
+enable_default_pie=no)
+if test x$enable_default_pie = xyes; then
+  AC_MSG_CHECKING(if $target supports default PIE)
+  enable_default_pie=no
+  case $target in
+    i?86*-*-linux* | x86_64*-*-linux*)
+      saved_LDFLAGS="$LDFLAGS"
+      saved_CFLAGS="$CFLAGS"
+      CFLAGS="$CFLAGS -fPIE"
+      LDFLAGS="$LDFLAGS -fPIE -pie"
+      AC_TRY_LINK(,,[enable_default_pie=yes],)
+      LDFLAGS="$saved_LDFLAGS"
+      CFLAGS="$saved_CFLAGS"
+      ;;
+    *)
+      ;;
+    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 supports default PIE and it is enabled.])
+fi
+AC_SUBST([enable_default_pie])
+
 # Configure the subdirectories
 # AC_CONFIG_SUBDIRS($subdirs)
 
--- a/gcc/Makefile.in	2013-10-02 21:52:27.000000000 +0200
+++ b/gcc/Makefile.in	2013-10-24 17:46:22.055357122 +0200
@@ -963,14 +963,23 @@ CONTEXT_H = context.h
 # cross compiler which does not use the native headers and libraries.
 INTERNAL_CFLAGS = -DIN_GCC $(PICFLAG) @CROSS@
 
+# We don't want to compile the compiler with -fPIE, it make PCH fail.
+enable_default_pie = @enable_default_pie@
+ifeq ($(enable_default_pie),yes)
+NOPIE_CFLAGS = -fno-PIE
+else
+NOPIE_CFLAGS=
+endif
+
 # This is the variable actually used when we compile. If you change this,
 # you probably want to update BUILD_CFLAGS in configure.ac
-ALL_CFLAGS = $(T_CFLAGS) $(CFLAGS-$@) \
+ALL_CFLAGS = $(NOPIE_CFLAGS) $(T_CFLAGS) $(CFLAGS-$@) \
   $(CFLAGS) $(INTERNAL_CFLAGS) $(COVERAGE_FLAGS) $(WARN_CFLAGS) @DEFS@
 
 # The C++ version.
-ALL_CXXFLAGS = $(T_CFLAGS) $(CFLAGS-$@) $(CXXFLAGS) $(INTERNAL_CFLAGS) \
-  $(COVERAGE_FLAGS) $(NOEXCEPTION_FLAGS) $(WARN_CXXFLAGS) @DEFS@
+ALL_CXXFLAGS = $(NOPIE_CFLAGS) $(T_CFLAGS) $(CFLAGS-$@) $(CXXFLAGS) \
+  $(INTERNAL_CFLAGS) $(COVERAGE_FLAGS) $(NOEXCEPTION_FLAGS) \
+  $(WARN_CXXFLAGS) @DEFS@
 
 # Likewise.  Put INCLUDES at the beginning: this way, if some autoconf macro
 # puts -I options in CPPFLAGS, our include files in the srcdir will always
@@ -1854,6 +1854,7 @@ libgcc.mvars: config.status Makefile spe
 	echo GCC_CFLAGS = '$(GCC_CFLAGS)' >> tmp-libgcc.mvars
 	echo INHIBIT_LIBC_CFLAGS = '$(INHIBIT_LIBC_CFLAGS)' >> tmp-libgcc.mvars
 	echo TARGET_SYSTEM_ROOT = '$(TARGET_SYSTEM_ROOT)' >> tmp-libgcc.mvars
+	echo enable_default_pie = '$(enable_default_pie)' >> tmp-libgcc.mvars
 
 	mv tmp-libgcc.mvars libgcc.mvars
 
@@ -3609,6 +3609,9 @@ site.exp: ./config.status Makefile
 	@if test "@enable_lto@" = "yes" ; then \
 	  echo "set ENABLE_LTO 1" >> ./site.tmp; \
 	fi
+	@if test "@enable_default_pie@" = "yes" ; then \
+	  echo "set ENABLE_DEFAULT_PIE 1" >> ./site.tmp; \
+	fi
 # If newlib has been configured, we need to pass -B to gcc so it can find
 # newlib's crt0.o if it exists.  This will cause a "path prefix not used"
 # message if it doesn't, but the testsuite is supposed to ignore the message -
--- a/libgcc/Makefile.in	2014-10-30 18:28:30.000000000 +0100
+++ b/libgcc/Makefile.in	2014-11-08 20:37:04.462496763 +0100
@@ -282,11 +282,19 @@ override CFLAGS := $(filter-out -fprofil
 INTERNAL_CFLAGS = $(CFLAGS) $(LIBGCC2_CFLAGS) $(HOST_LIBGCC2_CFLAGS) \
 		  $(INCLUDES) @set_have_cc_tls@ @set_use_emutls@
 
+#Don't use -fPIE when compiling crtbegin/end.
+ifeq ($(enable_default_pie),yes)
+NOPIE_CFLAGS = -fno-PIE
+else
+NOPIE_CFLAGS=
+endif
+
 # Options to use when compiling crtbegin/end.
 CRTSTUFF_CFLAGS = -O2 $(GCC_CFLAGS) $(INCLUDES) $(MULTILIB_CFLAGS) -g0 \
   -finhibit-size-directive -fno-inline -fno-exceptions \
   -fno-zero-initialized-in-bss -fno-toplevel-reorder -fno-tree-vectorize \
   -fbuilding-libgcc -fno-stack-protector $(FORCE_EXPLICIT_EH_REGISTRY) \
+  $(NOPIE_CFLAGS) \
   $(INHIBIT_LIBC_CFLAGS)
 
 # Extra flags to use when compiling crt{begin,end}.o.

[-- Attachment #4: gcc50_default_pie_testsuite.patch --]
[-- Type: text/x-patch, Size: 2361 bytes --]

--- 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 { } {

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PING][PATCH][1-3] New configure options that make the compiler use -fPIE and -pie as default option
  2014-12-30 22:04       ` [PING][PATCH][1-3] " Magnus Granberg
@ 2015-01-09  4:31         ` Allan McRae
  2015-01-09 13:04         ` Richard Biener
  1 sibling, 0 replies; 20+ messages in thread
From: Allan McRae @ 2015-01-09  4:31 UTC (permalink / raw)
  To: Magnus Granberg, gcc-patches, danielmicay

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.
> 

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH][1-3] New configure options that make the compiler use -fPIE and -pie as default option
  2014-11-10 20:33   ` Magnus Granberg
  2014-11-14 23:19     ` Magnus Granberg
@ 2015-01-09 10:48     ` Marcus Meissner
  1 sibling, 0 replies; 20+ messages in thread
From: Marcus Meissner @ 2015-01-09 10:48 UTC (permalink / raw)
  To: Magnus Granberg, gcc-patches

Hi,

can this be added for GCC 5? 

It would be interesting for SUSE too.

Ciao, Marcus
On Mon, Nov 10, 2014 at 09:26:39PM +0100, Magnus Granberg wrote:
> fredag 01 augusti 2014 10.52.27 skrev  Rainer Orth:
> > Hi Magnus,
> > 
> > a couple of comments, mostly nits.
> > 
> > > 2014-07-31  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.
> > 
> > Many of those entries are mis-formatted.  See other examples and the GNU
> > Coding Standards for details.  E.g. the first would be
> > 
> > 	* config/gnu-user.h (PIE_DRIVER_SELF_SPECS): Define.
> > 
> > In general, you need to mention which macro, variable, manual section
> > you change.  Emacs' add-change-log-entry does the basics for you.
> > Besides, you only state what changed, not why.
> > 
> > Apart from that, I don't think defining PIE_DRIVER_SELF_SPECS in
> > gnu-user.h is a good idea.  This way, every other target supporting the
> > option would have to duplicate that stuff.
> > 
> > 	* testsuite/gcc/default-pie.c: New test for new configure option
> > 	--enale-default-pie
> > 
> > gcc/testsuite has its own ChangeLog file.  Typo for --enale-...
> > 
> > 	* testsuite/gcc.dg/other/anon5.C: Add skip test as it fail to link
> > 	on effective_target default_pie.
> > 
> > should be
> > 
> > 	* g++.dg/other/anon5.C: Skip if default_pie.
> > 
> > No explanations in ChangeLog entries; they belong into the code.
> > Besides, you had the first dir component wrong.  Again, Emacs does this
> > for you.
> > 
> > 	* 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.
> > 
> > Wrong: should be
> > 
> > 	* lib/target-supports.exp (check_effective_target_default_pie):
> >         New proc.
> > 
> > The new default_pic effective-target keyword needs to be documented in
> > doc/sourcebuild.texi.
> > 
> > --- 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 } */
> > 
> > Why restrict to Linux, GNU?  default_pie should be enough once other
> > targets add this.
> > 
> > --- 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,9 @@
> >  /* 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* } {
> > "*" } { "" } } */ +/* Skipped on default_pie targets because __PIC__ is
> > +   defined for executables.  */
> > +/* { dg-skip-if "" { default_pie } { "*" } { "" } }  */
> > 
> > Emit those default args, they're unnecessary.  Also in g++.dg/other/anon5.C.
> > 
> > --- 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 } { "*" } { "" } }
> > 
> > The first arg to dg-skip-if should explain why you're skipping the test.
> > 
> > --- 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.
> > 
> > Grammar: "doesn't work".
> > 
> > +# Return 1 if -pie, -fPIE are default enable, 0 otherwise.
> > +
> > +proc check_effective_target_default_pie { } {
> > 
> > Hard to understand, perhaps
> > 
> > # Return 1 if -pie -fPIE are enabled by default, 0 otherwise.
> > 
> > --- a/gcc/doc/invoke.texi	2013-10-03 19:13:50.000000000 +0200
> > +++ b/gcc/doc/invoke.texi	2013-11-17 21:30:02.784220111 +0100
> > @@ -10535,6 +10535,12 @@ For predictable results, you must also s
> >  used for compilation (@option{-fpie}, @option{-fPIE},
> >  or model suboptions) when you specify this linker option.
> > 
> > +NOTE: With configure --enable-default-pie this option is enabled by default
> > 
> > With the @option{--enable-default-pie} configure option, ...
> > 
> > +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.
> > 
> > @option{-static}.
> > 
> > 	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.

> --- a/gcc/doc/install.texi	2013-10-01 19:29:40.000000000 +0200
> +++ b/gcc/doc/install.texi	2013-11-17 16:13:20.474144921 +0100
> @@ -1455,6 +1455,10 @@ 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
> +Turn on @option{-fPIE} and @option{-pie} by default if supported.
> +Currently supported targets are i?86-*-linux* and x86-64-*-linux*.
> +
>  @item --disable-libquadmath
>  Specify that the GCC quad-precision math library should not be built.
>  On some systems, the library is required to be linkable when building
> --- a/gcc/doc/invoke.texi	2013-10-03 19:13:50.000000000 +0200
> +++ b/gcc/doc/invoke.texi	2013-11-17 21:30:02.784220111 +0100
> @@ -10535,6 +10535,13 @@ For predictable results, you must also s
>  used for compilation (@option{-fpie}, @option{-fPIE},
>  or model suboptions) when you specify this linker option.
>  
> +@emph{Note}: With the @option{--enable-default-pie} configure option, this
> +options is enabled by default 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.
> +
>  @item -rdynamic
>  @opindex rdynamic
>  Pass the flag @option{-export-dynamic} to the ELF linker, on targets
> @@ -22476,6 +22476,13 @@ used during linking.
>  @code{__pie__} and @code{__PIE__}.  The macros have the value 1
>  for @option{-fpie} and 2 for @option{-fPIE}.
>  
> +@emph{Note}: With the @option{--enable-default-pie} configure option, this
> +options is enabled by default 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.
> +
>  @item -fno-jump-tables
>  @opindex fno-jump-tables
>  Do not use jump tables for switch statements even where it would be
> --- a/gcc/doc/sourcebuild.texi	2014-08-20 17:56:45.000000000 +0200
> +++ b/gcc/doc/sourcebuild.texi	2014-11-09 23:43:06.254817553 +0100
> @@ -1881,6 +1881,9 @@ Target supports @option{-mpe-aligned-com
>  @item pie
>  Target supports @option{-pie}, @option{-fpie} and @option{-fPIE}.
>  
> +@item default_pie
> +Target enable @option{-pie}, and @option{-fPIE} as default.
> +
>  @item section_anchors
>  Target supports section anchors.
>  

> --- a/gcc/config/gnu-user.h	2013-08-20 10:31:40.000000000 +0200
> +++ b/gcc/config/gnu-user.h	2013-10-23 22:01:42.337238981 +0200
> @@ -126,3 +126,17 @@ see the files COPYING3 and COPYING.RUNTI
>    LD_STATIC_OPTION " --whole-archive -ltsan --no-whole-archive " \
>    LD_DYNAMIC_OPTION "}}%{!static-libtsan:-ltsan}"
>  #endif
> +
> +/* We use this to make the compiler use -fPIE as default and link
> +   with -pie.  */
> +#ifdef ENABLE_DEFAULT_PIE
> +#define PIE_DRIVER_SELF_SPECS \
> +"%{pie|fpic|fPIC|fpie|fPIE|fno-pic|fno-PIC|fno-pie|fno-PIE| \
> +  shared|static|nostdlib|nodefaultlibs|nostartfiles:;:-fPIE -pie}"
> +#else
> +#define PIE_DRIVER_SELF_SPECS ""
> +#endif
> +
> +#ifndef GNU_DRIVER_SELF_SPECS
> +#define GNU_DRIVER_SELF_SPECS PIE_DRIVER_SELF_SPECS
> +#endif
> --- a/gcc/config/i386/gnu-user-common.h	2013-01-10 21:38:27.000000000 +0100
> +++ b/gcc/config/i386/gnu-user-common.h	2013-10-23 17:37:45.432767049 +0200
> @@ -70,3 +70,8 @@ along with GCC; see the file COPYING3.
>  
>  /* Static stack checking is supported by means of probes.  */
>  #define STACK_CHECK_STATIC_BUILTIN 1
> +
> +/* Use GNU_DRIVER_SELF_SPECS.  */
> +#ifndef DRIVER_SELF_SPECS
> +#define DRIVER_SELF_SPECS GNU_DRIVER_SELF_SPECS
> +#endif
> --- a/gcc/configure.ac	2014-04-28 16:01:40.000000000 +0200
> +++ b/gcc/configure.ac	2014-05-08 02:42:30.900883247 +0200
> @@ -5671,6 +5671,36 @@ 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])],
> +enable_default_pie=$enableval,
> +enable_default_pie=no)
> +if test x$enable_default_pie = xyes; then
> +  AC_MSG_CHECKING(if $target supports default PIE)
> +  enable_default_pie=no
> +  case $target in
> +    i?86*-*-linux* | x86_64*-*-linux*)
> +      saved_LDFLAGS="$LDFLAGS"
> +      saved_CFLAGS="$CFLAGS"
> +      CFLAGS="$CFLAGS -fPIE"
> +      LDFLAGS="$LDFLAGS -fPIE -pie"
> +      AC_TRY_LINK(,,[enable_default_pie=yes],)
> +      LDFLAGS="$saved_LDFLAGS"
> +      CFLAGS="$saved_CFLAGS"
> +      ;;
> +    *)
> +      ;;
> +    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 supports default PIE and it is enabled.])
> +fi
> +AC_SUBST([enable_default_pie])
> +
>  # Configure the subdirectories
>  # AC_CONFIG_SUBDIRS($subdirs)
>  
> --- a/gcc/Makefile.in	2013-10-02 21:52:27.000000000 +0200
> +++ b/gcc/Makefile.in	2013-10-24 17:46:22.055357122 +0200
> @@ -968,14 +968,23 @@ CONTEXT_H = context.h
>  # cross compiler which does not use the native headers and libraries.
>  INTERNAL_CFLAGS = -DIN_GCC $(PICFLAG) @CROSS@
>  
> +# We don't want to compile the compiler with -fPIE, it make PCH fail.
> +enable_default_pie = @enable_default_pie@
> +ifeq ($(enable_default_pie),yes)
> +NOPIE_CFLAGS = -fno-PIE
> +else
> +NOPIE_CFLAGS=
> +endif
> +
>  # This is the variable actually used when we compile. If you change this,
>  # you probably want to update BUILD_CFLAGS in configure.ac
> -ALL_CFLAGS = $(T_CFLAGS) $(CFLAGS-$@) \
> +ALL_CFLAGS = $(NOPIE_CFLAGS) $(T_CFLAGS) $(CFLAGS-$@) \
>    $(CFLAGS) $(INTERNAL_CFLAGS) $(COVERAGE_FLAGS) $(WARN_CFLAGS) @DEFS@
>  
>  # The C++ version.
> -ALL_CXXFLAGS = $(T_CFLAGS) $(CFLAGS-$@) $(CXXFLAGS) $(INTERNAL_CFLAGS) \
> -  $(COVERAGE_FLAGS) $(NOEXCEPTION_FLAGS) $(WARN_CXXFLAGS) @DEFS@
> +ALL_CXXFLAGS = $(NOPIE_CFLAGS) $(T_CFLAGS) $(CFLAGS-$@) $(CXXFLAGS) \
> +  $(INTERNAL_CFLAGS) $(COVERAGE_FLAGS) $(NOEXCEPTION_FLAGS) \
> +  $(WARN_CXXFLAGS) @DEFS@
>  
>  # Likewise.  Put INCLUDES at the beginning: this way, if some autoconf macro
>  # puts -I options in CPPFLAGS, our include files in the srcdir will always
> @@ -1831,6 +1831,7 @@ libgcc.mvars: config.status Makefile spe
>  	echo GCC_CFLAGS = '$(GCC_CFLAGS)' >> tmp-libgcc.mvars
>  	echo INHIBIT_LIBC_CFLAGS = '$(INHIBIT_LIBC_CFLAGS)' >> tmp-libgcc.mvars
>  	echo TARGET_SYSTEM_ROOT = '$(TARGET_SYSTEM_ROOT)' >> tmp-libgcc.mvars
> +	echo enable_default_pie = '$(enable_default_pie)' >> tmp-libgcc.mvars
>  
>  	mv tmp-libgcc.mvars libgcc.mvars
>  
> @@ -3536,6 +3536,9 @@ site.exp: ./config.status Makefile
>  	@if test "@enable_lto@" = "yes" ; then \
>  	  echo "set ENABLE_LTO 1" >> ./site.tmp; \
>  	fi
> +	@if test "@enable_default_pie@" = "yes" ; then \
> +	  echo "set ENABLE_DEFAULT_PIE 1" >> ./site.tmp; \
> +	fi
>  # If newlib has been configured, we need to pass -B to gcc so it can find
>  # newlib's crt0.o if it exists.  This will cause a "path prefix not used"
>  # message if it doesn't, but the testsuite is supposed to ignore the message -
> --- a/libgcc/Makefile.in	2014-10-30 18:28:30.000000000 +0100
> +++ b/libgcc/Makefile.in	2014-11-08 20:37:04.462496763 +0100
> @@ -281,11 +281,19 @@ override CFLAGS := $(filter-out -fprofil
>  INTERNAL_CFLAGS = $(CFLAGS) $(LIBGCC2_CFLAGS) $(HOST_LIBGCC2_CFLAGS) \
>  		  $(INCLUDES) @set_have_cc_tls@ @set_use_emutls@
>  
> +#Don't use -fPIE when compiling crtbegin/end.
> +ifeq ($(enable_default_pie),yes)
> +NOPIE_CFLAGS = -fno-PIE
> +else
> +NOPIE_CFLAGS=
> +endif
> +
>  # Options to use when compiling crtbegin/end.
>  CRTSTUFF_CFLAGS = -O2 $(GCC_CFLAGS) $(INCLUDES) $(MULTILIB_CFLAGS) -g0 \
>    -finhibit-size-directive -fno-inline -fno-exceptions \
>    -fno-zero-initialized-in-bss -fno-toplevel-reorder -fno-tree-vectorize \
>    -fbuilding-libgcc -fno-stack-protector $(FORCE_EXPLICIT_EH_REGISTRY) \
> +  $(NOPIE_CFLAGS) \
>    $(INHIBIT_LIBC_CFLAGS)
>  
>  # Extra flags to use when compiling crt{begin,end}.o.

> --- 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
> @@ -474,6 +474,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
> @@ -856,6 +856,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 { } {

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PING][PATCH][1-3] New configure options that make the compiler use -fPIE and -pie as default option
  2014-12-30 22:04       ` [PING][PATCH][1-3] " Magnus Granberg
  2015-01-09  4:31         ` Allan McRae
@ 2015-01-09 13:04         ` Richard Biener
  2015-01-09 14:17           ` Daniel Micay
  2015-01-12 16:18           ` [PATCH]: " H.J. Lu
  1 sibling, 2 replies; 20+ messages in thread
From: Richard Biener @ 2015-01-09 13:04 UTC (permalink / raw)
  To: Magnus Granberg, Joseph S. Myers; +Cc: GCC Patches, danielmicay

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.
>

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PING][PATCH][1-3] New configure options that make the compiler use -fPIE and -pie as default option
  2015-01-09 13:04         ` Richard Biener
@ 2015-01-09 14:17           ` Daniel Micay
  2015-01-09 17:57             ` Joseph Myers
  2015-01-12 16:18           ` [PATCH]: " H.J. Lu
  1 sibling, 1 reply; 20+ messages in thread
From: Daniel Micay @ 2015-01-09 14:17 UTC (permalink / raw)
  To: Richard Biener, Magnus Granberg, Joseph S. Myers; +Cc: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 2401 bytes --]

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.


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PING][PATCH][1-3] New configure options that make the compiler use -fPIE and -pie as default option
  2015-01-09 14:17           ` Daniel Micay
@ 2015-01-09 17:57             ` Joseph Myers
  2015-01-09 18:03               ` Daniel Micay
  0 siblings, 1 reply; 20+ messages in thread
From: Joseph Myers @ 2015-01-09 17:57 UTC (permalink / raw)
  To: Daniel Micay; +Cc: Richard Biener, Magnus Granberg, GCC Patches

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).

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PING][PATCH][1-3] New configure options that make the compiler use -fPIE and -pie as default option
  2015-01-09 17:57             ` Joseph Myers
@ 2015-01-09 18:03               ` Daniel Micay
  2015-01-09 20:40                 ` Magnus Granberg
  0 siblings, 1 reply; 20+ messages in thread
From: Daniel Micay @ 2015-01-09 18:03 UTC (permalink / raw)
  To: Joseph Myers; +Cc: Richard Biener, Magnus Granberg, GCC Patches

[-- Attachment #1: Type: text/plain, Size: 1161 bytes --]

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.


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PING][PATCH][1-3] New configure options that make the compiler use -fPIE and -pie as default option
  2015-01-09 18:03               ` Daniel Micay
@ 2015-01-09 20:40                 ` Magnus Granberg
  2015-01-10  2:32                   ` H.J. Lu
  0 siblings, 1 reply; 20+ messages in thread
From: Magnus Granberg @ 2015-01-09 20:40 UTC (permalink / raw)
  To: gcc-patches

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.


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PING][PATCH][1-3] New configure options that make the compiler use -fPIE and -pie as default option
  2015-01-09 20:40                 ` Magnus Granberg
@ 2015-01-10  2:32                   ` H.J. Lu
  2015-01-10 17:06                     ` H.J. Lu
  0 siblings, 1 reply; 20+ messages in thread
From: H.J. Lu @ 2015-01-10  2:32 UTC (permalink / raw)
  To: Magnus Granberg; +Cc: GCC Patches

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.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PING][PATCH][1-3] New configure options that make the compiler use -fPIE and -pie as default option
  2015-01-10  2:32                   ` H.J. Lu
@ 2015-01-10 17:06                     ` H.J. Lu
  0 siblings, 0 replies; 20+ messages in thread
From: H.J. Lu @ 2015-01-10 17:06 UTC (permalink / raw)
  To: Magnus Granberg; +Cc: GCC Patches

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.

-- 
H.J.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option
  2015-01-09 13:04         ` Richard Biener
  2015-01-09 14:17           ` Daniel Micay
@ 2015-01-12 16:18           ` H.J. Lu
  2015-01-12 23:53             ` Joseph Myers
  1 sibling, 1 reply; 20+ messages in thread
From: H.J. Lu @ 2015-01-12 16:18 UTC (permalink / raw)
  To: Richard Biener; +Cc: Magnus Granberg, Joseph S. Myers, GCC Patches, danielmicay

On Fri, Jan 09, 2015 at 01:58:45PM +0100, Richard Biener wrote:
> 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.
> 

This is the new implementation of --enable-default-pie.  Tested on
Linux/x86-64.  OK for trunk?

Thanks.


H.J.
---
gcc/

2015-01-12  Magnus Granberg  <zorry@gentoo.org>
	    H.J. Lu  <hongjiu.lu@intel.com>

	* Makefile.in (COMPILER): Add @NO_PIE_CFLAGS@.
	(LINKER): Add @NO_PIE_FLAG@.
	(libgcc.mvars): Set NO_PIE_CFLAGS to -fno-PIE for
	--enable-default-pie.
	* common.opt (fPIE): Initialize to -1.
	(fpie): Likewise.
	(static): Add "RejectNegative Negative(shared)".
	(no-pie): New option.
	(pie): Replace "Negative(shared)" with "Negative(no-pie)".
	* configure.ac: Add --enable-default-pie.
	(NO_PIE_CFLAGS): New. Check if -fno-PIE works.  AC_SUBST.
	(NO_PIE_FLAG): New. Check if -no-pie works.  AC_SUBST.
	* defaults.h (DEFAULT_FLAG_PIE): New.  Default PIE to -fPIE.
	* gcc.c (NO_PIE_SPEC): New.
	(PIE_SPEC): Likewise.
	(LD_PIE_SPEC): Likewise.
	(LINK_PIE_SPEC): Handle -no-pie.  Use PIE_SPEC and LD_PIE_SPEC.
	* opts.c (DEFAULT_FLAG_PIE): New.  Set to 0 if ENABLE_DEFAULT_PIE
	is undefined.
	(finish_options): Update opts->x_flag_pie if it is -1.
	* config/gnu-user.h (FVTABLE_VERIFY_SPEC): New.
	(GNU_USER_TARGET_STARTFILE_SPEC): Use FVTABLE_VERIFY_SPEC.  Use
	NO_PIE_SPEC and NO_PIE_SPEC if ENABLE_DEFAULT_PIE is defined.
	(GNU_USER_TARGET_STARTFILE_SPEC): Use FVTABLE_VERIFY_SPEC.
	* doc/install.texi: Document --enable-default-pie.
	* doc/invoke.texi: Document -no-pie.
	* config.in: Regenerated.
	* configure: Likewise.

gcc/ada/

2015-01-12  H.J. Lu  <hongjiu.lu@intel.com>

	* gcc-interface/Makefile.in (TOOLS_LIBS): Add @NO_PIE_FLAG@.

libgcc/

2015-01-12  H.J. Lu  <hongjiu.lu@intel.com>

	* Makefile.in (CRTSTUFF_CFLAGS): Add $(NO_PIE_CFLAGS).

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 5f9261f..180751f 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -252,6 +252,12 @@ LINKER = $(CC)
 LINKER_FLAGS = $(CFLAGS)
 endif
 
+# We don't want to compile the compiler with -fPIE, it make PCH fail.
+COMPILER += @NO_PIE_CFLAGS@
+
+# Link with -no-pie since we compile the compiler with -fno-PIE.
+LINKER += @NO_PIE_FLAG@
+
 # Like LINKER, but use a mutex for serializing front end links.
 ifeq (@DO_LINK_MUTEX@,true)
 LLINKER = $(SHELL) $(srcdir)/lock-and-run.sh linkfe.lck $(LINKER)
@@ -1854,6 +1860,12 @@ libgcc.mvars: config.status Makefile specs xgcc$(exeext)
 	echo GCC_CFLAGS = '$(GCC_CFLAGS)' >> tmp-libgcc.mvars
 	echo INHIBIT_LIBC_CFLAGS = '$(INHIBIT_LIBC_CFLAGS)' >> tmp-libgcc.mvars
 	echo TARGET_SYSTEM_ROOT = '$(TARGET_SYSTEM_ROOT)' >> tmp-libgcc.mvars
+	if test @enable_default_pie@ = yes; then \
+	  NO_PIE_CFLAGS="-fno-PIE"; \
+	else \
+	  NO_PIE_CFLAGS=; \
+	fi; \
+	echo NO_PIE_CFLAGS = "$$NO_PIE_CFLAGS" >> tmp-libgcc.mvars
 
 	mv tmp-libgcc.mvars libgcc.mvars
 
diff --git a/gcc/ada/gcc-interface/Makefile.in b/gcc/ada/gcc-interface/Makefile.in
index 870cfab..a446d48 100644
--- a/gcc/ada/gcc-interface/Makefile.in
+++ b/gcc/ada/gcc-interface/Makefile.in
@@ -267,6 +267,9 @@ TOOLS_LIBS = ../link.o ../targext.o ../../ggc-none.o ../../libcommon-target.a \
   ../../libcommon.a ../../../libcpp/libcpp.a $(LIBGNAT) $(LIBINTL) $(LIBICONV) \
   ../$(LIBBACKTRACE) ../$(LIBIBERTY) $(SYSLIBS) $(TGT_LIB)
 
+# Add -no-pie to TOOLS_LIBS since some of them are compiled with -fno-PIE.
+TOOLS_LIBS += @NO_PIE_FLAG@
+
 # Specify the directories to be searched for header files.
 # Both . and srcdir are used, in that order,
 # so that tm.h and config.h will be found in the compilation
diff --git a/gcc/common.opt b/gcc/common.opt
index e104269..b3fdb27 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -1755,7 +1755,7 @@ Common Report Var(flag_pic,2) Negative(fPIE)
 Generate position-independent code if possible (large mode)
 
 fPIE
-Common Report Var(flag_pie,2) Negative(fpic)
+Common Report Var(flag_pie,2) Negative(fpic) Init(-1)
 Generate position-independent code for executables if possible (large mode)
 
 fpic
@@ -1763,7 +1763,7 @@ Common Report Var(flag_pic,1) Negative(fpie)
 Generate position-independent code if possible (small mode)
 
 fpie
-Common Report Var(flag_pie,1) Negative(fPIC)
+Common Report Var(flag_pie,1) Negative(fPIC) Init(-1)
 Generate position-independent code for executables if possible (small mode)
 
 fplugin=
@@ -2792,7 +2792,7 @@ specs=
 Driver Joined
 
 static
-Driver
+Driver RejectNegative Negative(shared)
 
 static-libgcc
 Driver
@@ -2823,8 +2823,12 @@ Driver
 symbolic
 Driver
 
+no-pie
+Driver RejectNegative Negative(static)
+Don't create a position independent executable
+
 pie
-Driver RejectNegative Negative(shared)
+Driver RejectNegative Negative(no-pie)
 Create a position independent executable
 
 z
diff --git a/gcc/config.in b/gcc/config.in
index f34adb5..3fc018a 100644
--- a/gcc/config.in
+++ b/gcc/config.in
@@ -89,6 +89,12 @@
 #endif
 
 
+/* Define if your target supports default PIE and it is enabled. */
+#ifndef USED_FOR_TARGET
+#undef ENABLE_DEFAULT_PIE
+#endif
+
+
 /* Define if you want more run-time sanity checks for dataflow. */
 #ifndef USED_FOR_TARGET
 #undef ENABLE_DF_CHECKING
diff --git a/gcc/config/gnu-user.h b/gcc/config/gnu-user.h
index 2faa2e5..5cbe5da 100644
--- a/gcc/config/gnu-user.h
+++ b/gcc/config/gnu-user.h
@@ -41,19 +41,29 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
    object constructed before entering `main'.  */
 
 #if defined HAVE_LD_PIE
-#define GNU_USER_TARGET_STARTFILE_SPEC \
-  "%{!shared: %{pg|p|profile:gcrt1.o%s;pie:Scrt1.o%s;:crt1.o%s}} \
-   crti.o%s %{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbegin.o%s} \
-   %{fvtable-verify=none:%s; \
+#define FVTABLE_VERIFY_SPEC \
+  "%{fvtable-verify=none:%s; \
      fvtable-verify=preinit:vtv_start_preinit.o%s; \
      fvtable-verify=std:vtv_start.o%s}"
+#if defined ENABLE_DEFAULT_PIE
+#define GNU_USER_TARGET_STARTFILE_SPEC \
+  "%{!shared: %{pg|p|profile:gcrt1.o%s;: \
+    %{" PIE_SPEC ":Scrt1.o%s} %{" NO_PIE_SPEC ":crt1.o%s}}} \
+   crti.o%s %{static:crtbeginT.o%s;: %{shared:crtbeginS.o%s} \
+	      %{" PIE_SPEC ":crtbeginS.o%s} \
+	      %{" NO_PIE_SPEC ":crtbegin.o%s}}" \
+   FVTABLE_VERIFY_SPEC
+#else
+#define GNU_USER_TARGET_STARTFILE_SPEC \
+  "%{!shared: %{pg|p|profile:gcrt1.o%s;pie:Scrt1.o%s;:crt1.o%s}} \
+   crti.o%s %{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbegin.o%s}" \
+   FVTABLE_VERIFY_SPEC
+#endif
 #else
 #define GNU_USER_TARGET_STARTFILE_SPEC \
   "%{!shared: %{pg|p|profile:gcrt1.o%s;:crt1.o%s}} \
-   crti.o%s %{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbegin.o%s} \
-   %{fvtable-verify=none:%s; \
-     fvtable-verify=preinit:vtv_start_preinit.o%s; \
-     fvtable-verify=std:vtv_start.o%s}"
+   crti.o%s %{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbegin.o%s}" \
+   FVTABLE_VERIFY_SPEC
 #endif
 #undef  STARTFILE_SPEC
 #define STARTFILE_SPEC GNU_USER_TARGET_STARTFILE_SPEC
diff --git a/gcc/configure b/gcc/configure
index 1bf4358..57debff 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -600,6 +600,9 @@ ac_includes_default="\
 
 ac_subst_vars='LTLIBOBJS
 LIBOBJS
+NO_PIE_FLAG
+NO_PIE_CFLAGS
+enable_default_pie
 PICFLAG
 enable_host_shared
 enable_plugin
@@ -937,6 +940,7 @@ enable_host_shared
 enable_libquadmath_support
 with_linker_hash_style
 with_diagnostics_color
+enable_default_pie
 '
       ac_precious_vars='build_alias
 host_alias
@@ -1665,6 +1669,7 @@ Optional Features:
   --enable-host-shared    build host code as shared libraries
   --disable-libquadmath-support
                           disable libquadmath support for Fortran
+  --enable-default-pie    enable Position Independent Executable as default
 
 Optional Packages:
   --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
@@ -18147,7 +18152,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 18150 "configure"
+#line 18155 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -18253,7 +18258,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 18256 "configure"
+#line 18261 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -28432,6 +28437,111 @@ cat > gcc-driver-name.h <<EOF
 #define GCC_DRIVER_NAME "${target_noncanonical}-gcc-${gcc_BASEVER}${exeext}"
 EOF
 
+# Check whether --enable-default-pie was given and target have the support.
+# Check whether --enable-default-pie was given.
+if test "${enable_default_pie+set}" = set; then :
+  enableval=$enable_default_pie; enable_default_pie=$enableval
+else
+  enable_default_pie=no
+fi
+
+if test x$enable_default_pie = xyes; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $target supports default PIE" >&5
+$as_echo_n "checking if $target supports default PIE... " >&6; }
+  enable_default_pie=no
+  case $target in
+    i?86*-*-linux* | x86_64*-*-linux*)
+      saved_LDFLAGS="$LDFLAGS"
+      saved_CFLAGS="$CFLAGS"
+      CFLAGS="$CFLAGS -fPIE"
+      LDFLAGS="$LDFLAGS -fPIE -pie"
+      cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  enable_default_pie=yes
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+      LDFLAGS="$saved_LDFLAGS"
+      CFLAGS="$saved_CFLAGS"
+      ;;
+    *)
+      ;;
+    esac
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $enable_default_pie" >&5
+$as_echo "$enable_default_pie" >&6; }
+fi
+if test x$enable_default_pie == xyes ; then
+
+$as_echo "#define ENABLE_DEFAULT_PIE 1" >>confdefs.h
+
+fi
+
+
+# Check if -fno-PIE works.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for -fno-PIE option" >&5
+$as_echo_n "checking for -fno-PIE option... " >&6; }
+if test "${gcc_cv_c_no_fpie+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  saved_CFLAGS="$CFLAGS"
+   CFLAGS="$CFLAGS -fno-PIE"
+   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int main(void) {return 0;}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  gcc_cv_c_no_fpie=yes
+else
+  gcc_cv_c_no_fpie=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+   CFLAGS="$saved_CFLAGS"
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_c_no_fpie" >&5
+$as_echo "$gcc_cv_c_no_fpie" >&6; }
+if test "$gcc_cv_c_no_fpie" = "yes"; then
+  NO_PIE_CFLAGS="-fno-PIE"
+fi
+
+
+# Check if -no-pie works.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for -no-pie option" >&5
+$as_echo_n "checking for -no-pie option... " >&6; }
+if test "${gcc_cv_no_pie+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  saved_LDFLAGS="$LDFLAGS"
+   LDFLAGS="$LDFLAGS -no-pie"
+   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int main(void) {return 0;}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  gcc_cv_no_pie=yes
+else
+  gcc_cv_no_pie=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+   LDFLAGS="$saved_LDFLAGS"
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_no_pie" >&5
+$as_echo "$gcc_cv_no_pie" >&6; }
+if test "$gcc_cv_no_pie" = "yes"; then
+  NO_PIE_FLAG="-no-pie"
+fi
+
+
 # Configure the subdirectories
 # AC_CONFIG_SUBDIRS($subdirs)
 
diff --git a/gcc/configure.ac b/gcc/configure.ac
index 102dab9..952fbec 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -5759,6 +5759,64 @@ cat > gcc-driver-name.h <<EOF
 #define GCC_DRIVER_NAME "${target_noncanonical}-gcc-${gcc_BASEVER}${exeext}"
 EOF
 
+# 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])],
+enable_default_pie=$enableval,
+enable_default_pie=no)
+if test x$enable_default_pie = xyes; then
+  AC_MSG_CHECKING(if $target supports default PIE)
+  enable_default_pie=no
+  case $target in
+    i?86*-*-linux* | x86_64*-*-linux*)
+      saved_LDFLAGS="$LDFLAGS"
+      saved_CFLAGS="$CFLAGS"
+      CFLAGS="$CFLAGS -fPIE"
+      LDFLAGS="$LDFLAGS -fPIE -pie"
+      AC_TRY_LINK(,,[enable_default_pie=yes],)
+      LDFLAGS="$saved_LDFLAGS"
+      CFLAGS="$saved_CFLAGS"
+      ;;
+    *)
+      ;;
+    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 supports default PIE and it is enabled.])
+fi
+AC_SUBST([enable_default_pie])
+
+# Check if -fno-PIE works.
+AC_CACHE_CHECK([for -fno-PIE option],
+  [gcc_cv_c_no_fpie],
+  [saved_CFLAGS="$CFLAGS"
+   CFLAGS="$CFLAGS -fno-PIE"
+   AC_COMPILE_IFELSE([int main(void) {return 0;}],
+     [gcc_cv_c_no_fpie=yes],
+     [gcc_cv_c_no_fpie=no])
+   CFLAGS="$saved_CFLAGS"])
+if test "$gcc_cv_c_no_fpie" = "yes"; then
+  NO_PIE_CFLAGS="-fno-PIE"
+fi
+AC_SUBST([NO_PIE_CFLAGS])
+
+# Check if -no-pie works.
+AC_CACHE_CHECK([for -no-pie option],
+  [gcc_cv_no_pie],
+  [saved_LDFLAGS="$LDFLAGS"
+   LDFLAGS="$LDFLAGS -no-pie"
+   AC_LINK_IFELSE([int main(void) {return 0;}],
+     [gcc_cv_no_pie=yes],
+     [gcc_cv_no_pie=no])
+   LDFLAGS="$saved_LDFLAGS"])
+if test "$gcc_cv_no_pie" = "yes"; then
+  NO_PIE_FLAG="-no-pie"
+fi
+AC_SUBST([NO_PIE_FLAG])
+
 # Configure the subdirectories
 # AC_CONFIG_SUBDIRS($subdirs)
 
diff --git a/gcc/defaults.h b/gcc/defaults.h
index 5cef92c..970040e 100644
--- a/gcc/defaults.h
+++ b/gcc/defaults.h
@@ -1182,6 +1182,12 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #define DEFAULT_PCC_STRUCT_RETURN 1
 #endif
 
+/* Default PIE to -fPIE.  */
+#ifndef DEFAULT_FLAG_PIE
+# define DEFAULT_FLAG_PIE 2
+#endif
+
+
 #ifdef GCC_INSN_FLAGS_H
 /* Dependent default target macro definitions
 
diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
index c9e3bf1..89fc305 100644
--- a/gcc/doc/install.texi
+++ b/gcc/doc/install.texi
@@ -1583,6 +1583,10 @@ not be built.
 Specify that the run-time libraries for stack smashing protection
 should not be built.
 
+@item --enable-default-pie
+Turn on @option{-fPIE} and @option{-pie} by default if supported.
+Currently supported targets are i?86-*-linux* and x86-64-*-linux*.
+
 @item --disable-libquadmath
 Specify that the GCC quad-precision math library should not be built.
 On some systems, the library is required to be linkable when building
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 0182952..842b2b8 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -10972,6 +10972,10 @@ For predictable results, you must also specify the same set of options
 used for compilation (@option{-fpie}, @option{-fPIE},
 or model suboptions) when you specify this linker option.
 
+@item -no-pie
+@opindex no-pie
+Don't produce a position independent executable.
+
 @item -rdynamic
 @opindex rdynamic
 Pass the flag @option{-export-dynamic} to the ELF linker, on targets
diff --git a/gcc/gcc.c b/gcc/gcc.c
index 55d0ff2..5d2e09d4 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -734,12 +734,20 @@ proper position among the other output files.  */
 #endif
 #endif
 
+#ifdef ENABLE_DEFAULT_PIE
+#define NO_PIE_SPEC	"no-pie|static"
+#define PIE_SPEC	NO_PIE_SPEC "|shared:;"
+#else
+#define PIE_SPEC "pie"
+#endif
+
 #ifndef LINK_PIE_SPEC
 #ifdef HAVE_LD_PIE
-#define LINK_PIE_SPEC "%{pie:-pie} "
+#define LD_PIE_SPEC "-pie"
 #else
-#define LINK_PIE_SPEC "%{pie:} "
+#define LD_PIE_SPEC ""
 #endif
+#define LINK_PIE_SPEC "%{no-pie:} " "%{" PIE_SPEC ":" LD_PIE_SPEC "} "
 #endif
 
 #ifndef LINK_BUILDID_SPEC
diff --git a/gcc/opts.c b/gcc/opts.c
index 8a16116..ee769c8 100644
--- a/gcc/opts.c
+++ b/gcc/opts.c
@@ -738,8 +738,22 @@ finish_options (struct gcc_options *opts, struct gcc_options *opts_set,
       opts->x_flag_section_anchors = 0;
     }
 
+#ifndef ENABLE_DEFAULT_PIE
+#undef DEFAULT_FLAG_PIE
+#define DEFAULT_FLAG_PIE 0
+#endif
+
   if (!opts->x_flag_opts_finished)
     {
+      /* We initialize opts->x_flag_pie to -1 so that targets can set a
+	 default value.  */
+      if (opts->x_flag_pie == -1)
+	{
+	  if (opts->x_flag_pic == 0)
+	    opts->x_flag_pie = DEFAULT_FLAG_PIE;
+	  else
+	    opts->x_flag_pie = 0;
+	}
       if (opts->x_flag_pie)
 	opts->x_flag_pic = opts->x_flag_pie;
       if (opts->x_flag_pic && !opts->x_flag_pie)
diff --git a/libgcc/Makefile.in b/libgcc/Makefile.in
index f693883..8d10386 100644
--- a/libgcc/Makefile.in
+++ b/libgcc/Makefile.in
@@ -284,7 +284,7 @@ INTERNAL_CFLAGS = $(CFLAGS) $(LIBGCC2_CFLAGS) $(HOST_LIBGCC2_CFLAGS) \
 
 # Options to use when compiling crtbegin/end.
 CRTSTUFF_CFLAGS = -O2 $(GCC_CFLAGS) $(INCLUDES) $(MULTILIB_CFLAGS) -g0 \
-  -finhibit-size-directive -fno-inline -fno-exceptions \
+  $(NO_PIE_CFLAGS) -finhibit-size-directive -fno-inline -fno-exceptions \
   -fno-zero-initialized-in-bss -fno-toplevel-reorder -fno-tree-vectorize \
   -fbuilding-libgcc -fno-stack-protector $(FORCE_EXPLICIT_EH_REGISTRY) \
   $(INHIBIT_LIBC_CFLAGS)

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option
  2015-01-12 16:18           ` [PATCH]: " H.J. Lu
@ 2015-01-12 23:53             ` Joseph Myers
  2015-01-13  0:31               ` H.J. Lu
  2015-01-13 13:10               ` H.J. Lu
  0 siblings, 2 replies; 20+ messages in thread
From: Joseph Myers @ 2015-01-12 23:53 UTC (permalink / raw)
  To: H.J. Lu; +Cc: Richard Biener, Magnus Granberg, GCC Patches, danielmicay

On Mon, 12 Jan 2015, H.J. Lu wrote:

> +if test x$enable_default_pie = xyes; then
> +  AC_MSG_CHECKING(if $target supports default PIE)
> +  enable_default_pie=no
> +  case $target in
> +    i?86*-*-linux* | x86_64*-*-linux*)
> +      saved_LDFLAGS="$LDFLAGS"
> +      saved_CFLAGS="$CFLAGS"
> +      CFLAGS="$CFLAGS -fPIE"
> +      LDFLAGS="$LDFLAGS -fPIE -pie"
> +      AC_TRY_LINK(,,[enable_default_pie=yes],)
> +      LDFLAGS="$saved_LDFLAGS"
> +      CFLAGS="$saved_CFLAGS"
> +      ;;
> +    *)
> +      ;;
> +    esac

There should not be any such hardcoding of targets here without concrete 
evidence that the targets for which this sets enable_default_pie=no really 
cannot support PIE.  In particular, there is no reason at all for this to 
be architecture-specific; all GNU/Linux architectures should support PIE.

I believe AC_TRY_LINK here will test for the host, whereas what you want 
to know is what's supported for the target (but it's not possible to run 
link tests for the target at this point; the compiler for the target 
hasn't even been built).

So: just presume that if the user passes --enable-default-pie then they 
know what they are doing, and don't try to override their choice.

> diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
> index c9e3bf1..89fc305 100644
> --- a/gcc/doc/install.texi
> +++ b/gcc/doc/install.texi
> @@ -1583,6 +1583,10 @@ not be built.
>  Specify that the run-time libraries for stack smashing protection
>  should not be built.
>  
> +@item --enable-default-pie
> +Turn on @option{-fPIE} and @option{-pie} by default if supported.
> +Currently supported targets are i?86-*-linux* and x86-64-*-linux*.

The "if supported" and target list can then be removed here.

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option
  2015-01-12 23:53             ` Joseph Myers
@ 2015-01-13  0:31               ` H.J. Lu
  2015-01-13 13:10               ` H.J. Lu
  1 sibling, 0 replies; 20+ messages in thread
From: H.J. Lu @ 2015-01-13  0:31 UTC (permalink / raw)
  To: Joseph Myers; +Cc: Richard Biener, Magnus Granberg, GCC Patches, danielmicay

On Mon, Jan 12, 2015 at 3:50 PM, Joseph Myers <joseph@codesourcery.com> wrote:
> On Mon, 12 Jan 2015, H.J. Lu wrote:
>
>> +if test x$enable_default_pie = xyes; then
>> +  AC_MSG_CHECKING(if $target supports default PIE)
>> +  enable_default_pie=no
>> +  case $target in
>> +    i?86*-*-linux* | x86_64*-*-linux*)
>> +      saved_LDFLAGS="$LDFLAGS"
>> +      saved_CFLAGS="$CFLAGS"
>> +      CFLAGS="$CFLAGS -fPIE"
>> +      LDFLAGS="$LDFLAGS -fPIE -pie"
>> +      AC_TRY_LINK(,,[enable_default_pie=yes],)
>> +      LDFLAGS="$saved_LDFLAGS"
>> +      CFLAGS="$saved_CFLAGS"
>> +      ;;
>> +    *)
>> +      ;;
>> +    esac
>
> There should not be any such hardcoding of targets here without concrete
> evidence that the targets for which this sets enable_default_pie=no really
> cannot support PIE.  In particular, there is no reason at all for this to
> be architecture-specific; all GNU/Linux architectures should support PIE.

I will make the change.  Can someone test it on non-x86 Linux?

> I believe AC_TRY_LINK here will test for the host, whereas what you want
> to know is what's supported for the target (but it's not possible to run
> link tests for the target at this point; the compiler for the target
> hasn't even been built).
>
> So: just presume that if the user passes --enable-default-pie then they
> know what they are doing, and don't try to override their choice.
>
>> diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
>> index c9e3bf1..89fc305 100644
>> --- a/gcc/doc/install.texi
>> +++ b/gcc/doc/install.texi
>> @@ -1583,6 +1583,10 @@ not be built.
>>  Specify that the run-time libraries for stack smashing protection
>>  should not be built.
>>
>> +@item --enable-default-pie
>> +Turn on @option{-fPIE} and @option{-pie} by default if supported.
>> +Currently supported targets are i?86-*-linux* and x86-64-*-linux*.
>
> The "if supported" and target list can then be removed here.
>

I will remove them.

Thanks.

-- 
H.J.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option
  2015-01-12 23:53             ` Joseph Myers
  2015-01-13  0:31               ` H.J. Lu
@ 2015-01-13 13:10               ` H.J. Lu
  2015-01-14  0:03                 ` H.J. Lu
  1 sibling, 1 reply; 20+ messages in thread
From: H.J. Lu @ 2015-01-13 13:10 UTC (permalink / raw)
  To: Joseph Myers; +Cc: Richard Biener, Magnus Granberg, GCC Patches, danielmicay

On Mon, Jan 12, 2015 at 11:50:41PM +0000, Joseph Myers wrote:
> On Mon, 12 Jan 2015, H.J. Lu wrote:
> 
> > +if test x$enable_default_pie = xyes; then
> > +  AC_MSG_CHECKING(if $target supports default PIE)
> > +  enable_default_pie=no
> > +  case $target in
> > +    i?86*-*-linux* | x86_64*-*-linux*)
> > +      saved_LDFLAGS="$LDFLAGS"
> > +      saved_CFLAGS="$CFLAGS"
> > +      CFLAGS="$CFLAGS -fPIE"
> > +      LDFLAGS="$LDFLAGS -fPIE -pie"
> > +      AC_TRY_LINK(,,[enable_default_pie=yes],)
> > +      LDFLAGS="$saved_LDFLAGS"
> > +      CFLAGS="$saved_CFLAGS"
> > +      ;;
> > +    *)
> > +      ;;
> > +    esac
> 
> There should not be any such hardcoding of targets here without concrete 
> evidence that the targets for which this sets enable_default_pie=no really 
> cannot support PIE.  In particular, there is no reason at all for this to 
> be architecture-specific; all GNU/Linux architectures should support PIE.
> 
> I believe AC_TRY_LINK here will test for the host, whereas what you want 
> to know is what's supported for the target (but it's not possible to run 
> link tests for the target at this point; the compiler for the target 
> hasn't even been built).
> 
> So: just presume that if the user passes --enable-default-pie then they 
> know what they are doing, and don't try to override their choice.
> 
> > diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
> > index c9e3bf1..89fc305 100644
> > --- a/gcc/doc/install.texi
> > +++ b/gcc/doc/install.texi
> > @@ -1583,6 +1583,10 @@ not be built.
> >  Specify that the run-time libraries for stack smashing protection
> >  should not be built.
> >  
> > +@item --enable-default-pie
> > +Turn on @option{-fPIE} and @option{-pie} by default if supported.
> > +Currently supported targets are i?86-*-linux* and x86-64-*-linux*.
> 
> The "if supported" and target list can then be removed here.
> 

Here is the updated patch.  To support --enable-default-pie, each target
must update STARTFILE_SPEC to support PIE_SPEC and NO_PIE_SPEC.  I can
provide STARTFILE_SPEC patch if needed.

Thanks.


H.J.
---
gcc/

2015-01-12  Magnus Granberg  <zorry@gentoo.org>
	    H.J. Lu  <hongjiu.lu@intel.com>

	* Makefile.in (COMPILER): Add @NO_PIE_CFLAGS@.
	(LINKER): Add @NO_PIE_FLAG@.
	(libgcc.mvars): Set NO_PIE_CFLAGS to -fno-PIE for
	--enable-default-pie.
	* common.opt (fPIE): Initialize to -1.
	(fpie): Likewise.
	(static): Add "RejectNegative Negative(shared)".
	(no-pie): New option.
	(pie): Replace "Negative(shared)" with "Negative(no-pie)".
	* configure.ac: Add --enable-default-pie.
	(NO_PIE_CFLAGS): New.  Check if -fno-PIE works.  AC_SUBST.
	(NO_PIE_FLAG): New.  Check if -no-pie works.  AC_SUBST.
	* defaults.h (DEFAULT_FLAG_PIE): New.  Default PIE to -fPIE.
	* gcc.c (NO_PIE_SPEC): New.
	(PIE_SPEC): Likewise.
	(LD_PIE_SPEC): Likewise.
	(LINK_PIE_SPEC): Handle -no-pie.  Use PIE_SPEC and LD_PIE_SPEC.
	* opts.c (DEFAULT_FLAG_PIE): New.  Set to 0 if ENABLE_DEFAULT_PIE
	is undefined.
	(finish_options): Update opts->x_flag_pie if it is -1.
	* config/gnu-user.h (FVTABLE_VERIFY_SPEC): New.
	(GNU_USER_TARGET_STARTFILE_SPEC): Use FVTABLE_VERIFY_SPEC.  Use
	NO_PIE_SPEC and NO_PIE_SPEC if ENABLE_DEFAULT_PIE is defined.
	(GNU_USER_TARGET_STARTFILE_SPEC): Use FVTABLE_VERIFY_SPEC.
	* doc/install.texi: Document --enable-default-pie.
	* doc/invoke.texi: Document -no-pie.
	* config.in: Regenerated.
	* configure: Likewise.

gcc/ada/

2015-01-12  H.J. Lu  <hongjiu.lu@intel.com>

	* gcc-interface/Makefile.in (TOOLS_LIBS): Add @NO_PIE_FLAG@.

libgcc/

2015-01-12  H.J. Lu  <hongjiu.lu@intel.com>

	* Makefile.in (CRTSTUFF_CFLAGS): Add $(NO_PIE_CFLAGS).

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 5f9261f..180751f 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -252,6 +252,12 @@ LINKER = $(CC)
 LINKER_FLAGS = $(CFLAGS)
 endif
 
+# We don't want to compile the compiler with -fPIE, it make PCH fail.
+COMPILER += @NO_PIE_CFLAGS@
+
+# Link with -no-pie since we compile the compiler with -fno-PIE.
+LINKER += @NO_PIE_FLAG@
+
 # Like LINKER, but use a mutex for serializing front end links.
 ifeq (@DO_LINK_MUTEX@,true)
 LLINKER = $(SHELL) $(srcdir)/lock-and-run.sh linkfe.lck $(LINKER)
@@ -1854,6 +1860,12 @@ libgcc.mvars: config.status Makefile specs xgcc$(exeext)
 	echo GCC_CFLAGS = '$(GCC_CFLAGS)' >> tmp-libgcc.mvars
 	echo INHIBIT_LIBC_CFLAGS = '$(INHIBIT_LIBC_CFLAGS)' >> tmp-libgcc.mvars
 	echo TARGET_SYSTEM_ROOT = '$(TARGET_SYSTEM_ROOT)' >> tmp-libgcc.mvars
+	if test @enable_default_pie@ = yes; then \
+	  NO_PIE_CFLAGS="-fno-PIE"; \
+	else \
+	  NO_PIE_CFLAGS=; \
+	fi; \
+	echo NO_PIE_CFLAGS = "$$NO_PIE_CFLAGS" >> tmp-libgcc.mvars
 
 	mv tmp-libgcc.mvars libgcc.mvars
 
diff --git a/gcc/ada/gcc-interface/Makefile.in b/gcc/ada/gcc-interface/Makefile.in
index 870cfab..a446d48 100644
--- a/gcc/ada/gcc-interface/Makefile.in
+++ b/gcc/ada/gcc-interface/Makefile.in
@@ -267,6 +267,9 @@ TOOLS_LIBS = ../link.o ../targext.o ../../ggc-none.o ../../libcommon-target.a \
   ../../libcommon.a ../../../libcpp/libcpp.a $(LIBGNAT) $(LIBINTL) $(LIBICONV) \
   ../$(LIBBACKTRACE) ../$(LIBIBERTY) $(SYSLIBS) $(TGT_LIB)
 
+# Add -no-pie to TOOLS_LIBS since some of them are compiled with -fno-PIE.
+TOOLS_LIBS += @NO_PIE_FLAG@
+
 # Specify the directories to be searched for header files.
 # Both . and srcdir are used, in that order,
 # so that tm.h and config.h will be found in the compilation
diff --git a/gcc/common.opt b/gcc/common.opt
index e104269..b3fdb27 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -1755,7 +1755,7 @@ Common Report Var(flag_pic,2) Negative(fPIE)
 Generate position-independent code if possible (large mode)
 
 fPIE
-Common Report Var(flag_pie,2) Negative(fpic)
+Common Report Var(flag_pie,2) Negative(fpic) Init(-1)
 Generate position-independent code for executables if possible (large mode)
 
 fpic
@@ -1763,7 +1763,7 @@ Common Report Var(flag_pic,1) Negative(fpie)
 Generate position-independent code if possible (small mode)
 
 fpie
-Common Report Var(flag_pie,1) Negative(fPIC)
+Common Report Var(flag_pie,1) Negative(fPIC) Init(-1)
 Generate position-independent code for executables if possible (small mode)
 
 fplugin=
@@ -2792,7 +2792,7 @@ specs=
 Driver Joined
 
 static
-Driver
+Driver RejectNegative Negative(shared)
 
 static-libgcc
 Driver
@@ -2823,8 +2823,12 @@ Driver
 symbolic
 Driver
 
+no-pie
+Driver RejectNegative Negative(static)
+Don't create a position independent executable
+
 pie
-Driver RejectNegative Negative(shared)
+Driver RejectNegative Negative(no-pie)
 Create a position independent executable
 
 z
diff --git a/gcc/config.in b/gcc/config.in
index f34adb5..3fc018a 100644
--- a/gcc/config.in
+++ b/gcc/config.in
@@ -89,6 +89,12 @@
 #endif
 
 
+/* Define if your target supports default PIE and it is enabled. */
+#ifndef USED_FOR_TARGET
+#undef ENABLE_DEFAULT_PIE
+#endif
+
+
 /* Define if you want more run-time sanity checks for dataflow. */
 #ifndef USED_FOR_TARGET
 #undef ENABLE_DF_CHECKING
diff --git a/gcc/config/gnu-user.h b/gcc/config/gnu-user.h
index 2faa2e5..5cbe5da 100644
--- a/gcc/config/gnu-user.h
+++ b/gcc/config/gnu-user.h
@@ -41,19 +41,29 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
    object constructed before entering `main'.  */
 
 #if defined HAVE_LD_PIE
-#define GNU_USER_TARGET_STARTFILE_SPEC \
-  "%{!shared: %{pg|p|profile:gcrt1.o%s;pie:Scrt1.o%s;:crt1.o%s}} \
-   crti.o%s %{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbegin.o%s} \
-   %{fvtable-verify=none:%s; \
+#define FVTABLE_VERIFY_SPEC \
+  "%{fvtable-verify=none:%s; \
      fvtable-verify=preinit:vtv_start_preinit.o%s; \
      fvtable-verify=std:vtv_start.o%s}"
+#if defined ENABLE_DEFAULT_PIE
+#define GNU_USER_TARGET_STARTFILE_SPEC \
+  "%{!shared: %{pg|p|profile:gcrt1.o%s;: \
+    %{" PIE_SPEC ":Scrt1.o%s} %{" NO_PIE_SPEC ":crt1.o%s}}} \
+   crti.o%s %{static:crtbeginT.o%s;: %{shared:crtbeginS.o%s} \
+	      %{" PIE_SPEC ":crtbeginS.o%s} \
+	      %{" NO_PIE_SPEC ":crtbegin.o%s}}" \
+   FVTABLE_VERIFY_SPEC
+#else
+#define GNU_USER_TARGET_STARTFILE_SPEC \
+  "%{!shared: %{pg|p|profile:gcrt1.o%s;pie:Scrt1.o%s;:crt1.o%s}} \
+   crti.o%s %{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbegin.o%s}" \
+   FVTABLE_VERIFY_SPEC
+#endif
 #else
 #define GNU_USER_TARGET_STARTFILE_SPEC \
   "%{!shared: %{pg|p|profile:gcrt1.o%s;:crt1.o%s}} \
-   crti.o%s %{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbegin.o%s} \
-   %{fvtable-verify=none:%s; \
-     fvtable-verify=preinit:vtv_start_preinit.o%s; \
-     fvtable-verify=std:vtv_start.o%s}"
+   crti.o%s %{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbegin.o%s}" \
+   FVTABLE_VERIFY_SPEC
 #endif
 #undef  STARTFILE_SPEC
 #define STARTFILE_SPEC GNU_USER_TARGET_STARTFILE_SPEC
diff --git a/gcc/configure b/gcc/configure
index 1bf4358..980c680 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -600,6 +600,9 @@ ac_includes_default="\
 
 ac_subst_vars='LTLIBOBJS
 LIBOBJS
+NO_PIE_FLAG
+NO_PIE_CFLAGS
+enable_default_pie
 PICFLAG
 enable_host_shared
 enable_plugin
@@ -937,6 +940,7 @@ enable_host_shared
 enable_libquadmath_support
 with_linker_hash_style
 with_diagnostics_color
+enable_default_pie
 '
       ac_precious_vars='build_alias
 host_alias
@@ -1665,6 +1669,7 @@ Optional Features:
   --enable-host-shared    build host code as shared libraries
   --disable-libquadmath-support
                           disable libquadmath support for Fortran
+  --enable-default-pie    enable Position Independent Executable as default
 
 Optional Packages:
   --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
@@ -18147,7 +18152,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 18150 "configure"
+#line 18155 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -18253,7 +18258,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 18256 "configure"
+#line 18261 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -28432,6 +28437,76 @@ cat > gcc-driver-name.h <<EOF
 #define GCC_DRIVER_NAME "${target_noncanonical}-gcc-${gcc_BASEVER}${exeext}"
 EOF
 
+# Check whether --enable-default-pie was given and target have the support.
+# Check whether --enable-default-pie was given.
+if test "${enable_default_pie+set}" = set; then :
+  enableval=$enable_default_pie; enable_default_pie=$enableval
+else
+  enable_default_pie=no
+fi
+
+if test x$enable_default_pie == xyes ; then
+
+$as_echo "#define ENABLE_DEFAULT_PIE 1" >>confdefs.h
+
+fi
+
+
+# Check if -fno-PIE works.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for -fno-PIE option" >&5
+$as_echo_n "checking for -fno-PIE option... " >&6; }
+if test "${gcc_cv_c_no_fpie+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  saved_CFLAGS="$CFLAGS"
+   CFLAGS="$CFLAGS -fno-PIE"
+   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int main(void) {return 0;}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  gcc_cv_c_no_fpie=yes
+else
+  gcc_cv_c_no_fpie=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+   CFLAGS="$saved_CFLAGS"
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_c_no_fpie" >&5
+$as_echo "$gcc_cv_c_no_fpie" >&6; }
+if test "$gcc_cv_c_no_fpie" = "yes"; then
+  NO_PIE_CFLAGS="-fno-PIE"
+fi
+
+
+# Check if -no-pie works.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for -no-pie option" >&5
+$as_echo_n "checking for -no-pie option... " >&6; }
+if test "${gcc_cv_no_pie+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  saved_LDFLAGS="$LDFLAGS"
+   LDFLAGS="$LDFLAGS -no-pie"
+   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int main(void) {return 0;}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  gcc_cv_no_pie=yes
+else
+  gcc_cv_no_pie=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+   LDFLAGS="$saved_LDFLAGS"
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_no_pie" >&5
+$as_echo "$gcc_cv_no_pie" >&6; }
+if test "$gcc_cv_no_pie" = "yes"; then
+  NO_PIE_FLAG="-no-pie"
+fi
+
+
 # Configure the subdirectories
 # AC_CONFIG_SUBDIRS($subdirs)
 
diff --git a/gcc/configure.ac b/gcc/configure.ac
index 102dab9..e6da960 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -5759,6 +5759,46 @@ cat > gcc-driver-name.h <<EOF
 #define GCC_DRIVER_NAME "${target_noncanonical}-gcc-${gcc_BASEVER}${exeext}"
 EOF
 
+# 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])],
+enable_default_pie=$enableval,
+enable_default_pie=no)
+if test x$enable_default_pie == xyes ; then
+  AC_DEFINE(ENABLE_DEFAULT_PIE, 1,
+      [Define if your target supports default PIE and it is enabled.])
+fi
+AC_SUBST([enable_default_pie])
+
+# Check if -fno-PIE works.
+AC_CACHE_CHECK([for -fno-PIE option],
+  [gcc_cv_c_no_fpie],
+  [saved_CFLAGS="$CFLAGS"
+   CFLAGS="$CFLAGS -fno-PIE"
+   AC_COMPILE_IFELSE([int main(void) {return 0;}],
+     [gcc_cv_c_no_fpie=yes],
+     [gcc_cv_c_no_fpie=no])
+   CFLAGS="$saved_CFLAGS"])
+if test "$gcc_cv_c_no_fpie" = "yes"; then
+  NO_PIE_CFLAGS="-fno-PIE"
+fi
+AC_SUBST([NO_PIE_CFLAGS])
+
+# Check if -no-pie works.
+AC_CACHE_CHECK([for -no-pie option],
+  [gcc_cv_no_pie],
+  [saved_LDFLAGS="$LDFLAGS"
+   LDFLAGS="$LDFLAGS -no-pie"
+   AC_LINK_IFELSE([int main(void) {return 0;}],
+     [gcc_cv_no_pie=yes],
+     [gcc_cv_no_pie=no])
+   LDFLAGS="$saved_LDFLAGS"])
+if test "$gcc_cv_no_pie" = "yes"; then
+  NO_PIE_FLAG="-no-pie"
+fi
+AC_SUBST([NO_PIE_FLAG])
+
 # Configure the subdirectories
 # AC_CONFIG_SUBDIRS($subdirs)
 
diff --git a/gcc/defaults.h b/gcc/defaults.h
index 5cef92c..970040e 100644
--- a/gcc/defaults.h
+++ b/gcc/defaults.h
@@ -1182,6 +1182,12 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #define DEFAULT_PCC_STRUCT_RETURN 1
 #endif
 
+/* Default PIE to -fPIE.  */
+#ifndef DEFAULT_FLAG_PIE
+# define DEFAULT_FLAG_PIE 2
+#endif
+
+
 #ifdef GCC_INSN_FLAGS_H
 /* Dependent default target macro definitions
 
diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
index c9e3bf1..aaed6c7 100644
--- a/gcc/doc/install.texi
+++ b/gcc/doc/install.texi
@@ -1583,6 +1583,9 @@ not be built.
 Specify that the run-time libraries for stack smashing protection
 should not be built.
 
+@item --enable-default-pie
+Turn on @option{-fPIE} and @option{-pie} by default.
+
 @item --disable-libquadmath
 Specify that the GCC quad-precision math library should not be built.
 On some systems, the library is required to be linkable when building
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index d84e3b7..7b8ed89 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -10973,6 +10973,10 @@ For predictable results, you must also specify the same set of options
 used for compilation (@option{-fpie}, @option{-fPIE},
 or model suboptions) when you specify this linker option.
 
+@item -no-pie
+@opindex no-pie
+Don't produce a position independent executable.
+
 @item -rdynamic
 @opindex rdynamic
 Pass the flag @option{-export-dynamic} to the ELF linker, on targets
diff --git a/gcc/gcc.c b/gcc/gcc.c
index 55d0ff2..5d2e09d4 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -734,12 +734,20 @@ proper position among the other output files.  */
 #endif
 #endif
 
+#ifdef ENABLE_DEFAULT_PIE
+#define NO_PIE_SPEC	"no-pie|static"
+#define PIE_SPEC	NO_PIE_SPEC "|shared:;"
+#else
+#define PIE_SPEC "pie"
+#endif
+
 #ifndef LINK_PIE_SPEC
 #ifdef HAVE_LD_PIE
-#define LINK_PIE_SPEC "%{pie:-pie} "
+#define LD_PIE_SPEC "-pie"
 #else
-#define LINK_PIE_SPEC "%{pie:} "
+#define LD_PIE_SPEC ""
 #endif
+#define LINK_PIE_SPEC "%{no-pie:} " "%{" PIE_SPEC ":" LD_PIE_SPEC "} "
 #endif
 
 #ifndef LINK_BUILDID_SPEC
diff --git a/gcc/opts.c b/gcc/opts.c
index 8a16116..ee769c8 100644
--- a/gcc/opts.c
+++ b/gcc/opts.c
@@ -738,8 +738,22 @@ finish_options (struct gcc_options *opts, struct gcc_options *opts_set,
       opts->x_flag_section_anchors = 0;
     }
 
+#ifndef ENABLE_DEFAULT_PIE
+#undef DEFAULT_FLAG_PIE
+#define DEFAULT_FLAG_PIE 0
+#endif
+
   if (!opts->x_flag_opts_finished)
     {
+      /* We initialize opts->x_flag_pie to -1 so that targets can set a
+	 default value.  */
+      if (opts->x_flag_pie == -1)
+	{
+	  if (opts->x_flag_pic == 0)
+	    opts->x_flag_pie = DEFAULT_FLAG_PIE;
+	  else
+	    opts->x_flag_pie = 0;
+	}
       if (opts->x_flag_pie)
 	opts->x_flag_pic = opts->x_flag_pie;
       if (opts->x_flag_pic && !opts->x_flag_pie)
diff --git a/libgcc/Makefile.in b/libgcc/Makefile.in
index f693883..8d10386 100644
--- a/libgcc/Makefile.in
+++ b/libgcc/Makefile.in
@@ -284,7 +284,7 @@ INTERNAL_CFLAGS = $(CFLAGS) $(LIBGCC2_CFLAGS) $(HOST_LIBGCC2_CFLAGS) \
 
 # Options to use when compiling crtbegin/end.
 CRTSTUFF_CFLAGS = -O2 $(GCC_CFLAGS) $(INCLUDES) $(MULTILIB_CFLAGS) -g0 \
-  -finhibit-size-directive -fno-inline -fno-exceptions \
+  $(NO_PIE_CFLAGS) -finhibit-size-directive -fno-inline -fno-exceptions \
   -fno-zero-initialized-in-bss -fno-toplevel-reorder -fno-tree-vectorize \
   -fbuilding-libgcc -fno-stack-protector $(FORCE_EXPLICIT_EH_REGISTRY) \
   $(INHIBIT_LIBC_CFLAGS)

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option
  2015-01-13 13:10               ` H.J. Lu
@ 2015-01-14  0:03                 ` H.J. Lu
  0 siblings, 0 replies; 20+ messages in thread
From: H.J. Lu @ 2015-01-14  0:03 UTC (permalink / raw)
  To: Joseph Myers; +Cc: Richard Biener, Magnus Granberg, GCC Patches, danielmicay

[-- Attachment #1: Type: text/plain, Size: 4139 bytes --]

On Tue, Jan 13, 2015 at 5:03 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Mon, Jan 12, 2015 at 11:50:41PM +0000, Joseph Myers wrote:
>> On Mon, 12 Jan 2015, H.J. Lu wrote:
>>
>> > +if test x$enable_default_pie = xyes; then
>> > +  AC_MSG_CHECKING(if $target supports default PIE)
>> > +  enable_default_pie=no
>> > +  case $target in
>> > +    i?86*-*-linux* | x86_64*-*-linux*)
>> > +      saved_LDFLAGS="$LDFLAGS"
>> > +      saved_CFLAGS="$CFLAGS"
>> > +      CFLAGS="$CFLAGS -fPIE"
>> > +      LDFLAGS="$LDFLAGS -fPIE -pie"
>> > +      AC_TRY_LINK(,,[enable_default_pie=yes],)
>> > +      LDFLAGS="$saved_LDFLAGS"
>> > +      CFLAGS="$saved_CFLAGS"
>> > +      ;;
>> > +    *)
>> > +      ;;
>> > +    esac
>>
>> There should not be any such hardcoding of targets here without concrete
>> evidence that the targets for which this sets enable_default_pie=no really
>> cannot support PIE.  In particular, there is no reason at all for this to
>> be architecture-specific; all GNU/Linux architectures should support PIE.
>>
>> I believe AC_TRY_LINK here will test for the host, whereas what you want
>> to know is what's supported for the target (but it's not possible to run
>> link tests for the target at this point; the compiler for the target
>> hasn't even been built).
>>
>> So: just presume that if the user passes --enable-default-pie then they
>> know what they are doing, and don't try to override their choice.
>>
>> > diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
>> > index c9e3bf1..89fc305 100644
>> > --- a/gcc/doc/install.texi
>> > +++ b/gcc/doc/install.texi
>> > @@ -1583,6 +1583,10 @@ not be built.
>> >  Specify that the run-time libraries for stack smashing protection
>> >  should not be built.
>> >
>> > +@item --enable-default-pie
>> > +Turn on @option{-fPIE} and @option{-pie} by default if supported.
>> > +Currently supported targets are i?86-*-linux* and x86-64-*-linux*.
>>
>> The "if supported" and target list can then be removed here.
>>
>
> Here is the updated patch.  To support --enable-default-pie, each target
> must update STARTFILE_SPEC to support PIE_SPEC and NO_PIE_SPEC.  I can
> provide STARTFILE_SPEC patch if needed.
>
> Thanks.
>
>
> H.J.
> ---
> gcc/
>
> 2015-01-12  Magnus Granberg  <zorry@gentoo.org>
>             H.J. Lu  <hongjiu.lu@intel.com>
>
>         * Makefile.in (COMPILER): Add @NO_PIE_CFLAGS@.
>         (LINKER): Add @NO_PIE_FLAG@.
>         (libgcc.mvars): Set NO_PIE_CFLAGS to -fno-PIE for
>         --enable-default-pie.
>         * common.opt (fPIE): Initialize to -1.
>         (fpie): Likewise.
>         (static): Add "RejectNegative Negative(shared)".
>         (no-pie): New option.
>         (pie): Replace "Negative(shared)" with "Negative(no-pie)".
>         * configure.ac: Add --enable-default-pie.
>         (NO_PIE_CFLAGS): New.  Check if -fno-PIE works.  AC_SUBST.
>         (NO_PIE_FLAG): New.  Check if -no-pie works.  AC_SUBST.
>         * defaults.h (DEFAULT_FLAG_PIE): New.  Default PIE to -fPIE.
>         * gcc.c (NO_PIE_SPEC): New.
>         (PIE_SPEC): Likewise.
>         (LD_PIE_SPEC): Likewise.
>         (LINK_PIE_SPEC): Handle -no-pie.  Use PIE_SPEC and LD_PIE_SPEC.
>         * opts.c (DEFAULT_FLAG_PIE): New.  Set to 0 if ENABLE_DEFAULT_PIE
>         is undefined.
>         (finish_options): Update opts->x_flag_pie if it is -1.
>         * config/gnu-user.h (FVTABLE_VERIFY_SPEC): New.
>         (GNU_USER_TARGET_STARTFILE_SPEC): Use FVTABLE_VERIFY_SPEC.  Use
>         NO_PIE_SPEC and NO_PIE_SPEC if ENABLE_DEFAULT_PIE is defined.
>         (GNU_USER_TARGET_STARTFILE_SPEC): Use FVTABLE_VERIFY_SPEC.
>         * doc/install.texi: Document --enable-default-pie.
>         * doc/invoke.texi: Document -no-pie.
>         * config.in: Regenerated.
>         * configure: Likewise.
>
> gcc/ada/
>
> 2015-01-12  H.J. Lu  <hongjiu.lu@intel.com>
>
>         * gcc-interface/Makefile.in (TOOLS_LIBS): Add @NO_PIE_FLAG@.
>
> libgcc/
>
> 2015-01-12  H.J. Lu  <hongjiu.lu@intel.com>
>
>         * Makefile.in (CRTSTUFF_CFLAGS): Add $(NO_PIE_CFLAGS).
>

This is the updated patch.  I fixed the -r regression.   LTO tests
pass now.

-- 
H.J.

[-- Attachment #2: pie.patch --]
[-- Type: text/x-patch, Size: 14971 bytes --]

gcc/

2015-01-12  Magnus Granberg  <zorry@gentoo.org>
	    H.J. Lu  <hongjiu.lu@intel.com>

	* Makefile.in (COMPILER): Add @NO_PIE_CFLAGS@.
	(LINKER): Add @NO_PIE_FLAG@.
	(libgcc.mvars): Set NO_PIE_CFLAGS to -fno-PIE for
	--enable-default-pie.
	* common.opt (fPIE): Initialize to -1.
	(fpie): Likewise.
	(no-pie): New option.
	(pie): Replace "Negative(shared)" with "Negative(no-pie)".
	* configure.ac: Add --enable-default-pie.
	(NO_PIE_CFLAGS): New.  Check if -fno-PIE works.  AC_SUBST.
	(NO_PIE_FLAG): New.  Check if -no-pie works.  AC_SUBST.
	* defaults.h (DEFAULT_FLAG_PIE): New.  Default PIE to -fPIE.
	* gcc.c (NO_PIE_SPEC): New.
	(PIE_SPEC): Likewise.
	(LD_PIE_SPEC): Likewise.
	(LINK_PIE_SPEC): Handle -no-pie.  Use PIE_SPEC and LD_PIE_SPEC.
	* opts.c (DEFAULT_FLAG_PIE): New.  Set to 0 if ENABLE_DEFAULT_PIE
	is undefined.
	(finish_options): Update opts->x_flag_pie if it is -1.
	* config/gnu-user.h (FVTABLE_VERIFY_SPEC): New.
	(GNU_USER_TARGET_STARTFILE_SPEC): Use FVTABLE_VERIFY_SPEC.  Use
	PIE_SPEC and NO_PIE_SPEC if ENABLE_DEFAULT_PIE is defined.
	(GNU_USER_TARGET_STARTFILE_SPEC): Use FVTABLE_VERIFY_SPEC.
	* doc/install.texi: Document --enable-default-pie.
	* doc/invoke.texi: Document -no-pie.
	* config.in: Regenerated.
	* configure: Likewise.

gcc/ada/

2015-01-12  H.J. Lu  <hongjiu.lu@intel.com>

	* gcc-interface/Makefile.in (TOOLS_LIBS): Add @NO_PIE_FLAG@.

libgcc/

2015-01-12  H.J. Lu  <hongjiu.lu@intel.com>

	* Makefile.in (CRTSTUFF_CFLAGS): Add $(NO_PIE_CFLAGS).

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 5f9261f..180751f 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -252,6 +252,12 @@ LINKER = $(CC)
 LINKER_FLAGS = $(CFLAGS)
 endif
 
+# We don't want to compile the compiler with -fPIE, it make PCH fail.
+COMPILER += @NO_PIE_CFLAGS@
+
+# Link with -no-pie since we compile the compiler with -fno-PIE.
+LINKER += @NO_PIE_FLAG@
+
 # Like LINKER, but use a mutex for serializing front end links.
 ifeq (@DO_LINK_MUTEX@,true)
 LLINKER = $(SHELL) $(srcdir)/lock-and-run.sh linkfe.lck $(LINKER)
@@ -1854,6 +1860,12 @@ libgcc.mvars: config.status Makefile specs xgcc$(exeext)
 	echo GCC_CFLAGS = '$(GCC_CFLAGS)' >> tmp-libgcc.mvars
 	echo INHIBIT_LIBC_CFLAGS = '$(INHIBIT_LIBC_CFLAGS)' >> tmp-libgcc.mvars
 	echo TARGET_SYSTEM_ROOT = '$(TARGET_SYSTEM_ROOT)' >> tmp-libgcc.mvars
+	if test @enable_default_pie@ = yes; then \
+	  NO_PIE_CFLAGS="-fno-PIE"; \
+	else \
+	  NO_PIE_CFLAGS=; \
+	fi; \
+	echo NO_PIE_CFLAGS = "$$NO_PIE_CFLAGS" >> tmp-libgcc.mvars
 
 	mv tmp-libgcc.mvars libgcc.mvars
 
diff --git a/gcc/ada/gcc-interface/Makefile.in b/gcc/ada/gcc-interface/Makefile.in
index 870cfab..a446d48 100644
--- a/gcc/ada/gcc-interface/Makefile.in
+++ b/gcc/ada/gcc-interface/Makefile.in
@@ -267,6 +267,9 @@ TOOLS_LIBS = ../link.o ../targext.o ../../ggc-none.o ../../libcommon-target.a \
   ../../libcommon.a ../../../libcpp/libcpp.a $(LIBGNAT) $(LIBINTL) $(LIBICONV) \
   ../$(LIBBACKTRACE) ../$(LIBIBERTY) $(SYSLIBS) $(TGT_LIB)
 
+# Add -no-pie to TOOLS_LIBS since some of them are compiled with -fno-PIE.
+TOOLS_LIBS += @NO_PIE_FLAG@
+
 # Specify the directories to be searched for header files.
 # Both . and srcdir are used, in that order,
 # so that tm.h and config.h will be found in the compilation
diff --git a/gcc/common.opt b/gcc/common.opt
index e104269..47f9fa2 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -1755,7 +1755,7 @@ Common Report Var(flag_pic,2) Negative(fPIE)
 Generate position-independent code if possible (large mode)
 
 fPIE
-Common Report Var(flag_pie,2) Negative(fpic)
+Common Report Var(flag_pie,2) Negative(fpic) Init(-1)
 Generate position-independent code for executables if possible (large mode)
 
 fpic
@@ -1763,7 +1763,7 @@ Common Report Var(flag_pic,1) Negative(fpie)
 Generate position-independent code if possible (small mode)
 
 fpie
-Common Report Var(flag_pie,1) Negative(fPIC)
+Common Report Var(flag_pie,1) Negative(fPIC) Init(-1)
 Generate position-independent code for executables if possible (small mode)
 
 fplugin=
@@ -2823,8 +2823,12 @@ Driver
 symbolic
 Driver
 
-pie
+no-pie
 Driver RejectNegative Negative(shared)
+Don't create a position independent executable
+
+pie
+Driver RejectNegative Negative(no-pie)
 Create a position independent executable
 
 z
diff --git a/gcc/config.in b/gcc/config.in
index f34adb5..3fc018a 100644
--- a/gcc/config.in
+++ b/gcc/config.in
@@ -89,6 +89,12 @@
 #endif
 
 
+/* Define if your target supports default PIE and it is enabled. */
+#ifndef USED_FOR_TARGET
+#undef ENABLE_DEFAULT_PIE
+#endif
+
+
 /* Define if you want more run-time sanity checks for dataflow. */
 #ifndef USED_FOR_TARGET
 #undef ENABLE_DF_CHECKING
diff --git a/gcc/config/gnu-user.h b/gcc/config/gnu-user.h
index 2faa2e5..5cbe5da 100644
--- a/gcc/config/gnu-user.h
+++ b/gcc/config/gnu-user.h
@@ -41,19 +41,29 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
    object constructed before entering `main'.  */
 
 #if defined HAVE_LD_PIE
-#define GNU_USER_TARGET_STARTFILE_SPEC \
-  "%{!shared: %{pg|p|profile:gcrt1.o%s;pie:Scrt1.o%s;:crt1.o%s}} \
-   crti.o%s %{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbegin.o%s} \
-   %{fvtable-verify=none:%s; \
+#define FVTABLE_VERIFY_SPEC \
+  "%{fvtable-verify=none:%s; \
      fvtable-verify=preinit:vtv_start_preinit.o%s; \
      fvtable-verify=std:vtv_start.o%s}"
+#if defined ENABLE_DEFAULT_PIE
+#define GNU_USER_TARGET_STARTFILE_SPEC \
+  "%{!shared: %{pg|p|profile:gcrt1.o%s;: \
+    %{" PIE_SPEC ":Scrt1.o%s} %{" NO_PIE_SPEC ":crt1.o%s}}} \
+   crti.o%s %{static:crtbeginT.o%s;: %{shared:crtbeginS.o%s} \
+	      %{" PIE_SPEC ":crtbeginS.o%s} \
+	      %{" NO_PIE_SPEC ":crtbegin.o%s}}" \
+   FVTABLE_VERIFY_SPEC
+#else
+#define GNU_USER_TARGET_STARTFILE_SPEC \
+  "%{!shared: %{pg|p|profile:gcrt1.o%s;pie:Scrt1.o%s;:crt1.o%s}} \
+   crti.o%s %{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbegin.o%s}" \
+   FVTABLE_VERIFY_SPEC
+#endif
 #else
 #define GNU_USER_TARGET_STARTFILE_SPEC \
   "%{!shared: %{pg|p|profile:gcrt1.o%s;:crt1.o%s}} \
-   crti.o%s %{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbegin.o%s} \
-   %{fvtable-verify=none:%s; \
-     fvtable-verify=preinit:vtv_start_preinit.o%s; \
-     fvtable-verify=std:vtv_start.o%s}"
+   crti.o%s %{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbegin.o%s}" \
+   FVTABLE_VERIFY_SPEC
 #endif
 #undef  STARTFILE_SPEC
 #define STARTFILE_SPEC GNU_USER_TARGET_STARTFILE_SPEC
diff --git a/gcc/configure b/gcc/configure
index 1bf4358..980c680 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -600,6 +600,9 @@ ac_includes_default="\
 
 ac_subst_vars='LTLIBOBJS
 LIBOBJS
+NO_PIE_FLAG
+NO_PIE_CFLAGS
+enable_default_pie
 PICFLAG
 enable_host_shared
 enable_plugin
@@ -937,6 +940,7 @@ enable_host_shared
 enable_libquadmath_support
 with_linker_hash_style
 with_diagnostics_color
+enable_default_pie
 '
       ac_precious_vars='build_alias
 host_alias
@@ -1665,6 +1669,7 @@ Optional Features:
   --enable-host-shared    build host code as shared libraries
   --disable-libquadmath-support
                           disable libquadmath support for Fortran
+  --enable-default-pie    enable Position Independent Executable as default
 
 Optional Packages:
   --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
@@ -18147,7 +18152,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 18150 "configure"
+#line 18155 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -18253,7 +18258,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 18256 "configure"
+#line 18261 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -28432,6 +28437,76 @@ cat > gcc-driver-name.h <<EOF
 #define GCC_DRIVER_NAME "${target_noncanonical}-gcc-${gcc_BASEVER}${exeext}"
 EOF
 
+# Check whether --enable-default-pie was given and target have the support.
+# Check whether --enable-default-pie was given.
+if test "${enable_default_pie+set}" = set; then :
+  enableval=$enable_default_pie; enable_default_pie=$enableval
+else
+  enable_default_pie=no
+fi
+
+if test x$enable_default_pie == xyes ; then
+
+$as_echo "#define ENABLE_DEFAULT_PIE 1" >>confdefs.h
+
+fi
+
+
+# Check if -fno-PIE works.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for -fno-PIE option" >&5
+$as_echo_n "checking for -fno-PIE option... " >&6; }
+if test "${gcc_cv_c_no_fpie+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  saved_CFLAGS="$CFLAGS"
+   CFLAGS="$CFLAGS -fno-PIE"
+   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int main(void) {return 0;}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  gcc_cv_c_no_fpie=yes
+else
+  gcc_cv_c_no_fpie=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+   CFLAGS="$saved_CFLAGS"
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_c_no_fpie" >&5
+$as_echo "$gcc_cv_c_no_fpie" >&6; }
+if test "$gcc_cv_c_no_fpie" = "yes"; then
+  NO_PIE_CFLAGS="-fno-PIE"
+fi
+
+
+# Check if -no-pie works.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for -no-pie option" >&5
+$as_echo_n "checking for -no-pie option... " >&6; }
+if test "${gcc_cv_no_pie+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  saved_LDFLAGS="$LDFLAGS"
+   LDFLAGS="$LDFLAGS -no-pie"
+   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int main(void) {return 0;}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  gcc_cv_no_pie=yes
+else
+  gcc_cv_no_pie=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+   LDFLAGS="$saved_LDFLAGS"
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_no_pie" >&5
+$as_echo "$gcc_cv_no_pie" >&6; }
+if test "$gcc_cv_no_pie" = "yes"; then
+  NO_PIE_FLAG="-no-pie"
+fi
+
+
 # Configure the subdirectories
 # AC_CONFIG_SUBDIRS($subdirs)
 
diff --git a/gcc/configure.ac b/gcc/configure.ac
index 102dab9..e6da960 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -5759,6 +5759,46 @@ cat > gcc-driver-name.h <<EOF
 #define GCC_DRIVER_NAME "${target_noncanonical}-gcc-${gcc_BASEVER}${exeext}"
 EOF
 
+# 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])],
+enable_default_pie=$enableval,
+enable_default_pie=no)
+if test x$enable_default_pie == xyes ; then
+  AC_DEFINE(ENABLE_DEFAULT_PIE, 1,
+      [Define if your target supports default PIE and it is enabled.])
+fi
+AC_SUBST([enable_default_pie])
+
+# Check if -fno-PIE works.
+AC_CACHE_CHECK([for -fno-PIE option],
+  [gcc_cv_c_no_fpie],
+  [saved_CFLAGS="$CFLAGS"
+   CFLAGS="$CFLAGS -fno-PIE"
+   AC_COMPILE_IFELSE([int main(void) {return 0;}],
+     [gcc_cv_c_no_fpie=yes],
+     [gcc_cv_c_no_fpie=no])
+   CFLAGS="$saved_CFLAGS"])
+if test "$gcc_cv_c_no_fpie" = "yes"; then
+  NO_PIE_CFLAGS="-fno-PIE"
+fi
+AC_SUBST([NO_PIE_CFLAGS])
+
+# Check if -no-pie works.
+AC_CACHE_CHECK([for -no-pie option],
+  [gcc_cv_no_pie],
+  [saved_LDFLAGS="$LDFLAGS"
+   LDFLAGS="$LDFLAGS -no-pie"
+   AC_LINK_IFELSE([int main(void) {return 0;}],
+     [gcc_cv_no_pie=yes],
+     [gcc_cv_no_pie=no])
+   LDFLAGS="$saved_LDFLAGS"])
+if test "$gcc_cv_no_pie" = "yes"; then
+  NO_PIE_FLAG="-no-pie"
+fi
+AC_SUBST([NO_PIE_FLAG])
+
 # Configure the subdirectories
 # AC_CONFIG_SUBDIRS($subdirs)
 
diff --git a/gcc/defaults.h b/gcc/defaults.h
index 5cef92c..970040e 100644
--- a/gcc/defaults.h
+++ b/gcc/defaults.h
@@ -1182,6 +1182,12 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #define DEFAULT_PCC_STRUCT_RETURN 1
 #endif
 
+/* Default PIE to -fPIE.  */
+#ifndef DEFAULT_FLAG_PIE
+# define DEFAULT_FLAG_PIE 2
+#endif
+
+
 #ifdef GCC_INSN_FLAGS_H
 /* Dependent default target macro definitions
 
diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
index c9e3bf1..aaed6c7 100644
--- a/gcc/doc/install.texi
+++ b/gcc/doc/install.texi
@@ -1583,6 +1583,9 @@ not be built.
 Specify that the run-time libraries for stack smashing protection
 should not be built.
 
+@item --enable-default-pie
+Turn on @option{-fPIE} and @option{-pie} by default.
+
 @item --disable-libquadmath
 Specify that the GCC quad-precision math library should not be built.
 On some systems, the library is required to be linkable when building
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index d84e3b7..7b8ed89 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -10973,6 +10973,10 @@ For predictable results, you must also specify the same set of options
 used for compilation (@option{-fpie}, @option{-fPIE},
 or model suboptions) when you specify this linker option.
 
+@item -no-pie
+@opindex no-pie
+Don't produce a position independent executable.
+
 @item -rdynamic
 @opindex rdynamic
 Pass the flag @option{-export-dynamic} to the ELF linker, on targets
diff --git a/gcc/gcc.c b/gcc/gcc.c
index 55d0ff2..db15f69 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -734,12 +734,20 @@ proper position among the other output files.  */
 #endif
 #endif
 
+#ifdef ENABLE_DEFAULT_PIE
+#define NO_PIE_SPEC	"no-pie|static"
+#define PIE_SPEC	NO_PIE_SPEC "|r|shared:;"
+#else
+#define PIE_SPEC "pie"
+#endif
+
 #ifndef LINK_PIE_SPEC
 #ifdef HAVE_LD_PIE
-#define LINK_PIE_SPEC "%{pie:-pie} "
+#define LD_PIE_SPEC "-pie"
 #else
-#define LINK_PIE_SPEC "%{pie:} "
+#define LD_PIE_SPEC ""
 #endif
+#define LINK_PIE_SPEC "%{no-pie:} " "%{" PIE_SPEC ":" LD_PIE_SPEC "} "
 #endif
 
 #ifndef LINK_BUILDID_SPEC
diff --git a/gcc/opts.c b/gcc/opts.c
index 8a16116..ee769c8 100644
--- a/gcc/opts.c
+++ b/gcc/opts.c
@@ -738,8 +738,22 @@ finish_options (struct gcc_options *opts, struct gcc_options *opts_set,
       opts->x_flag_section_anchors = 0;
     }
 
+#ifndef ENABLE_DEFAULT_PIE
+#undef DEFAULT_FLAG_PIE
+#define DEFAULT_FLAG_PIE 0
+#endif
+
   if (!opts->x_flag_opts_finished)
     {
+      /* We initialize opts->x_flag_pie to -1 so that targets can set a
+	 default value.  */
+      if (opts->x_flag_pie == -1)
+	{
+	  if (opts->x_flag_pic == 0)
+	    opts->x_flag_pie = DEFAULT_FLAG_PIE;
+	  else
+	    opts->x_flag_pie = 0;
+	}
       if (opts->x_flag_pie)
 	opts->x_flag_pic = opts->x_flag_pie;
       if (opts->x_flag_pic && !opts->x_flag_pie)
diff --git a/libgcc/Makefile.in b/libgcc/Makefile.in
index f693883..8d10386 100644
--- a/libgcc/Makefile.in
+++ b/libgcc/Makefile.in
@@ -284,7 +284,7 @@ INTERNAL_CFLAGS = $(CFLAGS) $(LIBGCC2_CFLAGS) $(HOST_LIBGCC2_CFLAGS) \
 
 # Options to use when compiling crtbegin/end.
 CRTSTUFF_CFLAGS = -O2 $(GCC_CFLAGS) $(INCLUDES) $(MULTILIB_CFLAGS) -g0 \
-  -finhibit-size-directive -fno-inline -fno-exceptions \
+  $(NO_PIE_CFLAGS) -finhibit-size-directive -fno-inline -fno-exceptions \
   -fno-zero-initialized-in-bss -fno-toplevel-reorder -fno-tree-vectorize \
   -fbuilding-libgcc -fno-stack-protector $(FORCE_EXPLICIT_EH_REGISTRY) \
   $(INHIBIT_LIBC_CFLAGS)

^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2015-01-13 23:25 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-31 20:32 [PATCH][1-3] New configure options that make the compiler use -fPIE and -pie as default option Magnus Granberg
2014-08-01  8:52 ` Rainer Orth
2014-08-31 15:49   ` Gerald Pfeifer
2014-11-10 20:33   ` Magnus Granberg
2014-11-14 23:19     ` Magnus Granberg
2014-12-30 22:04       ` [PING][PATCH][1-3] " Magnus Granberg
2015-01-09  4:31         ` Allan McRae
2015-01-09 13:04         ` Richard Biener
2015-01-09 14:17           ` Daniel Micay
2015-01-09 17:57             ` Joseph Myers
2015-01-09 18:03               ` Daniel Micay
2015-01-09 20:40                 ` Magnus Granberg
2015-01-10  2:32                   ` H.J. Lu
2015-01-10 17:06                     ` H.J. Lu
2015-01-12 16:18           ` [PATCH]: " H.J. Lu
2015-01-12 23:53             ` Joseph Myers
2015-01-13  0:31               ` H.J. Lu
2015-01-13 13:10               ` H.J. Lu
2015-01-14  0:03                 ` H.J. Lu
2015-01-09 10:48     ` [PATCH][1-3] " Marcus Meissner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).