summaryrefslogtreecommitdiff
path: root/gcc/configure.ac
diff options
context:
space:
mode:
authorhjl <hjl@138bc75d-0d04-0410-961f-82ee72b054a4>2015-05-28 02:36:55 +0000
committerhjl <hjl@138bc75d-0d04-0410-961f-82ee72b054a4>2015-05-28 02:36:55 +0000
commite9abca4f4a48fa8b1fd9778f6a3cd748e099e3bb (patch)
treec1842de03eb800c3a5a10555b12a3407e50560ba /gcc/configure.ac
parent734ac1224eec2d90f100d0384add954a549b0cdb (diff)
downloadgcc-e9abca4f4a48fa8b1fd9778f6a3cd748e099e3bb.tar.gz
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). git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@223796 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/configure.ac')
-rw-r--r--gcc/configure.ac40
1 files changed, 40 insertions, 0 deletions
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 <<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)