Add --enable-default-pie option to GCC configure
authorH.J. Lu <hjl@gcc.gnu.org>
Thu, 28 May 2015 02:36:55 +0000 (19:36 -0700)
committerH.J. Lu <hjl@gcc.gnu.org>
Thu, 28 May 2015 02:36:55 +0000 (19:36 -0700)
Add --enable-default-pie option to configure GCC to generate PIE by
default.

gcc/

* Makefile.in (COMPILER): Add @NO_PIE_CFLAGS@.
(BUILD_CFLAGS): Likewise.
(BUILD_CXXFLAGS): Likewise.
(LINKER): Add @NO_PIE_FLAG@.
(BUILD_LDFLAGS): Likewise.
(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.
(NO_FPIE1_SPEC): Likewise.
(FPIE1_SPEC): Likewise.
(NO_FPIE2_SPEC): Likewise.
(FPIE2_SPEC): Likewise.
(NO_FPIE2_SPEC): Likewise.
(FPIE_SPEC): Likewise.
(NO_FPIE_SPEC): Likewise.
(NO_FPIC1_SPEC): Likewise.
(FPIC1_SPEC): Likewise.
(NO_FPIC2_SPEC): Likewise.
(FPIC2_SPEC): Likewise.
(NO_FPIC2_SPEC): Likewise.
(FPIC_SPEC): Likewise.
(NO_FPIC_SPEC): Likewise.
(NO_FPIE1_AND_FPIC1_SPEC): Likewise.
(FPIE1_OR_FPIC1_SPEC): Likewise.
(NO_FPIE2_AND_FPIC2_SPEC): Likewise.
(FPIE2_OR_FPIC2_SPEC): Likewise.
(NO_FPIE_AND_FPIC_SPEC): Likewise.
(FPIE_OR_FPIC_SPEC): Likewise.
(LD_PIE_SPEC): Likewise.
(LINK_PIE_SPEC): Handle -no-pie.  Use PIE_SPEC and LD_PIE_SPEC.
* opts.c (finish_options): Update opts->x_flag_pie if it is -1.
* config/darwin.h (PIE_SPEC): Renamed to ...
(DARWIN_PIE_SPEC): This.
(LINK_SPEC): Replace PIE_SPEC with DARWIN_PIE_SPEC.
* config/darwin9.h (PIE_SPEC): Renamed to ...
(DARWIN_PIE_SPEC): This.
* config/gnu-user.h (GNU_USER_TARGET_STARTFILE_SPEC): Use
PIE_SPEC and NO_PIE_SPEC if HAVE_LD_PIE is defined.
* config/openbsd.h (ASM_SPEC): Use FPIE1_OR_FPIC1_SPEC and
FPIE2_OR_FPIC2_SPEC.
* config/m68k/netbsd-elf.h (ASM_SPEC): Likewise.
* config/m68k/openbsd.h (ASM_SPEC): Likewise.
* gcc/config/sol2.h (ASM_PIC_SPEC): Likewise.
* config/arm/freebsd.h (SUBTARGET_EXTRA_ASM_SPEC): Likewise.
* config/arm/netbsd-elf.h (SUBTARGET_EXTRA_ASM_SPEC): Likewise.
* config/arm/semi.h (SUBTARGET_EXTRA_ASM_SPEC): Likewise.
* config/cris/linux.h (CRIS_ASM_SUBTARGET_SPEC): Likewise.
* config/m32r/m32r.h (ASM_SPEC): Likewise.
* config/m68k/uclinux.h (DRIVER_SELF_SPECS): Likewise.
* config/rs6000/linux64.h (ASM_SPEC32): Likewise.
* config/rs6000/sysv4.h (ASM_SPEC): Likewise.
* config/sparc/freebsd.h (ASM_SPEC): Likewise.
* config/sparc/linux.h (ASM_SPEC): Likewise.
* config/sparc/linux64.h (ASM_SPEC): Likewise.
* config/sparc/netbsd-elf.h (ASM_SPEC): Likewise.
* config/sparc/openbsd64.h (ASM_SPEC): Likewise.
* config/sparc/sp-elf.h (ASM_SPEC): Likewise.
* config/sparc/sp64-elf.h (ASM_SPEC): Likewise.
* config/sparc/sparc.h (ASM_SPEC): Likewise.
* config/sparc/sysv4.h (ASM_SPEC): Likewise.
* config/sparc/vxworks.h (ASM_SPEC): Likewise.
* config/c6x/elf-common.h (ASM_SPEC): Use NO_FPIC2_SPEC,
FPIC2_SPEC, FPIC1_SPEC and FPIC2_SPEC.
* config/c6x/uclinux-elf.h (LINK_SPEC): Use FPIE_SPEC.
* config/frv/frv.h (DRIVER_SELF_SPECS): Use FPIC_SPEC,
NO_FPIC_SPEC and NO_FPIE1_AND_FPIC1_SPEC.
(ASM_SPEC): Use FPIE1_OR_FPIC1_SPEC and FPIE2_OR_FPIC2_SPEC.
* config/m68k/m68k.h (ASM_PCREL_SPEC): Use FPIC_SPEC and
NO_FPIC_SPEC.
* config/mips/gnu-user.h (NO_SHARED_SPECS): Use
NO_FPIE_AND_FPIC_SPEC.
* config/mips/vxworks.h (SUBTARGET_ASM_SPEC): Use FPIC_SPEC.
* config/rs6000/freebsd64.h (ASM_SPEC32): Likewise.
* config/rs6000/vxworks.h (ASM_SPEC): Likewise.
* config/vax/linux.h (ASM_SPEC): Likewise.
* doc/install.texi: Document --enable-default-pie.
* doc/invoke.texi: Document -no-pie.
* config.in: Regenerated.
* configure: Likewise.

gcc/ada/

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

libgcc/

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

From-SVN: r223796

49 files changed:
gcc/ChangeLog
gcc/Makefile.in
gcc/ada/ChangeLog
gcc/ada/gcc-interface/Makefile.in
gcc/common.opt
gcc/config.in
gcc/config/arm/freebsd.h
gcc/config/arm/netbsd-elf.h
gcc/config/arm/semi.h
gcc/config/c6x/elf-common.h
gcc/config/c6x/uclinux-elf.h
gcc/config/cris/linux.h
gcc/config/darwin.h
gcc/config/darwin9.h
gcc/config/frv/frv.h
gcc/config/gnu-user.h
gcc/config/m32r/m32r.h
gcc/config/m68k/m68k.h
gcc/config/m68k/netbsd-elf.h
gcc/config/m68k/openbsd.h
gcc/config/m68k/uclinux.h
gcc/config/mips/gnu-user.h
gcc/config/mips/vxworks.h
gcc/config/openbsd.h
gcc/config/rs6000/freebsd64.h
gcc/config/rs6000/linux64.h
gcc/config/rs6000/sysv4.h
gcc/config/rs6000/vxworks.h
gcc/config/sol2.h
gcc/config/sparc/freebsd.h
gcc/config/sparc/linux.h
gcc/config/sparc/linux64.h
gcc/config/sparc/netbsd-elf.h
gcc/config/sparc/openbsd64.h
gcc/config/sparc/sp-elf.h
gcc/config/sparc/sp64-elf.h
gcc/config/sparc/sparc.h
gcc/config/sparc/sysv4.h
gcc/config/sparc/vxworks.h
gcc/config/vax/linux.h
gcc/configure
gcc/configure.ac
gcc/defaults.h
gcc/doc/install.texi
gcc/doc/invoke.texi
gcc/gcc.c
gcc/opts.c
libgcc/ChangeLog
libgcc/Makefile.in

index 74be3c707e92986b5eee25dab11e3be9cb3e2d10..29c26c4066134d2b8e99c6441a7c9f3979fb6d60 100644 (file)
@@ -1,3 +1,95 @@
+2015-05-27  Magnus Granberg  <zorry@gentoo.org>
+           H.J. Lu  <hongjiu.lu@intel.com>
+
+       * Makefile.in (COMPILER): Add @NO_PIE_CFLAGS@.
+       (BUILD_CFLAGS): Likewise.
+       (BUILD_CXXFLAGS): Likewise.
+       (LINKER): Add @NO_PIE_FLAG@.
+       (BUILD_LDFLAGS): Likewise.
+       (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.
+       (NO_FPIE1_SPEC): Likewise.
+       (FPIE1_SPEC): Likewise.
+       (NO_FPIE2_SPEC): Likewise.
+       (FPIE2_SPEC): Likewise.
+       (NO_FPIE2_SPEC): Likewise.
+       (FPIE_SPEC): Likewise.
+       (NO_FPIE_SPEC): Likewise.
+       (NO_FPIC1_SPEC): Likewise.
+       (FPIC1_SPEC): Likewise.
+       (NO_FPIC2_SPEC): Likewise.
+       (FPIC2_SPEC): Likewise.
+       (NO_FPIC2_SPEC): Likewise.
+       (FPIC_SPEC): Likewise.
+       (NO_FPIC_SPEC): Likewise.
+       (NO_FPIE1_AND_FPIC1_SPEC): Likewise.
+       (FPIE1_OR_FPIC1_SPEC): Likewise.
+       (NO_FPIE2_AND_FPIC2_SPEC): Likewise.
+       (FPIE2_OR_FPIC2_SPEC): Likewise.
+       (NO_FPIE_AND_FPIC_SPEC): Likewise.
+       (FPIE_OR_FPIC_SPEC): Likewise.
+       (LD_PIE_SPEC): Likewise.
+       (LINK_PIE_SPEC): Handle -no-pie.  Use PIE_SPEC and LD_PIE_SPEC.
+       * opts.c (finish_options): Update opts->x_flag_pie if it is -1.
+       * config/darwin.h (PIE_SPEC): Renamed to ...
+       (DARWIN_PIE_SPEC): This.
+       (LINK_SPEC): Replace PIE_SPEC with DARWIN_PIE_SPEC.
+       * config/darwin9.h (PIE_SPEC): Renamed to ...
+       (DARWIN_PIE_SPEC): This.
+       * config/gnu-user.h (GNU_USER_TARGET_STARTFILE_SPEC): Use
+       PIE_SPEC and NO_PIE_SPEC if HAVE_LD_PIE is defined.
+       * config/openbsd.h (ASM_SPEC): Use FPIE1_OR_FPIC1_SPEC and
+       FPIE2_OR_FPIC2_SPEC.
+       * config/m68k/netbsd-elf.h (ASM_SPEC): Likewise.
+       * config/m68k/openbsd.h (ASM_SPEC): Likewise.
+       * gcc/config/sol2.h (ASM_PIC_SPEC): Likewise.
+       * config/arm/freebsd.h (SUBTARGET_EXTRA_ASM_SPEC): Likewise.
+       * config/arm/netbsd-elf.h (SUBTARGET_EXTRA_ASM_SPEC): Likewise.
+       * config/arm/semi.h (SUBTARGET_EXTRA_ASM_SPEC): Likewise.
+       * config/cris/linux.h (CRIS_ASM_SUBTARGET_SPEC): Likewise.
+       * config/m32r/m32r.h (ASM_SPEC): Likewise.
+       * config/m68k/uclinux.h (DRIVER_SELF_SPECS): Likewise.
+       * config/rs6000/linux64.h (ASM_SPEC32): Likewise.
+       * config/rs6000/sysv4.h (ASM_SPEC): Likewise.
+       * config/sparc/freebsd.h (ASM_SPEC): Likewise.
+       * config/sparc/linux.h (ASM_SPEC): Likewise.
+       * config/sparc/linux64.h (ASM_SPEC): Likewise.
+       * config/sparc/netbsd-elf.h (ASM_SPEC): Likewise.
+       * config/sparc/openbsd64.h (ASM_SPEC): Likewise.
+       * config/sparc/sp-elf.h (ASM_SPEC): Likewise.
+       * config/sparc/sp64-elf.h (ASM_SPEC): Likewise.
+       * config/sparc/sparc.h (ASM_SPEC): Likewise.
+       * config/sparc/sysv4.h (ASM_SPEC): Likewise.
+       * config/sparc/vxworks.h (ASM_SPEC): Likewise.
+       * config/c6x/elf-common.h (ASM_SPEC): Use NO_FPIC2_SPEC,
+       FPIC2_SPEC, FPIC1_SPEC and FPIC2_SPEC.
+       * config/c6x/uclinux-elf.h (LINK_SPEC): Use FPIE_SPEC.
+       * config/frv/frv.h (DRIVER_SELF_SPECS): Use FPIC_SPEC,
+       NO_FPIC_SPEC and NO_FPIE1_AND_FPIC1_SPEC.
+       (ASM_SPEC): Use FPIE1_OR_FPIC1_SPEC and FPIE2_OR_FPIC2_SPEC.
+       * config/m68k/m68k.h (ASM_PCREL_SPEC): Use FPIC_SPEC and
+       NO_FPIC_SPEC.
+       * config/mips/gnu-user.h (NO_SHARED_SPECS): Use
+       NO_FPIE_AND_FPIC_SPEC.
+       * config/mips/vxworks.h (SUBTARGET_ASM_SPEC): Use FPIC_SPEC.
+       * config/rs6000/freebsd64.h (ASM_SPEC32): Likewise.
+       * config/rs6000/vxworks.h (ASM_SPEC): Likewise.
+       * config/vax/linux.h (ASM_SPEC): Likewise.
+       * doc/install.texi: Document --enable-default-pie.
+       * doc/invoke.texi: Document -no-pie.
+       * config.in: Regenerated.
+       * configure: Likewise.
+
 2015-05-28  Thomas Preud'homme  <thomas.preudhomme@arm.com>
 
        PR rtl-optimization/66168
index 03c2ac6a62ee15102b8c6ea24d3bf940d1fdc85d..b59b5d9e6e9773f2bde01641a5d9c7a84fd396f0 100644 (file)
@@ -253,6 +253,12 @@ LINKER = $(CC)
 LINKER_FLAGS = $(CFLAGS)
 endif
 
+# We don't want to compile the compilers 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)
@@ -746,6 +752,8 @@ CC_FOR_BUILD = @CC_FOR_BUILD@
 CXX_FOR_BUILD = @CXX_FOR_BUILD@
 BUILD_CFLAGS= @BUILD_CFLAGS@ -DGENERATOR_FILE
 BUILD_CXXFLAGS = @BUILD_CXXFLAGS@ -DGENERATOR_FILE
+BUILD_CFLAGS += @NO_PIE_CFLAGS@
+BUILD_CXXFLAGS += @NO_PIE_CFLAGS@
 
 # Native compiler that we use.  This may be C++ some day.
 COMPILER_FOR_BUILD = $(CXX_FOR_BUILD)
@@ -757,6 +765,7 @@ BUILD_LINKERFLAGS = $(BUILD_CXXFLAGS)
 
 # Native linker and preprocessor flags.  For x-fragment overrides.
 BUILD_LDFLAGS=@BUILD_LDFLAGS@
+BUILD_LDFLAGS += @NO_PIE_FLAG@
 BUILD_CPPFLAGS= -I. -I$(@D) -I$(srcdir) -I$(srcdir)/$(@D) \
                -I$(srcdir)/../include @INCINTL@ $(CPPINC) $(CPPFLAGS)
 
@@ -1860,6 +1869,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
 
index 073172eac972e19829c60ccd554617a82aea24cd..aa4aa18a014b0523341aee0ac7c6ae15c3b09610 100644 (file)
@@ -1,3 +1,7 @@
+2015-05-27  H.J. Lu  <hongjiu.lu@intel.com>
+
+       * gcc-interface/Makefile.in (TOOLS_LIBS): Add @NO_PIE_FLAG@.
+
 2015-05-27  Eric Botcazou  <ebotcazou@adacore.com>
 
        * gcc-interface/trans.c (elaborate_all_entities): Do not elaborate an
index ecc443e106673365b321b849692a02379b3d87bc..90aedb575d753a2727e0a0026b28b00962a2470d 100644 (file)
@@ -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
index 562d34a05ae632c690f079ef2f6bc046345f6c09..6e15af2e189a1f1503af79a2de8b8b94d1d9eb7d 100644 (file)
@@ -1778,7 +1778,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
@@ -1786,7 +1786,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)
 
 fplt
@@ -2863,8 +2863,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
index 231c9abe712bfd244e96d70b8bc200783d1e3450..daaf9067e4f4f5ffd5f0930475f43ad49a38a7a6 100644 (file)
 #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
index 040d7c13b0dd56a9b34b7a66c97eb6f1ba80a2ad..2febf4b6091326a799dea441fb46d0ef25bf0a45 100644 (file)
@@ -34,7 +34,7 @@
 #undef SUBTARGET_EXTRA_ASM_SPEC
 #define SUBTARGET_EXTRA_ASM_SPEC \
   "%{mabi=apcs-gnu|mabi=atpcs:-meabi=gnu;:-meabi=5} " TARGET_FIX_V4BX_SPEC " \
-  %{fpic|fpie:-k} %{fPIC|fPIE:-k}"
+  %{" FPIE_OR_FPIC_SPEC ":-k}"
 
 #undef SUBTARGET_ASM_FLOAT_SPEC
 #ifdef TARGET_FREEBSD_ARM_HARD_FLOAT
index ee085a605976b945e43da388da06bb1313f525bb..65460979410d82f748560b62b7086cf7ec2d051f 100644 (file)
@@ -55,7 +55,7 @@
 
 #undef SUBTARGET_EXTRA_ASM_SPEC
 #define SUBTARGET_EXTRA_ASM_SPEC       \
-  "-matpcs %{fpic|fpie:-k} %{fPIC|fPIE:-k}"
+  "-matpcs %{" FPIE_OR_FPIC_SPEC ":-k}"
 
 /* Default to full VFP if -mfloat-abi=hard is specified.  */
 #undef SUBTARGET_ASM_FLOAT_SPEC
index 18a4443fdcc3d128f7cc939db1d8d5cf730669f6..1c938d3919788e86f29da636b9e0b9ca6d58b940 100644 (file)
@@ -58,7 +58,7 @@
    binutils can't.  */
 #ifndef ASM_SPEC
 #define ASM_SPEC "\
-%{fpic|fpie: -k} %{fPIC|fPIE: -k} \
+%{" FPIE_OR_FPIC_SPEC ": -k} \
 %{mbig-endian:-EB} \
 %(arm_cpu_spec) \
 %{mapcs-float:-mfloat} \
index 844172dd88df10da6398b20707a538c733d4cefd..2a7cd524534973c10cf3b9784f50bd11f6841b77 100644 (file)
 
 #undef ASM_SPEC
 #define ASM_SPEC "%{march=*:-march=%*} %{mbig-endian:-mbig-endian} \
- %{mdsbt:-mdsbt %{!fPIC:-mpid=near} %{fPIC:-mpid=far -mpic} %{fpic:-mpic}} \
- %{!mdsbt:%{fpic:-mpic -mpid=near} %{fPIC:-mpic -mpid=far}}"
+ %{mdsbt:-mdsbt %{" NO_FPIC2_SPEC ":-mpid=near} \
+   %{" FPIC2_SPEC ":-mpid=far -mpic} %{" FPIC1_SPEC ":-mpic}} \
+ %{!mdsbt:%{" FPIC1_SPEC ":-mpic -mpid=near} \
+   %{" FPIC2_SPEC ":-mpic -mpid=far}}"
 
 #undef DATA_SECTION_ASM_OP
 #define DATA_SECTION_ASM_OP "\t.section\t\".fardata\",\"aw\""
index 5048b71df0e7538eb94ce35060b6417f7a3b354a..5a04b9dc5d257232f952529dafcea102a959feea 100644 (file)
@@ -40,7 +40,7 @@
 
 #undef LINK_SPEC
 #define LINK_SPEC ENDIAN_LINK_SPEC \
-  "%{shared} %{fpie|fPIE:-pie} \
+  "%{shared} %{" FPIE_SPEC ":-pie} \
   %{!shared: %{!static: \
    %{rdynamic:-export-dynamic} \
    %{!dynamic-linker:-dynamic-linker " UCLIBC_DYNAMIC_LINKER "}} \
index bd579867a50a233ee126628e46e33eb50be2829b..262aac5c16c27ee4686cfff6fd315a14745e2f81 100644 (file)
@@ -79,13 +79,13 @@ along with GCC; see the file COPYING3.  If not see
  "--em=criself \
   %{!march=*:%{!mcpu=*:--march=v32}} \
   %{!fleading-underscore:--no-underscore}\
-  %{fPIC|fpic|fPIE|fpie: --pic}"
+  %{" FPIE_OR_FPIC_SPEC ": --pic}"
 #else
 # define CRIS_ASM_SUBTARGET_SPEC \
  "--em=criself \
   %{!march=*:%{!mcpu=*:--march=v10}} \
   %{!fleading-underscore:--no-underscore}\
-  %{fPIC|fpic|fPIE|fpie: --pic}"
+  %{" FPIE_OR_FPIC_SPEC ": --pic}"
 #endif
 
 /* Previously controlled by target_flags.  */
index 66f504ed35160285b14b5c3c3061f4b5355f6009..9a31952ce4e65348bb7d60db4d6b726b3239cbdb 100644 (file)
@@ -214,7 +214,7 @@ extern GTY(()) int darwin_ms_struct;
 #define LINK_SYSROOT_SPEC "%{isysroot*:-syslibroot %*}"
 #endif
 
-#define PIE_SPEC "%{fpie|pie|fPIE:}"
+#define DARWIN_PIE_SPEC "%{fpie|pie|fPIE:}"
 
 /* Please keep the random linker options in alphabetical order (modulo
    'Z' and 'no' prefixes). Note that options taking arguments may appear
@@ -280,7 +280,7 @@ extern GTY(()) int darwin_ms_struct;
      %:version-compare(< 10.5 mmacosx-version-min= -multiply_defined) \
      %:version-compare(< 10.5 mmacosx-version-min= suppress)}} \
    %{Zmultiplydefinedunused*:-multiply_defined_unused %*} \
-   " PIE_SPEC " \
+   " DARWIN_PIE_SPEC " \
    %{prebind} %{noprebind} %{nofixprebinding} %{prebind_all_twolevel_modules} \
    %{read_only_relocs} \
    %{sectcreate*} %{sectorder*} %{seg1addr*} %{segprot*} \
index 4204825708e20d7c49b39ab71880cba82848d7ff..309c835b6ee9f459038d37f664b7b75f9a9ca4fe 100644 (file)
@@ -35,8 +35,8 @@ along with GCC; see the file COPYING3.  If not see
 /* Tell collect2 to run dsymutil for us as necessary.  */
 #define COLLECT_RUN_DSYMUTIL 1
 
-#undef PIE_SPEC
-#define PIE_SPEC \
+#undef DARWIN_PIE_SPEC
+#define DARWIN_PIE_SPEC \
   "%{fpie|pie|fPIE: \
      %{mdynamic-no-pic: %n'-mdynamic-no-pic' overrides '-pie', '-fpie' or '-fPIE'; \
       :-pie}}"
index 978fefa26574f52f92bc0fa305f90b65eaac47e9..2d4cbddeb74e489c5e75a337941bf5b43ddd7835 100644 (file)
 "%{mno-pack:\
    %{!mhard-float:-msoft-float}\
    %{!mmedia:-mno-media}}\
- %{!mfdpic:%{fpic|fPIC: -multilib-library-pic}}\
+ %{!mfdpic:%{" FPIC_SPEC ": -multilib-library-pic}}\
  %{mfdpic:%{!fpic:%{!fpie:%{!fPIC:%{!fPIE:\
            %{!fno-pic:%{!fno-pie:%{!fno-PIC:%{!fno-PIE:-fPIE}}}}}}}} \
-         %{!mno-inline-plt:%{O*:%{!O0:%{!Os:%{fpic|fPIC:-minline-plt} \
-                    %{!fpic:%{!fPIC:%{!O:%{!O1:%{!O2:-minline-plt}}}}}}}}} \
-         %{!mno-gprel-ro:%{!fpic:%{!fpie:-mgprel-ro}}}} \
+         %{!mno-inline-plt:%{O*:%{!O0:%{!Os:%{" FPIC_SPEC ":-minline-plt} \
+                    %{" NO_FPIC_SPEC ":%{!O:%{!O1:%{!O2:-minline-plt}}}}}}}} \
+         %{!mno-gprel-ro:%{" NO_FPIE1_AND_FPIC1_SPEC ":-mgprel-ro}}} \
 "
 #ifndef SUBTARGET_DRIVER_SELF_SPECS
 # define SUBTARGET_DRIVER_SELF_SPECS
@@ -67,7 +67,7 @@
     %{mmuladd} %{mno-muladd} \
     %{mpack} %{mno-pack} \
     %{mno-fdpic:-mnopic} %{mfdpic} \
-    %{fpic|fpie: -mpic} %{fPIC|fPIE: -mPIC} %{mlibrary-pic}}"
+    %{" FPIE1_OR_FPIC1_SPEC ":-mpic} %{" FPIE2_OR_FPIC2_SPEC ":-mPIC} %{mlibrary-pic}}"
 
 #undef  STARTFILE_SPEC
 #define STARTFILE_SPEC "crt0%O%s frvbegin%O%s"
index 2faa2e5e85a492ea824c40d4ecb89e81bea2981d..2fcb55dbdab2071ff7e9e3a04016a1290b5b705d 100644 (file)
@@ -42,8 +42,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 
 #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} \
+  "%{!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=none:%s; \
      fvtable-verify=preinit:vtv_start_preinit.o%s; \
      fvtable-verify=std:vtv_start.o%s}"
index 66ceae0c1814c681a7e0e8e924a08feb241e049b..2163de41349b3dfabd2cfd9925e6a2253d52aa43 100644 (file)
 
 /* Options to pass on to the assembler.  */
 #undef  ASM_SPEC
-#define ASM_SPEC "%(asm_cpu) %(relax) %{fpic|fpie:-K PIC} %{fPIC|fPIE:-K PIC}"
+#define ASM_SPEC "%(asm_cpu) %(relax) %{" FPIE_OR_FPIC_SPEC ":-K PIC}"
 
 #define LINK_SPEC "%{v} %(link_cpu) %(relax)"
 
index 88356ccac1fce406f70d53b6d9a213e15d76d8e6..74ebff7fab4bec8eebaca92e17b455f3e6e33df1 100644 (file)
@@ -40,7 +40,8 @@ along with GCC; see the file COPYING3.  If not see
 %{m68020-40:-m68040}%{m68020-60:-m68040}\
 %{mcpu=*:-mcpu=%*}%{march=*:-march=%*}\
 "
-#define ASM_PCREL_SPEC "%{fPIC|fpic|mpcrel:--pcrel} \
+#define ASM_PCREL_SPEC "%{" FPIC_SPEC ":--pcrel} \
+ %{mpcrel:%{" NO_FPIC_SPEC ":--pcrel}} \
  %{msep-data|mid-shared-library:--pcrel} \
 "
 
index 3922d255b443bc80d11b24ff5a14eb870aea3c53..a180667bf3d72c036a6eea85101c0620afe44a70 100644 (file)
@@ -56,7 +56,8 @@ along with GCC; see the file COPYING3.  If not see
    to pass PIC code generation options.  */
 
 #undef ASM_SPEC
-#define ASM_SPEC "%(asm_cpu_spec) %{fpic|fpie:-k} %{fPIC|fPIE:-k -K}"
+#define ASM_SPEC \
+  "%(asm_cpu_spec) %{" FPIE1_OR_FPIC1_SPEC ":-k} %{" FPIE2_OR_FPIC2_SPEC ":-k -K}"
 
 /* Provide a LINK_SPEC appropriate for a NetBSD/m68k ELF target.  */
 
index 34ea77f388673b9ec0ffb08e6b617ccf1e8c2658..379ca85f5676e3b2360d001677cc39d2a7d3e95c 100644 (file)
@@ -34,7 +34,8 @@ along with GCC; see the file COPYING3.  If not see
 #define CPP_SPEC "%{!msoft-float:-D__HAVE_68881__ -D__HAVE_FPU__} %{posix:-D_POSIX_SOURCE} %{pthread:-D_POSIX_THREADS}"
 
 #undef ASM_SPEC
-#define ASM_SPEC "%(asm_cpu_spec) %{fpic|fpie:-k} %{fPIC|fPIE:-k -K}"
+#define ASM_SPEC \
+  "%(asm_cpu_spec) %{" FPIE1_OR_FPIC1_SPEC ":-k} %{" FPIE2_OR_FPIC2_SPEC ":-k -K}"
 
 /* Layout of source language data types.  */
 
index a6c3f7fa61dc92b114c68af6c536031f74f2cd50..ef6a3a0f504cfc2fce285808c427b9350d142bac 100644 (file)
@@ -60,7 +60,7 @@ along with GCC; see the file COPYING3.  If not see
 
 /* -msep-data is the default PIC mode on this target.  */
 #define DRIVER_SELF_SPECS \
-  "%{fpie|fPIE|fpic|fPIC:%{!msep-data:%{!mid-shared-library: -msep-data}}}"
+  "%{" FPIE_OR_FPIC_SPEC ":%{!msep-data:%{!mid-shared-library: -msep-data}}}"
 
 /* The uclinux binary format relies on relocations against a segment being
    within that segment.  Conservatively apply this rule to individual
index 28b00ed20a503df0f01f0e4bc83141c9dbe98d35..dd4cf11377e9dbfb32206d274bc4bf7fd2bed042 100644 (file)
@@ -100,7 +100,7 @@ along with GCC; see the file COPYING3.  If not see
 #ifdef HAVE_AS_NO_SHARED
 /* Default to -mno-shared for non-PIC.  */
 # define NO_SHARED_SPECS \
-  " %{mshared|mno-shared|fpic|fPIC|fpie|fPIE:;:-mno-shared}"
+  " %{mshared|mno-shared:;:%{" NO_FPIE_AND_FPIC_SPEC ":-mno-shared}}"
 #else
 # define NO_SHARED_SPECS ""
 #endif
index 96512a20056114f3ff8a090ccacc5dfc2c516437..0fa40b0d7d6fcc130e9547692dc508d6fd2c7099 100644 (file)
@@ -70,7 +70,7 @@ VXWORKS_LINK_SPEC
 #define FUNCTION_PROFILER VXWORKS_FUNCTION_PROFILER
 
 #undef SUBTARGET_ASM_SPEC
-#define SUBTARGET_ASM_SPEC "%{mrtp:%{fPIC|fpic:-mvxworks-pic}}"
+#define SUBTARGET_ASM_SPEC "%{mrtp:%{" FPIC_SPEC ":-mvxworks-pic}}"
 
 #undef SUBTARGET_OVERRIDE_OPTIONS
 #define SUBTARGET_OVERRIDE_OPTIONS VXWORKS_OVERRIDE_OPTIONS
index 5890078dd417f5dd35f8885b69660273af756aa7..cf6654898ebf7a706e94c98b0d4d4f9036af37be 100644 (file)
@@ -126,7 +126,7 @@ while (0)
    still uses a special flavor of gas that needs to be told when generating 
    pic code.  */
 #undef ASM_SPEC
-#define ASM_SPEC "%{fpic|fpie:-k} %{fPIC|fPIE:-k -K}"
+#define ASM_SPEC "%{" FPIE1_OR_FPIC1_SPEC ":-k} %{" FPIE2_OR_FPIC2_SPEC ":-k -K}"
 #endif
 
 /* Since we use gas, stdin -> - is a good idea.  */
index 84066f60e1454d3659c8cb5ae89b9a1c8c7136d3..7e630231bc7eabe86b0748e9d1ef92fdcf3b04c2 100644 (file)
@@ -130,7 +130,7 @@ extern int dot_symbols;
 #define        LINK_OS_FREEBSD_SPEC "%{m32:%(link_os_freebsd_spec32)}%{!m32:%(link_os_freebsd_spec64)}"
 
 #define ASM_SPEC32 "-a32 \
-%{mrelocatable} %{mrelocatable-lib} %{fpic:-K PIC} %{fPIC:-K PIC} \
+%{mrelocatable} %{mrelocatable-lib} %{" FPIC_SPEC ":-K PIC} \
 %{memb} %{!memb: %{msdata=eabi: -memb}} \
 %{!mlittle: %{!mlittle-endian: %{!mbig: %{!mbig-endian: \
     %{mcall-freebsd: -mbig} \
index 1b7f695bc60a1f72df4e13609a256d7f0c8fe2f8..bec0fd9c84210f7c786d1deaea8e924dea123861 100644 (file)
@@ -192,7 +192,7 @@ extern int dot_symbols;
 #endif
 
 #define ASM_SPEC32 "-a32 \
-%{mrelocatable} %{mrelocatable-lib} %{fpic|fpie|fPIC|fPIE:-K PIC} \
+%{mrelocatable} %{mrelocatable-lib} %{" FPIE_OR_FPIC_SPEC ":-K PIC} \
 %{memb|msdata=eabi: -memb}"
 
 #define ASM_SPEC64 "-a64"
index 41ed4eff0662fea6c6d78ace4c2ec67c6401a8e3..24618e309f16596ba3743c2ebfce4d2d0b65070f 100644 (file)
@@ -530,7 +530,7 @@ extern int fixuplabelno;
 #undef ASM_SPEC
 #define        ASM_SPEC "%(asm_cpu) \
 %{,assembler|,assembler-with-cpp: %{mregnames} %{mno-regnames}} \
-%{mrelocatable} %{mrelocatable-lib} %{fpic|fpie|fPIC|fPIE:-K PIC} \
+%{mrelocatable} %{mrelocatable-lib} %{" FPIE_OR_FPIC_SPEC ":-K PIC} \
 %{memb|msdata=eabi: -memb}" \
 ENDIAN_SELECT(" -mbig", " -mlittle", DEFAULT_ASM_ENDIAN)
 
index b4f88debb96e1b584e840c37b1e40078cb066187..744017204ab2b703b40e981f4244fceccc1c7e29 100644 (file)
@@ -90,7 +90,7 @@ VXWORKS_ADDITIONAL_CPP_SPEC
 #define ASM_SPEC \
 "%(asm_cpu) \
  %{,assembler|,assembler-with-cpp: %{mregnames} %{mno-regnames}} \
- %{mrelocatable} %{mrelocatable-lib} %{fpic:-K PIC} %{fPIC:-K PIC} -mbig"
+ %{mrelocatable} %{mrelocatable-lib} %{" FPIC_SPEC ":-K PIC} -mbig"
 
 #undef  LIB_SPEC
 #define LIB_SPEC VXWORKS_LIB_SPEC
index 4dceb16d4c73a41b422faf0a672400c732840aab..adf6f3b9fbe06347479d4445e33c3cfe1c8ebd22 100644 (file)
@@ -127,7 +127,7 @@ along with GCC; see the file COPYING3.  If not see
 #define ASM_SPEC_BASE \
 "%{v:-V} %{Qy:} %{!Qn:-Qy} %{Ym,*} -s %(asm_cpu)"
 
-#define ASM_PIC_SPEC " %{fpic|fpie|fPIC|fPIE:-K PIC}"
+#define ASM_PIC_SPEC " %{" FPIE_OR_FPIC_SPEC ":-K PIC}"
 
 #undef ASM_CPU_DEFAULT_SPEC
 #define ASM_CPU_DEFAULT_SPEC \
index fa40d4e16174a92a7433a10d4ac80792ac6b0423..f469bf1d89cbe970eabdafd4496bf8fb7ed92256 100644 (file)
@@ -38,7 +38,7 @@ along with GCC; see the file COPYING3.  If not see
   while (0)
 
 #undef ASM_SPEC
-#define ASM_SPEC "%{fpic|fPIC|fpie|fPIE:-K PIC} %(asm_cpu)"
+#define ASM_SPEC "%{" FPIE_OR_FPIC_SPEC ":-K PIC} %(asm_cpu)"
 
 #define LINK_SPEC "%(link_arch)                                                \
   %{!mno-relax:%{!r:-relax}}                                           \
index 56def4bcd4738a3ffd1430a7effb7792fc0b7e81..17e1e862b68d753f8729df61f12224d4d33577d8 100644 (file)
@@ -98,7 +98,7 @@ extern const char *host_detect_local_cpu (int argc, const char **argv);
 #undef ASM_SPEC
 #define ASM_SPEC "\
 -s \
-%{fpic|fPIC|fpie|fPIE:-K PIC} \
+%{" FPIE_OR_FPIC_SPEC ":-K PIC} \
 %{!.c:%{findirect-dispatch:-K PIC}} \
 %(asm_cpu) %(asm_relax)"
 
index fa805fd4432e7d31b2068c38dc371b5fc26f892b..43da8480f24bc68cc60a8f1dc2d07c0175f7efee 100644 (file)
@@ -208,7 +208,7 @@ extern const char *host_detect_local_cpu (int argc, const char **argv);
 #undef ASM_SPEC
 #define ASM_SPEC "\
 -s \
-%{fpic|fPIC|fpie|fPIE:-K PIC} \
+%{" FPIE_OR_FPIC_SPEC ":-K PIC} \
 %{!.c:%{findirect-dispatch:-K PIC}} \
 %(asm_cpu) %(asm_arch) %(asm_relax)"
 
index 165660ce532beb8d34c3a5e9e446ada8b1aa79ea..6f99ed4853c82a0cd5c30d66259c1eead02967f4 100644 (file)
@@ -67,7 +67,7 @@ along with GCC; see the file COPYING3.  If not see
 #define USER_LABEL_PREFIX ""
 
 #undef ASM_SPEC
-#define ASM_SPEC "%{fpic|fPIC|fpie|fPIE:-K PIC} \
+#define ASM_SPEC "%{" FPIE_OR_FPIC_SPEC ":-K PIC} \
 %(asm_cpu) %(asm_arch) %(asm_relax)"
 
 #undef STDC_0_IN_SYSTEM_HEADERS
index a84d2106e634314ff0c4776376575d9054495aad..b62f9c3e65c4ad30a98adff20e6c56ea54d781b1 100644 (file)
@@ -46,7 +46,7 @@ along with GCC; see the file COPYING3.  If not see
 
 #undef ASM_SPEC
 #define ASM_SPEC "\
--s %{fpic|fPIC|fpie|fPIE:-K PIC} \
+-s %{" FPIE_OR_FPIC_SPEC ":-K PIC} \
 %(asm_cpu) %(asm_arch) \
 "
 
index 85da652a99d117a466d6c53b6ac9f9b62e7cc248..371bb6a767db384a7b79e99eb8f5e397ababad23 100644 (file)
@@ -25,7 +25,7 @@ along with GCC; see the file COPYING3.  If not see
 #undef ASM_SPEC
 #define ASM_SPEC \
   "-s \
-   %{fpic|fpie|fPIC|fPIE:-K PIC} %(asm_cpu)"
+   %{" FPIE_OR_FPIC_SPEC ":-K PIC} %(asm_cpu)"
 
 /* Use the default.  */
 #undef LINK_SPEC
index 2fbdfd0872f66a75abedb7aaf9526a92e15cf1f8..43adbb50839ce5e26dbd70e73305620c69291bd2 100644 (file)
@@ -32,7 +32,7 @@ along with GCC; see the file COPYING3.  If not see
 
 #undef ASM_SPEC
 #define ASM_SPEC "\
--s %{fpic|fPIC|fpie|fPIE:-K PIC} \
+-s %{" FPIE_OR_FPIC_SPEC ":-K PIC} \
 %(asm_cpu) %(asm_arch) \
 "
 
index ce1b68b1b442c920ce9334b7504f039bc3a8ed6d..106d993ee3580b259083b56de0e7292f0624a5e8 100644 (file)
@@ -380,7 +380,7 @@ extern enum cmodel sparc_cmodel;
 /* Special flags to the Sun-4 assembler when using pipe for input.  */
 
 #define ASM_SPEC "\
-%{!pg:%{!p:%{fpic|fPIC|fpie|fPIE:-k}}} %{keep-local-as-symbols:-L} \
+%{!pg:%{!p:%{" FPIE_OR_FPIC_SPEC ":-k}}} %{keep-local-as-symbols:-L} \
 %(asm_cpu) %(asm_relax)"
 
 /* This macro defines names of additional specifications to put in the specs
index ff886b1d195e4b8454d7daef55c428f7f7057748..0b358bbe186ccba0cd1687a0146448a3011fc282 100644 (file)
@@ -41,7 +41,7 @@ along with GCC; see the file COPYING3.  If not see
 #undef ASM_SPEC
 #define ASM_SPEC \
   "%{v:-V} %{Qy:} %{!Qn:-Qy} %{Ym,*} \
-   %{fpic|fPIC|fpie|fPIE:-K PIC} %(asm_cpu)"
+   %{" FPIE_OR_FPIC_SPEC ":-K PIC} %(asm_cpu)"
 
 /* Define the names of various pseudo-op used by the SPARC/svr4 assembler.
    Note that many of these are different from the typical pseudo-ops used
index c66dba8f5a410e68716ba4826d8f8bbdb2d5c7cf..e356b25d429000d2b9ad6234f762c6b5b1260e7b 100644 (file)
@@ -34,7 +34,7 @@ along with GCC; see the file COPYING3.  If not see
 #define CPP_SUBTARGET_SPEC VXWORKS_ADDITIONAL_CPP_SPEC
 
 #undef ASM_SPEC
-#define ASM_SPEC "%{fpic|fPIC|fpie|fPIE:-K PIC} %(asm_cpu)"
+#define ASM_SPEC "%{" FPIE_OR_FPIC_SPEC ":-K PIC} %(asm_cpu)"
 
 #undef LIB_SPEC
 #define LIB_SPEC VXWORKS_LIB_SPEC
index dfcad5be7badc91c0d5ad8e3164bbbdfc34bd9b6..0765ed99ecba9a0053177b749b89bd2b120a5652 100644 (file)
@@ -32,7 +32,7 @@ along with GCC; see the file COPYING3.  If not see
 #define CPP_SPEC "%{posix:-D_POSIX_SOURCE} %{pthread:-D_REENTRANT}"
 
 #undef ASM_SPEC
-#define ASM_SPEC "%{fpic|fPIC:-k}"
+#define ASM_SPEC "%{" FPIC_SPEC ":-k}"
 
 #undef LINK_SPEC
 #define LINK_SPEC \
index f08c17f1bc2fe83aebdb26d5ba6878ce8ee93504..a9a76d695c53eee5f988e9e0421c5883fac26c44 100755 (executable)
@@ -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
@@ -938,6 +941,7 @@ enable_host_shared
 enable_libquadmath_support
 with_linker_hash_style
 with_diagnostics_color
+enable_default_pie
 '
       ac_precious_vars='build_alias
 host_alias
@@ -1674,6 +1678,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]
@@ -18293,7 +18298,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 18296 "configure"
+#line 18301 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -18399,7 +18404,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 18402 "configure"
+#line 18407 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -28702,6 +28707,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.
+# 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_cxx_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_cxx_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)
 
index c76d06d9f82f72a8534684cec989cb871558b18f..83f9c0951dc116f00d6a988db823f55022ceefef 100644 (file)
@@ -5819,6 +5819,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.
+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)
 
index 53d66823977f5ce6e2fca80d03a298d6a4984140..b89f409baa1fe877ef4c49dff6a9733742e47c5f 100644 (file)
@@ -1241,6 +1241,18 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #endif
 #endif
 
+/* Default value for flag_pie when flag_pie is initialized to -1:
+   --enable-default-pie: Default flag_pie to -fPIE.
+   --disable-default-pie: Default flag_pie to 0.
+ */
+#ifdef ENABLE_DEFAULT_PIE
+# ifndef DEFAULT_FLAG_PIE
+#  define DEFAULT_FLAG_PIE 2
+# endif
+#else
+# define DEFAULT_FLAG_PIE 0
+#endif
+
 #ifdef GCC_INSN_FLAGS_H
 /* Dependent default target macro definitions
 
index 04332c1ae376182595a891f8e3a72d5f0a4e6ecb..24c4a33828280ab9b60cba10fe71ce31e273f101 100644 (file)
@@ -1621,6 +1621,9 @@ defaulted to o32.
 Currently, this option only affects sparc-linux, powerpc-linux, x86-linux,
 mips-linux and s390-linux.
 
+@item --enable-default-pie
+Turn on @option{-fPIE} and @option{-pie} by default.
+
 @item --enable-secureplt
 This option enables @option{-msecure-plt} by default for powerpc-linux.
 @ifnothtml
index a4515376c00e3b96b9b7c123fd0e10f4dbd7f1ff..e25bd6220369a1a3dfe94e139c04d545efcd336c 100644 (file)
@@ -11302,6 +11302,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
index 8f01e4202b04dc797d81257ecaada1d3bcbee4d0..a8e9c8c236226f4897885a22cb80ef9f4042df30 100644 (file)
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -737,12 +737,57 @@ 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:;"
+#define NO_FPIE1_SPEC          "fno-pie"
+#define FPIE1_SPEC             NO_FPIE1_SPEC ":;"
+#define NO_FPIE2_SPEC          "fno-PIE"
+#define FPIE2_SPEC             NO_FPIE2_SPEC ":;"
+#define NO_FPIE_SPEC           NO_FPIE1_SPEC "|" NO_FPIE2_SPEC
+#define FPIE_SPEC              NO_FPIE_SPEC ":;"
+#define NO_FPIC1_SPEC          "fno-pic"
+#define FPIC1_SPEC             NO_FPIC1_SPEC ":;"
+#define NO_FPIC2_SPEC          "fno-PIC"
+#define FPIC2_SPEC             NO_FPIC2_SPEC ":;"
+#define NO_FPIC_SPEC           NO_FPIC1_SPEC "|" NO_FPIC2_SPEC
+#define FPIC_SPEC              NO_FPIC_SPEC ":;"
+#define NO_FPIE1_AND_FPIC1_SPEC        NO_FPIE1_SPEC "|" NO_FPIC1_SPEC
+#define FPIE1_OR_FPIC1_SPEC    NO_FPIE1_AND_FPIC1_SPEC ":;"
+#define NO_FPIE2_AND_FPIC2_SPEC        NO_FPIE2_SPEC "|" NO_FPIC2_SPEC
+#define FPIE2_OR_FPIC2_SPEC    NO_FPIE2_AND_FPIC2_SPEC ":;"
+#define NO_FPIE_AND_FPIC_SPEC  NO_FPIE_SPEC "|" NO_FPIC_SPEC
+#define FPIE_OR_FPIC_SPEC      NO_FPIE_AND_FPIC_SPEC ":;"
+#else
+#define PIE_SPEC               "pie"
+#define NO_PIE_SPEC            PIE_SPEC "|r|shared:;"
+#define FPIE1_SPEC             "fpie"
+#define NO_FPIE1_SPEC          FPIE1_SPEC ":;"
+#define FPIE2_SPEC             "fPIE"
+#define NO_FPIE2_SPEC          FPIE2_SPEC ":;"
+#define FPIE_SPEC              FPIE1_SPEC "|" FPIE2_SPEC
+#define NO_FPIE_SPEC           FPIE_SPEC ":;"
+#define FPIC1_SPEC             "fpic"
+#define NO_FPIC1_SPEC          FPIC1_SPEC ":;"
+#define FPIC2_SPEC             "fPIC"
+#define NO_FPIC2_SPEC          FPIC2_SPEC ":;"
+#define FPIC_SPEC              FPIC1_SPEC "|" FPIC2_SPEC
+#define NO_FPIC_SPEC           FPIC_SPEC ":;"
+#define FPIE1_OR_FPIC1_SPEC    FPIE1_SPEC "|" FPIC1_SPEC
+#define NO_FPIE1_AND_FPIC1_SPEC        FPIE1_OR_FPIC1_SPEC ":;"
+#define FPIE2_OR_FPIC2_SPEC    FPIE2_SPEC "|" FPIC2_SPEC
+#define NO_FPIE2_AND_FPIC2_SPEC        FPIE1_OR_FPIC2_SPEC ":;"
+#define FPIE_OR_FPIC_SPEC      FPIE_SPEC "|" FPIC_SPEC
+#define NO_FPIE_AND_FPIC_SPEC  FPIE_OR_FPIC_SPEC ":;"
+#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
index 9deb8df6bc9bd11a33aad5a73c551b511df2555e..9793999016eceace2305200ede42a404ea3a6ce7 100644 (file)
@@ -741,6 +741,15 @@ finish_options (struct gcc_options *opts, struct gcc_options *opts_set,
 
   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)
index fb4d2bad8f0f2e4c850983d5ed2ba570388e17d3..b4fc479d7540c4057c2a679e8ced987a40f39f1e 100644 (file)
@@ -1,3 +1,7 @@
+2015-05-27  H.J. Lu  <hongjiu.lu@intel.com>
+
+       * Makefile.in (CRTSTUFF_CFLAGS): Add $(NO_PIE_CFLAGS).
+
 2015-05-27  John Marino <gnugcc@marino.st>
 
        * config.host (i[34567]86-*-freebsd*, x86_64-*-freebsd*): Set
index 1f2b80695122776752febd8b3dc413080f643c23..527d87b03104d4b642303a61a5bf479f99cc9c48 100644 (file)
@@ -285,7 +285,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)