From: H.J. Lu Date: Thu, 28 May 2015 02:36:55 +0000 (-0700) Subject: Add --enable-default-pie option to GCC configure X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=428b381275bc95032274440f02d7719225de2c17;p=gcc.git Add --enable-default-pie option to GCC configure 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 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 74be3c707e9..29c26c40661 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,95 @@ +2015-05-27 Magnus Granberg + H.J. Lu + + * 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 PR rtl-optimization/66168 diff --git a/gcc/Makefile.in b/gcc/Makefile.in index 03c2ac6a62e..b59b5d9e6e9 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -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 diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index 073172eac97..aa4aa18a014 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,7 @@ +2015-05-27 H.J. Lu + + * gcc-interface/Makefile.in (TOOLS_LIBS): Add @NO_PIE_FLAG@. + 2015-05-27 Eric Botcazou * gcc-interface/trans.c (elaborate_all_entities): Do not elaborate an diff --git a/gcc/ada/gcc-interface/Makefile.in b/gcc/ada/gcc-interface/Makefile.in index ecc443e1066..90aedb575d7 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 562d34a05ae..6e15af2e189 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -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 diff --git a/gcc/config.in b/gcc/config.in index 231c9abe712..daaf9067e4f 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/arm/freebsd.h b/gcc/config/arm/freebsd.h index 040d7c13b0d..2febf4b6091 100644 --- a/gcc/config/arm/freebsd.h +++ b/gcc/config/arm/freebsd.h @@ -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 diff --git a/gcc/config/arm/netbsd-elf.h b/gcc/config/arm/netbsd-elf.h index ee085a60597..65460979410 100644 --- a/gcc/config/arm/netbsd-elf.h +++ b/gcc/config/arm/netbsd-elf.h @@ -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 diff --git a/gcc/config/arm/semi.h b/gcc/config/arm/semi.h index 18a4443fdcc..1c938d39197 100644 --- a/gcc/config/arm/semi.h +++ b/gcc/config/arm/semi.h @@ -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} \ diff --git a/gcc/config/c6x/elf-common.h b/gcc/config/c6x/elf-common.h index 844172dd88d..2a7cd524534 100644 --- a/gcc/config/c6x/elf-common.h +++ b/gcc/config/c6x/elf-common.h @@ -24,8 +24,10 @@ #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\"" diff --git a/gcc/config/c6x/uclinux-elf.h b/gcc/config/c6x/uclinux-elf.h index 5048b71df0e..5a04b9dc5d2 100644 --- a/gcc/config/c6x/uclinux-elf.h +++ b/gcc/config/c6x/uclinux-elf.h @@ -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 "}} \ diff --git a/gcc/config/cris/linux.h b/gcc/config/cris/linux.h index bd579867a50..262aac5c16c 100644 --- a/gcc/config/cris/linux.h +++ b/gcc/config/cris/linux.h @@ -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. */ diff --git a/gcc/config/darwin.h b/gcc/config/darwin.h index 66f504ed351..9a31952ce4e 100644 --- a/gcc/config/darwin.h +++ b/gcc/config/darwin.h @@ -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*} \ diff --git a/gcc/config/darwin9.h b/gcc/config/darwin9.h index 4204825708e..309c835b6ee 100644 --- a/gcc/config/darwin9.h +++ b/gcc/config/darwin9.h @@ -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}}" diff --git a/gcc/config/frv/frv.h b/gcc/config/frv/frv.h index 978fefa2657..2d4cbddeb74 100644 --- a/gcc/config/frv/frv.h +++ b/gcc/config/frv/frv.h @@ -42,12 +42,12 @@ "%{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" diff --git a/gcc/config/gnu-user.h b/gcc/config/gnu-user.h index 2faa2e5e85a..2fcb55dbdab 100644 --- a/gcc/config/gnu-user.h +++ b/gcc/config/gnu-user.h @@ -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}" diff --git a/gcc/config/m32r/m32r.h b/gcc/config/m32r/m32r.h index 66ceae0c181..2163de41349 100644 --- a/gcc/config/m32r/m32r.h +++ b/gcc/config/m32r/m32r.h @@ -159,7 +159,7 @@ /* 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)" diff --git a/gcc/config/m68k/m68k.h b/gcc/config/m68k/m68k.h index 88356ccac1f..74ebff7fab4 100644 --- a/gcc/config/m68k/m68k.h +++ b/gcc/config/m68k/m68k.h @@ -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} \ " diff --git a/gcc/config/m68k/netbsd-elf.h b/gcc/config/m68k/netbsd-elf.h index 3922d255b44..a180667bf3d 100644 --- a/gcc/config/m68k/netbsd-elf.h +++ b/gcc/config/m68k/netbsd-elf.h @@ -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. */ diff --git a/gcc/config/m68k/openbsd.h b/gcc/config/m68k/openbsd.h index 34ea77f3886..379ca85f567 100644 --- a/gcc/config/m68k/openbsd.h +++ b/gcc/config/m68k/openbsd.h @@ -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. */ diff --git a/gcc/config/m68k/uclinux.h b/gcc/config/m68k/uclinux.h index a6c3f7fa61d..ef6a3a0f504 100644 --- a/gcc/config/m68k/uclinux.h +++ b/gcc/config/m68k/uclinux.h @@ -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 diff --git a/gcc/config/mips/gnu-user.h b/gcc/config/mips/gnu-user.h index 28b00ed20a5..dd4cf11377e 100644 --- a/gcc/config/mips/gnu-user.h +++ b/gcc/config/mips/gnu-user.h @@ -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 diff --git a/gcc/config/mips/vxworks.h b/gcc/config/mips/vxworks.h index 96512a20056..0fa40b0d7d6 100644 --- a/gcc/config/mips/vxworks.h +++ b/gcc/config/mips/vxworks.h @@ -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 diff --git a/gcc/config/openbsd.h b/gcc/config/openbsd.h index 5890078dd41..cf6654898eb 100644 --- a/gcc/config/openbsd.h +++ b/gcc/config/openbsd.h @@ -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. */ diff --git a/gcc/config/rs6000/freebsd64.h b/gcc/config/rs6000/freebsd64.h index 84066f60e14..7e630231bc7 100644 --- a/gcc/config/rs6000/freebsd64.h +++ b/gcc/config/rs6000/freebsd64.h @@ -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} \ diff --git a/gcc/config/rs6000/linux64.h b/gcc/config/rs6000/linux64.h index 1b7f695bc60..bec0fd9c842 100644 --- a/gcc/config/rs6000/linux64.h +++ b/gcc/config/rs6000/linux64.h @@ -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" diff --git a/gcc/config/rs6000/sysv4.h b/gcc/config/rs6000/sysv4.h index 41ed4eff066..24618e309f1 100644 --- a/gcc/config/rs6000/sysv4.h +++ b/gcc/config/rs6000/sysv4.h @@ -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) diff --git a/gcc/config/rs6000/vxworks.h b/gcc/config/rs6000/vxworks.h index b4f88debb96..744017204ab 100644 --- a/gcc/config/rs6000/vxworks.h +++ b/gcc/config/rs6000/vxworks.h @@ -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 diff --git a/gcc/config/sol2.h b/gcc/config/sol2.h index 4dceb16d4c7..adf6f3b9fbe 100644 --- a/gcc/config/sol2.h +++ b/gcc/config/sol2.h @@ -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 \ diff --git a/gcc/config/sparc/freebsd.h b/gcc/config/sparc/freebsd.h index fa40d4e1617..f469bf1d89c 100644 --- a/gcc/config/sparc/freebsd.h +++ b/gcc/config/sparc/freebsd.h @@ -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}} \ diff --git a/gcc/config/sparc/linux.h b/gcc/config/sparc/linux.h index 56def4bcd47..17e1e862b68 100644 --- a/gcc/config/sparc/linux.h +++ b/gcc/config/sparc/linux.h @@ -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)" diff --git a/gcc/config/sparc/linux64.h b/gcc/config/sparc/linux64.h index fa805fd4432..43da8480f24 100644 --- a/gcc/config/sparc/linux64.h +++ b/gcc/config/sparc/linux64.h @@ -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)" diff --git a/gcc/config/sparc/netbsd-elf.h b/gcc/config/sparc/netbsd-elf.h index 165660ce532..6f99ed4853c 100644 --- a/gcc/config/sparc/netbsd-elf.h +++ b/gcc/config/sparc/netbsd-elf.h @@ -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 diff --git a/gcc/config/sparc/openbsd64.h b/gcc/config/sparc/openbsd64.h index a84d2106e63..b62f9c3e65c 100644 --- a/gcc/config/sparc/openbsd64.h +++ b/gcc/config/sparc/openbsd64.h @@ -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) \ " diff --git a/gcc/config/sparc/sp-elf.h b/gcc/config/sparc/sp-elf.h index 85da652a99d..371bb6a767d 100644 --- a/gcc/config/sparc/sp-elf.h +++ b/gcc/config/sparc/sp-elf.h @@ -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 diff --git a/gcc/config/sparc/sp64-elf.h b/gcc/config/sparc/sp64-elf.h index 2fbdfd0872f..43adbb50839 100644 --- a/gcc/config/sparc/sp64-elf.h +++ b/gcc/config/sparc/sp64-elf.h @@ -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) \ " diff --git a/gcc/config/sparc/sparc.h b/gcc/config/sparc/sparc.h index ce1b68b1b44..106d993ee35 100644 --- a/gcc/config/sparc/sparc.h +++ b/gcc/config/sparc/sparc.h @@ -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 diff --git a/gcc/config/sparc/sysv4.h b/gcc/config/sparc/sysv4.h index ff886b1d195..0b358bbe186 100644 --- a/gcc/config/sparc/sysv4.h +++ b/gcc/config/sparc/sysv4.h @@ -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 diff --git a/gcc/config/sparc/vxworks.h b/gcc/config/sparc/vxworks.h index c66dba8f5a4..e356b25d429 100644 --- a/gcc/config/sparc/vxworks.h +++ b/gcc/config/sparc/vxworks.h @@ -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 diff --git a/gcc/config/vax/linux.h b/gcc/config/vax/linux.h index dfcad5be7ba..0765ed99ecb 100644 --- a/gcc/config/vax/linux.h +++ b/gcc/config/vax/linux.h @@ -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 \ diff --git a/gcc/configure b/gcc/configure index f08c17f1bc2..a9a76d695c5 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 @@ -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 <>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) diff --git a/gcc/configure.ac b/gcc/configure.ac index c76d06d9f82..83f9c0951dc 100644 --- a/gcc/configure.ac +++ b/gcc/configure.ac @@ -5819,6 +5819,46 @@ cat > gcc-driver-name.h <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/ChangeLog b/libgcc/ChangeLog index fb4d2bad8f0..b4fc479d754 100644 --- a/libgcc/ChangeLog +++ b/libgcc/ChangeLog @@ -1,3 +1,7 @@ +2015-05-27 H.J. Lu + + * Makefile.in (CRTSTUFF_CFLAGS): Add $(NO_PIE_CFLAGS). + 2015-05-27 John Marino * config.host (i[34567]86-*-freebsd*, x86_64-*-freebsd*): Set diff --git a/libgcc/Makefile.in b/libgcc/Makefile.in index 1f2b8069512..527d87b0310 100644 --- a/libgcc/Makefile.in +++ b/libgcc/Makefile.in @@ -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)