* PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option @ 2015-03-06 17:31 H.J. Lu 2015-03-06 20:22 ` Magnus Granberg 2015-05-07 21:17 ` Joseph Myers 0 siblings, 2 replies; 52+ messages in thread From: H.J. Lu @ 2015-03-06 17:31 UTC (permalink / raw) To: Joseph Myers; +Cc: Richard Biener, Magnus Granberg, GCC Patches, danielmicay [-- Attachment #1: Type: text/plain, Size: 4813 bytes --] PING. I am enclosing the patch here for review. On Wed, Feb 11, 2015 at 8:47 AM, H.J. Lu <hjl.tools@gmail.com> wrote: > PING. > > On Wed, Jan 28, 2015 at 8:05 AM, H.J. Lu <hjl.tools@gmail.com> wrote: >> PING. >> >> On Tue, Jan 13, 2015 at 3:25 PM, H.J. Lu <hjl.tools@gmail.com> wrote: >>> 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. >> >> >> >> -- >> H.J. > > > > -- > H.J. -- H.J. [-- Attachment #2: 0001-Add-enable-default-pie-option-to-GCC-configure.patch --] [-- Type: text/x-patch, Size: 15742 bytes --] From 46faeb11166103c6a8b1608731eccf75385fe5c9 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" <hjl.tools@gmail.com> Date: Fri, 6 Mar 2015 09:07:54 -0800 Subject: [PATCH] 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@. (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/ * gcc-interface/Makefile.in (TOOLS_LIBS): Add @NO_PIE_FLAG@. libgcc/ * Makefile.in (CRTSTUFF_CFLAGS): Add $(NO_PIE_CFLAGS). --- gcc/Makefile.in | 12 ++++++ gcc/ada/gcc-interface/Makefile.in | 3 ++ gcc/common.opt | 10 +++-- gcc/config.in | 6 +++ gcc/config/gnu-user.h | 26 +++++++++---- gcc/configure | 79 ++++++++++++++++++++++++++++++++++++++- gcc/configure.ac | 40 ++++++++++++++++++++ gcc/defaults.h | 6 +++ gcc/doc/install.texi | 3 ++ gcc/doc/invoke.texi | 4 ++ gcc/gcc.c | 12 +++++- gcc/opts.c | 14 +++++++ libgcc/Makefile.in | 2 +- 13 files changed, 201 insertions(+), 16 deletions(-) diff --git a/gcc/Makefile.in b/gcc/Makefile.in index de1f3b6..46c3ed3 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 60c1b5b..e09b921 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 b49ac46..51f17c0 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -1765,7 +1765,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 @@ -1773,7 +1773,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= @@ -2846,8 +2846,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 7bde5b1..b708f3a 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 1a35d5a..b419791 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. +# 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 a553a65..dfd1537 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. +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 1d54798..f0acadc 100644 --- a/gcc/defaults.h +++ b/gcc/defaults.h @@ -1186,6 +1186,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 b8bb4bd..761e929 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 006a852..7fcc8d1 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -11029,6 +11029,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 8a163a1..233a3db 100644 --- a/gcc/gcc.c +++ b/gcc/gcc.c @@ -737,12 +737,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 39c190d..748238e 100644 --- a/gcc/opts.c +++ b/gcc/opts.c @@ -739,8 +739,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 88ddfea..4fa0f78 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) -- 1.9.3 ^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option 2015-03-06 17:31 PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option H.J. Lu @ 2015-03-06 20:22 ` Magnus Granberg 2015-03-06 20:25 ` H.J. Lu 2015-05-07 21:17 ` Joseph Myers 1 sibling, 1 reply; 52+ messages in thread From: Magnus Granberg @ 2015-03-06 20:22 UTC (permalink / raw) To: gcc-patches fredag 06 mars 2015 09.31.26 skrev H.J. Lu: > PING. I am enclosing the patch here for review. > Have you tested it on mips? gcc pass -mno-shared if HAVE_AS_NO_SHARED is defened in config/mips/gnu-user.h. -mshared don't get enable. /Magnus G. ^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option 2015-03-06 20:22 ` Magnus Granberg @ 2015-03-06 20:25 ` H.J. Lu 0 siblings, 0 replies; 52+ messages in thread From: H.J. Lu @ 2015-03-06 20:25 UTC (permalink / raw) To: Magnus Granberg; +Cc: GCC Patches On Fri, Mar 6, 2015 at 12:11 PM, Magnus Granberg <zorry@gentoo.org> wrote: > fredag 06 mars 2015 09.31.26 skrev H.J. Lu: >> PING. I am enclosing the patch here for review. >> > Have you tested it on mips? > gcc pass -mno-shared if HAVE_AS_NO_SHARED is defened > in config/mips/gnu-user.h. -mshared don't get enable. > I am not familiar with mips. MIPS maintainer needs to look into it. -- H.J. ^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option 2015-03-06 17:31 PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option H.J. Lu 2015-03-06 20:22 ` Magnus Granberg @ 2015-05-07 21:17 ` Joseph Myers 2015-05-08 17:35 ` H.J. Lu 1 sibling, 1 reply; 52+ messages in thread From: Joseph Myers @ 2015-05-07 21:17 UTC (permalink / raw) To: H.J. Lu; +Cc: Richard Biener, Magnus Granberg, GCC Patches, danielmicay On Fri, 6 Mar 2015, H.J. Lu wrote: > +# 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@ As I understand it, what we don't want is the compiler to be a PIE. That is, it must be linked -no-pie (and given that the compiler is not a PIE, compiling -fPIE would be pointless, although it wouldn't actually break things to have PIE objects in the compiler as long as it's linked for a fixed address). > +#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 With appropriate definitions of PIE_SPEC and NO_PIE_SPEC, shouldn't a single definition of GNU_USER_TARGET_STARTFILE_SPEC be able to work for both ENABLE_DEFAULT_PIE and !ENABLE_DEFAULT_PIE? <https://gcc.gnu.org/ml/gcc-patches/2015-03/msg00393.html> noted a possible issue with MIPS. Actually, rather more config/*.h and config/*/*.h headers contain specs testing for (-fpie, -fPIE, -fno-pie, -fno-PIE, -pie) options, which would be affected by these changes. I'd say this patch should include an initial attempt at adjusting those config headers, which should be an essentially mechanical change not requiring understanding anything target-specific. For link-time specs, that may mean using PIE_SPEC and NO_PIE_SPEC. For compile-time specs, similar new macros would be added. Given such adjustments included in the patch and the relevant target maintainers CC:ed, I might then be inclined to approve the patch on the basis of allowing a week for target maintainers to test the changes for their targets before commit, as I don't see any major problems with it beyond the need to update the target-specific specs. -- Joseph S. Myers joseph@codesourcery.com ^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option 2015-05-07 21:17 ` Joseph Myers @ 2015-05-08 17:35 ` H.J. Lu 2015-05-18 22:53 ` Magnus Granberg 2015-05-26 23:09 ` Matthew Fortune 0 siblings, 2 replies; 52+ messages in thread From: H.J. Lu @ 2015-05-08 17:35 UTC (permalink / raw) To: Joseph Myers; +Cc: Richard Biener, Magnus Granberg, GCC Patches, danielmicay [-- Attachment #1: Type: text/plain, Size: 4305 bytes --] On Thu, May 7, 2015 at 2:17 PM, Joseph Myers <joseph@codesourcery.com> wrote: > On Fri, 6 Mar 2015, H.J. Lu wrote: > >> +# 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@ > > As I understand it, what we don't want is the compiler to be a PIE. That > is, it must be linked -no-pie (and given that the compiler is not a PIE, > compiling -fPIE would be pointless, although it wouldn't actually break > things to have PIE objects in the compiler as long as it's linked for a > fixed address). > >> +#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 > > With appropriate definitions of PIE_SPEC and NO_PIE_SPEC, shouldn't a > single definition of GNU_USER_TARGET_STARTFILE_SPEC be able to work for > both ENABLE_DEFAULT_PIE and !ENABLE_DEFAULT_PIE? Yes. > <https://gcc.gnu.org/ml/gcc-patches/2015-03/msg00393.html> noted a > possible issue with MIPS. Actually, rather more config/*.h and > config/*/*.h headers contain specs testing for (-fpie, -fPIE, -fno-pie, > -fno-PIE, -pie) options, which would be affected by these changes. I'd > say this patch should include an initial attempt at adjusting those config > headers, which should be an essentially mechanical change not requiring > understanding anything target-specific. For link-time specs, that may > mean using PIE_SPEC and NO_PIE_SPEC. For compile-time specs, similar new > macros would be added. Given such adjustments included in the patch and > the relevant target maintainers CC:ed, I might then be inclined to approve > the patch on the basis of allowing a week for target maintainers to test > the changes for their targets before commit, as I don't see any major > problems with it beyond the need to update the target-specific specs. > Here is the updated patch. I will post patches for cris, mips, powerpc and sparc separately. The target maintainers should be able to adjust backend ASM_SPEC with FPIE_OR_FPIC_SPEC and NO_FPIE_AND_FPIC_SPEC. OK for trunk? Thanks. -- H.J. --- Add --enable-default-pie option to configure GCC to generate PIE by default. gcc/ 2015-03-06 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_FPIE_SPEC): Likewise. (FPIE_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 (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 (GNU_USER_TARGET_STARTFILE_SPEC): Use PIE_SPEC and NO_PIE_SPEC if HAVE_LD_PIE is defined. * doc/install.texi: Document --enable-default-pie. * doc/invoke.texi: Document -no-pie. * config.in: Regenerated. * configure: Likewise. gcc/ada/ 2015-03-06 H.J. Lu <hongjiu.lu@intel.com> * gcc-interface/Makefile.in (TOOLS_LIBS): Add @NO_PIE_FLAG@. libgcc/ 2015-03-06 H.J. Lu <hongjiu.lu@intel.com> * Makefile.in (CRTSTUFF_CFLAGS): Add $(NO_PIE_CFLAGS). [-- Attachment #2: 0001-Add-enable-default-pie-option-to-GCC-configure.patch --] [-- Type: text/x-patch, Size: 16135 bytes --] From 57e2d527af4891a4bf05b57b01d9ac97d336e959 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" <hjl.tools@gmail.com> Date: Fri, 6 Mar 2015 09:07:54 -0800 Subject: [PATCH 1/5] Add --enable-default-pie option to GCC configure Add --enable-default-pie option to configure GCC to generate PIE by default. gcc/ 2015-03-06 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_FPIE_SPEC): Likewise. (FPIE_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 (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 (GNU_USER_TARGET_STARTFILE_SPEC): Use PIE_SPEC and NO_PIE_SPEC if HAVE_LD_PIE is defined. * doc/install.texi: Document --enable-default-pie. * doc/invoke.texi: Document -no-pie. * config.in: Regenerated. * configure: Likewise. gcc/ada/ 2015-03-06 H.J. Lu <hongjiu.lu@intel.com> * gcc-interface/Makefile.in (TOOLS_LIBS): Add @NO_PIE_FLAG@. libgcc/ 2015-03-06 H.J. Lu <hongjiu.lu@intel.com> * Makefile.in (CRTSTUFF_CFLAGS): Add $(NO_PIE_CFLAGS). --- gcc/Makefile.in | 15 ++++++++ gcc/ada/gcc-interface/Makefile.in | 3 ++ gcc/common.opt | 10 +++-- gcc/config.in | 6 +++ gcc/config/gnu-user.h | 7 +++- gcc/configure | 79 ++++++++++++++++++++++++++++++++++++++- gcc/configure.ac | 40 ++++++++++++++++++++ gcc/defaults.h | 5 +++ gcc/doc/install.texi | 3 ++ gcc/doc/invoke.texi | 4 ++ gcc/gcc.c | 21 ++++++++++- gcc/opts.c | 14 +++++++ libgcc/Makefile.in | 2 +- 13 files changed, 199 insertions(+), 10 deletions(-) diff --git a/gcc/Makefile.in b/gcc/Makefile.in index 652b3e71d..26faa2b 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) @@ -749,6 +755,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) @@ -760,6 +768,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) @@ -1863,6 +1872,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 ecc443e..90aedb5 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 51833c1..5b1735f8 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -1770,7 +1770,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 @@ -1778,7 +1778,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= @@ -2851,8 +2851,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 231c9ab..daaf906 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..2fcb55d 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/configure b/gcc/configure index b99eb6d..3a03dce 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] @@ -18162,7 +18167,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 18165 "configure" +#line 18170 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -18268,7 +18273,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 18271 "configure" +#line 18276 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -28571,6 +28576,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_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 810725c..73de1ad 100644 --- a/gcc/configure.ac +++ b/gcc/configure.ac @@ -5826,6 +5826,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) diff --git a/gcc/defaults.h b/gcc/defaults.h index 47fdcf4..a7da1a3 100644 --- a/gcc/defaults.h +++ b/gcc/defaults.h @@ -1229,6 +1229,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #define ARGS_GROW_DOWNWARD 0 #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 d8d3939..36502ee 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 9169731..ac34539 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -11251,6 +11251,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 d956c36..4ba3229 100644 --- a/gcc/gcc.c +++ b/gcc/gcc.c @@ -737,12 +737,29 @@ 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_FPIE_SPEC "fno-pie|fno-PIE" +#define FPIE_SPEC NO_FPIE_SPEC ":;" +#define NO_FPIE_AND_FPIC_SPEC NO_FPIE_SPEC "|fno-pic|fno-PIC" +#define FPIE_OR_FPIC_SPEC NO_FPIE_AND_FPIC_SPEC ":;" +#else +#define PIE_SPEC "pie" +#define NO_PIE_SPEC PIE_SPEC "|r|shared:;" +#define FPIE_SPEC "fpie|fPIE" +#define NO_FPIE_SPEC FPIE_SPEC ":;" +#define FPIE_OR_FPIC_SPEC FPIE_SPEC "|fpic|fPIC" +#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 diff --git a/gcc/opts.c b/gcc/opts.c index cf92334..c10126a 100644 --- a/gcc/opts.c +++ b/gcc/opts.c @@ -739,8 +739,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 1ab188d..b8fc1d8 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) -- 1.9.3 ^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option 2015-05-08 17:35 ` H.J. Lu @ 2015-05-18 22:53 ` Magnus Granberg 2015-05-19 1:25 ` Joseph Myers 2015-05-26 23:09 ` Matthew Fortune 1 sibling, 1 reply; 52+ messages in thread From: Magnus Granberg @ 2015-05-18 22:53 UTC (permalink / raw) To: gcc-patches fredag 08 maj 2015 10.35.44 skrev H.J. Lu: > On Thu, May 7, 2015 at 2:17 PM, Joseph Myers <joseph@codesourcery.com> wrote: > > On Fri, 6 Mar 2015, H.J. Lu wrote: > >> +# 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@ > > > > As I understand it, what we don't want is the compiler to be a PIE. That > > is, it must be linked -no-pie (and given that the compiler is not a PIE, > > compiling -fPIE would be pointless, although it wouldn't actually break > > things to have PIE objects in the compiler as long as it's linked for a > > fixed address). > > > >> +#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 > > > > With appropriate definitions of PIE_SPEC and NO_PIE_SPEC, shouldn't a > > single definition of GNU_USER_TARGET_STARTFILE_SPEC be able to work for > > both ENABLE_DEFAULT_PIE and !ENABLE_DEFAULT_PIE? > > Yes. > > > <https://gcc.gnu.org/ml/gcc-patches/2015-03/msg00393.html> noted a > > possible issue with MIPS. Actually, rather more config/*.h and > > config/*/*.h headers contain specs testing for (-fpie, -fPIE, -fno-pie, > > -fno-PIE, -pie) options, which would be affected by these changes. I'd > > say this patch should include an initial attempt at adjusting those config > > headers, which should be an essentially mechanical change not requiring > > understanding anything target-specific. For link-time specs, that may > > mean using PIE_SPEC and NO_PIE_SPEC. For compile-time specs, similar new > > macros would be added. Given such adjustments included in the patch and > > the relevant target maintainers CC:ed, I might then be inclined to approve > > the patch on the basis of allowing a week for target maintainers to test > > the changes for their targets before commit, as I don't see any major > > problems with it beyond the need to update the target-specific specs. > > Here is the updated patch. I will post patches for cris, mips, powerpc > and sparc separately. The target maintainers should be able to adjust > backend ASM_SPEC with FPIE_OR_FPIC_SPEC and > NO_FPIE_AND_FPIC_SPEC. > > OK for trunk? > > Thanks. PIng Any progress on this? /Magnus G. ^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option 2015-05-18 22:53 ` Magnus Granberg @ 2015-05-19 1:25 ` Joseph Myers 2015-05-19 1:34 ` H.J. Lu 0 siblings, 1 reply; 52+ messages in thread From: Joseph Myers @ 2015-05-19 1:25 UTC (permalink / raw) To: Magnus Granberg; +Cc: gcc-patches On Tue, 19 May 2015, Magnus Granberg wrote: > > > <https://gcc.gnu.org/ml/gcc-patches/2015-03/msg00393.html> noted a > > > possible issue with MIPS. Actually, rather more config/*.h and > > > config/*/*.h headers contain specs testing for (-fpie, -fPIE, -fno-pie, > > > -fno-PIE, -pie) options, which would be affected by these changes. I'd > > > say this patch should include an initial attempt at adjusting those config > > > headers, which should be an essentially mechanical change not requiring > > > understanding anything target-specific. For link-time specs, that may > > > mean using PIE_SPEC and NO_PIE_SPEC. For compile-time specs, similar new > > > macros would be added. Given such adjustments included in the patch and > > > the relevant target maintainers CC:ed, I might then be inclined to approve > > > the patch on the basis of allowing a week for target maintainers to test > > > the changes for their targets before commit, as I don't see any major > > > problems with it beyond the need to update the target-specific specs. > > > > Here is the updated patch. I will post patches for cris, mips, powerpc > > and sparc separately. The target maintainers should be able to adjust > > backend ASM_SPEC with FPIE_OR_FPIC_SPEC and > > NO_FPIE_AND_FPIC_SPEC. > > > > OK for trunk? > > > > Thanks. > PIng > > Any progress on this? Have updates for all affected specs for all targets been posted? I just saw a small and apparently arbitrary subset of targets with patches, and no explanation of how those targets were identified or why the other targets with specs mentioning the options in question did not need updates. -- Joseph S. Myers joseph@codesourcery.com ^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option 2015-05-19 1:25 ` Joseph Myers @ 2015-05-19 1:34 ` H.J. Lu 2015-05-19 15:27 ` Joseph Myers 0 siblings, 1 reply; 52+ messages in thread From: H.J. Lu @ 2015-05-19 1:34 UTC (permalink / raw) To: Joseph Myers; +Cc: Magnus Granberg, GCC Patches On Mon, May 18, 2015 at 6:11 PM, Joseph Myers <joseph@codesourcery.com> wrote: > On Tue, 19 May 2015, Magnus Granberg wrote: > >> > > <https://gcc.gnu.org/ml/gcc-patches/2015-03/msg00393.html> noted a >> > > possible issue with MIPS. Actually, rather more config/*.h and >> > > config/*/*.h headers contain specs testing for (-fpie, -fPIE, -fno-pie, >> > > -fno-PIE, -pie) options, which would be affected by these changes. I'd >> > > say this patch should include an initial attempt at adjusting those config >> > > headers, which should be an essentially mechanical change not requiring >> > > understanding anything target-specific. For link-time specs, that may >> > > mean using PIE_SPEC and NO_PIE_SPEC. For compile-time specs, similar new >> > > macros would be added. Given such adjustments included in the patch and >> > > the relevant target maintainers CC:ed, I might then be inclined to approve >> > > the patch on the basis of allowing a week for target maintainers to test >> > > the changes for their targets before commit, as I don't see any major >> > > problems with it beyond the need to update the target-specific specs. >> > >> > Here is the updated patch. I will post patches for cris, mips, powerpc >> > and sparc separately. The target maintainers should be able to adjust >> > backend ASM_SPEC with FPIE_OR_FPIC_SPEC and >> > NO_FPIE_AND_FPIC_SPEC. >> > >> > OK for trunk? >> > >> > Thanks. >> PIng >> >> Any progress on this? > > Have updates for all affected specs for all targets been posted? I just > saw a small and apparently arbitrary subset of targets with patches, and > no explanation of how those targets were identified or why the other > targets with specs mentioning the options in question did not need > updates. > I only posted patches for an arbitrary subset of targets because 1. Not everyone is interested in --enable-default-pie. 2. I can't tests all targets myself. If patches for all targets is the only blocker before the patch will be approved or target maintainers will help me test the patch, I will post patches for each target affected. -- H.J. ^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option 2015-05-19 1:34 ` H.J. Lu @ 2015-05-19 15:27 ` Joseph Myers 2015-05-19 15:33 ` H.J. Lu 0 siblings, 1 reply; 52+ messages in thread From: Joseph Myers @ 2015-05-19 15:27 UTC (permalink / raw) To: H.J. Lu; +Cc: Magnus Granberg, GCC Patches On Mon, 18 May 2015, H.J. Lu wrote: > > Have updates for all affected specs for all targets been posted? I just > > saw a small and apparently arbitrary subset of targets with patches, and > > no explanation of how those targets were identified or why the other > > targets with specs mentioning the options in question did not need > > updates. > > > > I only posted patches for an arbitrary subset of targets because > > 1. Not everyone is interested in --enable-default-pie. > 2. I can't tests all targets myself. > > If patches for all targets is the only blocker before the patch > will be approved or target maintainers will help me test the patch, > I will post patches for each target affected. I think the whole thing should be posted as one patch, with both the target-independent changes and the target-specific changes for all targets. -- Joseph S. Myers joseph@codesourcery.com ^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option 2015-05-19 15:27 ` Joseph Myers @ 2015-05-19 15:33 ` H.J. Lu 2015-05-19 15:33 ` Paul_Koning 2015-05-19 15:37 ` Joseph Myers 0 siblings, 2 replies; 52+ messages in thread From: H.J. Lu @ 2015-05-19 15:33 UTC (permalink / raw) To: Joseph Myers; +Cc: Magnus Granberg, GCC Patches On Tue, May 19, 2015 at 8:21 AM, Joseph Myers <joseph@codesourcery.com> wrote: > On Mon, 18 May 2015, H.J. Lu wrote: > >> > Have updates for all affected specs for all targets been posted? I just >> > saw a small and apparently arbitrary subset of targets with patches, and >> > no explanation of how those targets were identified or why the other >> > targets with specs mentioning the options in question did not need >> > updates. >> > >> >> I only posted patches for an arbitrary subset of targets because >> >> 1. Not everyone is interested in --enable-default-pie. >> 2. I can't tests all targets myself. >> >> If patches for all targets is the only blocker before the patch >> will be approved or target maintainers will help me test the patch, >> I will post patches for each target affected. > > I think the whole thing should be posted as one patch, with both the > target-independent changes and the target-specific changes for all > targets. > That is what makes me concerned. I have some simple target-specified patches which weren't reviewed for years. What will happen if no one reviews some simple target-specified changes due to 1. Reviewers don't have access to those targets. 2. Target maintainers aren't review them. 3. There are no clear maintainers for those targets. As the result, my patch may go nowhere. -- H.J. ^ permalink raw reply [flat|nested] 52+ messages in thread
* RE: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option 2015-05-19 15:33 ` H.J. Lu @ 2015-05-19 15:33 ` Paul_Koning 2015-05-19 15:43 ` H.J. Lu 2015-05-19 15:37 ` Joseph Myers 1 sibling, 1 reply; 52+ messages in thread From: Paul_Koning @ 2015-05-19 15:33 UTC (permalink / raw) To: hjl.tools, joseph; +Cc: zorry, gcc-patches ________________________________________ From: gcc-patches-owner@gcc.gnu.org [gcc-patches-owner@gcc.gnu.org] on behalf of H.J. Lu [hjl.tools@gmail.com] Sent: Tuesday, May 19, 2015 11:27 AM To: Joseph Myers Cc: Magnus Granberg; GCC Patches Subject: Re: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option On Tue, May 19, 2015 at 8:21 AM, Joseph Myers <joseph@codesourcery.com> wrote: > ... > I think the whole thing should be posted as one patch, with both the > target-independent changes and the target-specific changes for all > targets. > That is what makes me concerned. I have some simple target-specified patches which weren't reviewed for years. What will happen if no one reviews some simple target-specified changes due to 1. Reviewers don't have access to those targets. 2. Target maintainers aren't review them. 3. There are no clear maintainers for those targets. As the result, my patch may go nowhere. --- But that hasn't stopped others from posting patches like that, or getting them approved. And we also have global maintainers who can approve things. It feels a bit like a hypothetical issue is being used as a reason to do part of the job. paul ^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option 2015-05-19 15:33 ` Paul_Koning @ 2015-05-19 15:43 ` H.J. Lu 0 siblings, 0 replies; 52+ messages in thread From: H.J. Lu @ 2015-05-19 15:43 UTC (permalink / raw) To: Paul Koning; +Cc: Joseph S. Myers, Magnus Granberg, GCC Patches On Tue, May 19, 2015 at 8:33 AM, <Paul_Koning@dell.com> wrote: > > ________________________________________ > From: gcc-patches-owner@gcc.gnu.org [gcc-patches-owner@gcc.gnu.org] on behalf of H.J. Lu [hjl.tools@gmail.com] > Sent: Tuesday, May 19, 2015 11:27 AM > To: Joseph Myers > Cc: Magnus Granberg; GCC Patches > Subject: Re: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option > > On Tue, May 19, 2015 at 8:21 AM, Joseph Myers <joseph@codesourcery.com> wrote: >> ... >> I think the whole thing should be posted as one patch, with both the >> target-independent changes and the target-specific changes for all >> targets. >> > > That is what makes me concerned. I have some simple target-specified > patches which weren't reviewed for years. What will happen if no one > reviews some simple target-specified changes due to > > 1. Reviewers don't have access to those targets. > 2. Target maintainers aren't review them. > 3. There are no clear maintainers for those targets. > > As the result, my patch may go nowhere. > --- > > But that hasn't stopped others from posting patches like that, or getting them approved. And we also have global maintainers who can approve things. It feels a bit like a hypothetical issue is being used as a reason to do part of the job. It is not hypothetical. See: https://gcc.gnu.org/ml/gcc-patches/2012-09/msg01558.html It happened before. I don't want to make it harder for global maintainers to review a patch which has zero-impact on a target if --enable-default-pie isn't used. -- H.J. ^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option 2015-05-19 15:33 ` H.J. Lu 2015-05-19 15:33 ` Paul_Koning @ 2015-05-19 15:37 ` Joseph Myers 2015-05-19 19:33 ` H.J. Lu 1 sibling, 1 reply; 52+ messages in thread From: Joseph Myers @ 2015-05-19 15:37 UTC (permalink / raw) To: H.J. Lu; +Cc: Magnus Granberg, GCC Patches On Tue, 19 May 2015, H.J. Lu wrote: > > I think the whole thing should be posted as one patch, with both the > > target-independent changes and the target-specific changes for all > > targets. > > > > That is what makes me concerned. I have some simple target-specified > patches which weren't reviewed for years. What will happen if no one For any unreviewed patch, keep pinging weekly. > reviews some simple target-specified changes due to > > 1. Reviewers don't have access to those targets. > 2. Target maintainers aren't review them. > 3. There are no clear maintainers for those targets. I've already said in <https://gcc.gnu.org/ml/gcc-patches/2015-05/msg00593.html> that, given target maintainers CC:ed, I might be inclined to approve the patch on the basis of allowing them a week to test their target changes. -- Joseph S. Myers joseph@codesourcery.com ^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option 2015-05-19 15:37 ` Joseph Myers @ 2015-05-19 19:33 ` H.J. Lu 2015-05-20 21:29 ` Joseph Myers ` (4 more replies) 0 siblings, 5 replies; 52+ messages in thread From: H.J. Lu @ 2015-05-19 19:33 UTC (permalink / raw) To: Joseph Myers; +Cc: Magnus Granberg, GCC Patches [-- Attachment #1: Type: text/plain, Size: 5085 bytes --] On Tue, May 19, 2015 at 8:33 AM, Joseph Myers <joseph@codesourcery.com> wrote: > On Tue, 19 May 2015, H.J. Lu wrote: > >> > I think the whole thing should be posted as one patch, with both the >> > target-independent changes and the target-specific changes for all >> > targets. >> > >> >> That is what makes me concerned. I have some simple target-specified >> patches which weren't reviewed for years. What will happen if no one > > For any unreviewed patch, keep pinging weekly. > >> reviews some simple target-specified changes due to >> >> 1. Reviewers don't have access to those targets. >> 2. Target maintainers aren't review them. >> 3. There are no clear maintainers for those targets. > > I've already said in > <https://gcc.gnu.org/ml/gcc-patches/2015-05/msg00593.html> that, given > target maintainers CC:ed, I might be inclined to approve the patch on the > basis of allowing them a week to test their target changes. > Here is the complete patch. Tested on Linux/x86-64. It is also available on hjl/pie/master branch in git mirror. -- H.J. ---- Add --enable-default-pie option to configure GCC to generate PIE by default. gcc/ 2015-05-19 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 (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/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. * 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/ 2015-05-19 H.J. Lu <hongjiu.lu@intel.com> * gcc-interface/Makefile.in (TOOLS_LIBS): Add @NO_PIE_FLAG@. libgcc/ 2015-05-19 H.J. Lu <hongjiu.lu@intel.com> * Makefile.in (CRTSTUFF_CFLAGS): Add $(NO_PIE_CFLAGS). [-- Attachment #2: 0001-Add-enable-default-pie-option-to-GCC-configure.patch --] [-- Type: text/x-patch, Size: 38920 bytes --] From 15d2cee44ff03e1892e6513912e8fafefb12cc83 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" <hjl.tools@gmail.com> Date: Tue, 19 May 2015 10:12:20 -0700 Subject: [PATCH] Add --enable-default-pie option to GCC configure Add --enable-default-pie option to configure GCC to generate PIE by default. gcc/ 2015-05-19 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 (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/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. * 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/ 2015-05-19 H.J. Lu <hongjiu.lu@intel.com> * gcc-interface/Makefile.in (TOOLS_LIBS): Add @NO_PIE_FLAG@. libgcc/ 2015-05-19 H.J. Lu <hongjiu.lu@intel.com> * Makefile.in (CRTSTUFF_CFLAGS): Add $(NO_PIE_CFLAGS). --- gcc/Makefile.in | 15 ++++++++ gcc/ada/gcc-interface/Makefile.in | 3 ++ gcc/common.opt | 10 +++-- gcc/config.in | 6 +++ gcc/config/arm/freebsd.h | 2 +- gcc/config/arm/netbsd-elf.h | 2 +- gcc/config/arm/semi.h | 2 +- gcc/config/c6x/elf-common.h | 6 ++- gcc/config/c6x/uclinux-elf.h | 2 +- gcc/config/cris/linux.h | 4 +- gcc/config/darwin.h | 4 +- gcc/config/darwin9.h | 4 +- gcc/config/frv/frv.h | 10 ++--- gcc/config/gnu-user.h | 7 +++- gcc/config/m32r/m32r.h | 2 +- gcc/config/m68k/m68k.h | 2 +- gcc/config/m68k/netbsd-elf.h | 3 +- gcc/config/m68k/openbsd.h | 3 +- gcc/config/m68k/uclinux.h | 2 +- gcc/config/mips/gnu-user.h | 2 +- gcc/config/mips/vxworks.h | 2 +- gcc/config/openbsd.h | 2 +- gcc/config/rs6000/freebsd64.h | 2 +- gcc/config/rs6000/linux64.h | 2 +- gcc/config/rs6000/sysv4.h | 2 +- gcc/config/rs6000/vxworks.h | 2 +- gcc/config/sol2.h | 2 +- gcc/config/sparc/freebsd.h | 2 +- gcc/config/sparc/linux.h | 2 +- gcc/config/sparc/linux64.h | 2 +- gcc/config/sparc/netbsd-elf.h | 2 +- gcc/config/sparc/openbsd64.h | 2 +- gcc/config/sparc/sp-elf.h | 2 +- gcc/config/sparc/sp64-elf.h | 2 +- gcc/config/sparc/sparc.h | 2 +- gcc/config/sparc/sysv4.h | 2 +- gcc/config/sparc/vxworks.h | 2 +- gcc/config/vax/linux.h | 2 +- gcc/configure | 79 ++++++++++++++++++++++++++++++++++++++- gcc/configure.ac | 40 ++++++++++++++++++++ gcc/defaults.h | 5 +++ gcc/doc/install.texi | 3 ++ gcc/doc/invoke.texi | 4 ++ gcc/gcc.c | 49 +++++++++++++++++++++++- gcc/opts.c | 14 +++++++ libgcc/Makefile.in | 2 +- 46 files changed, 272 insertions(+), 51 deletions(-) diff --git a/gcc/Makefile.in b/gcc/Makefile.in index ab9b637..e429274 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 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) @@ -750,6 +756,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) @@ -761,6 +769,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) @@ -1864,6 +1873,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 ecc443e..90aedb5 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 562d34a..6e15af2 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 231c9ab..daaf906 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 040d7c1..2febf4b 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 ee085a6..6546097 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 18a4443..1c938d3 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 844172d..2a7cd52 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 5048b71..5a04b9d 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 bd57986..262aac5 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 66f504e..9a31952 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 4204825..309c835 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 978fefa..2d4cbdd 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 2faa2e5..2fcb55d 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 ee0c447..7c823f6 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 88356cc..3f45819 100644 --- a/gcc/config/m68k/m68k.h +++ b/gcc/config/m68k/m68k.h @@ -40,7 +40,7 @@ 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 "|mpcrel:--pcrel} \ %{msep-data|mid-shared-library:--pcrel} \ " diff --git a/gcc/config/m68k/netbsd-elf.h b/gcc/config/m68k/netbsd-elf.h index 3922d25..a180667 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 34ea77f..379ca85 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 a6c3f7f..ef6a3a0 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 28b00ed..dd4cf11 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 96512a2..0fa40b0 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 5890078..41bc599 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 84066f6..7e630231 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 1b7f695..bec0fd9 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 41ed4ef..24618e3 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 b4f88de..7440172 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 4dceb16..adf6f3b 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 fa40d4e..f469bf1 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 56def4b..17e1e86 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 fa805fd..43da848 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 165660c..6f99ed4 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 a84d210..b62f9c3 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 85da652..371bb6a 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 2fbdfd0..43adbb5 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 2fae9e8..274f7d6 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 ff886b1..0b358bb 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 c66dba8..e356b25 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 dfcad5b..0765ed9 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 b99eb6d..3a03dce 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] @@ -18162,7 +18167,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 18165 "configure" +#line 18170 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -18268,7 +18273,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 18271 "configure" +#line 18276 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -28571,6 +28576,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_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 810725c..73de1ad 100644 --- a/gcc/configure.ac +++ b/gcc/configure.ac @@ -5826,6 +5826,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) diff --git a/gcc/defaults.h b/gcc/defaults.h index b3edcc9..7436e2c 100644 --- a/gcc/defaults.h +++ b/gcc/defaults.h @@ -1229,6 +1229,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #define ARGS_GROW_DOWNWARD 0 #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 04332c1..437a534 100644 --- a/gcc/doc/install.texi +++ b/gcc/doc/install.texi @@ -1585,6 +1585,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 a451537..e25bd62 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -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 diff --git a/gcc/gcc.c b/gcc/gcc.c index 8f01e42..a8e9c8c 100644 --- 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 diff --git a/gcc/opts.c b/gcc/opts.c index 9deb8df..4b6d978 100644 --- a/gcc/opts.c +++ b/gcc/opts.c @@ -739,8 +739,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 1ab188d..b8fc1d8 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) -- 1.9.3 ^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option 2015-05-19 19:33 ` H.J. Lu @ 2015-05-20 21:29 ` Joseph Myers 2015-05-20 23:01 ` Hans-Peter Nilsson ` (3 subsequent siblings) 4 siblings, 0 replies; 52+ messages in thread From: Joseph Myers @ 2015-05-20 21:29 UTC (permalink / raw) To: H.J. Lu; +Cc: Magnus Granberg, GCC Patches On Tue, 19 May 2015, H.J. Lu wrote: > Here is the complete patch. Tested on Linux/x86-64. It is also > available on hjl/pie/master branch in git mirror. OK a week after you CC all relevant target maintainers on the patch, in the absence of objections from those target maintainers. -- Joseph S. Myers joseph@codesourcery.com ^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option 2015-05-19 19:33 ` H.J. Lu 2015-05-20 21:29 ` Joseph Myers @ 2015-05-20 23:01 ` Hans-Peter Nilsson 2015-05-20 23:54 ` H.J. Lu 2015-05-21 14:42 ` Rainer Orth ` (2 subsequent siblings) 4 siblings, 1 reply; 52+ messages in thread From: Hans-Peter Nilsson @ 2015-05-20 23:01 UTC (permalink / raw) To: hjl.tools; +Cc: joseph, zorry, gcc-patches > From: "H.J. Lu" <hjl.tools@gmail.com> > Date: Tue, 19 May 2015 21:20:46 +0200 > This patch affects your target. Can you verify if it is OK on > your target? If you mean philosophically, it's ok when the general bits and direction are ok, but for the practical part of checking e.g. for typos through compilation, please use yourself a script like gcc/contrib/config-list.mk. > ---- > Add --enable-default-pie option to configure GCC to generate PIE by > default. > > gcc/ > > 2015-05-19 Magnus Granberg <zorry@gentoo.org> > H.J. Lu <hongjiu.lu@intel.com> > * 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. > * config/openbsd.h (ASM_SPEC): Use FPIE1_OR_FPIC1_SPEC and > FPIE2_OR_FPIC2_SPEC. > * config/cris/linux.h (CRIS_ASM_SUBTARGET_SPEC): Likewise. ok. brgds, H-P ^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option 2015-05-20 23:01 ` Hans-Peter Nilsson @ 2015-05-20 23:54 ` H.J. Lu 0 siblings, 0 replies; 52+ messages in thread From: H.J. Lu @ 2015-05-20 23:54 UTC (permalink / raw) To: Hans-Peter Nilsson; +Cc: Joseph S. Myers, Magnus Granberg, GCC Patches On Wed, May 20, 2015 at 3:53 PM, Hans-Peter Nilsson <hans-peter.nilsson@axis.com> wrote: >> From: "H.J. Lu" <hjl.tools@gmail.com> >> Date: Tue, 19 May 2015 21:20:46 +0200 > >> This patch affects your target. Can you verify if it is OK on >> your target? > > If you mean philosophically, it's ok when the general bits and > direction are ok, but for the practical part of checking > e.g. for typos through compilation, please use yourself a script > like gcc/contrib/config-list.mk. > I will run it after I get feedbacks from target maintainers before I check in my patch. > >> * config/cris/linux.h (CRIS_ASM_SUBTARGET_SPEC): Likewise. > > ok. > Thanks. -- H.J. ^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option 2015-05-19 19:33 ` H.J. Lu 2015-05-20 21:29 ` Joseph Myers 2015-05-20 23:01 ` Hans-Peter Nilsson @ 2015-05-21 14:42 ` Rainer Orth 2015-05-21 17:19 ` Joseph Myers 2015-05-21 17:57 ` H.J. Lu [not found] ` <CAMe9rOpZow4w3zcycLoTb5LZdLKP2QWNpsU5oLMJCyZGUTd1fg@mail.gmail.com> 2015-06-10 13:26 ` Rainer Orth 4 siblings, 2 replies; 52+ messages in thread From: Rainer Orth @ 2015-05-21 14:42 UTC (permalink / raw) To: H.J. Lu; +Cc: Joseph Myers, Magnus Granberg, GCC Patches "H.J. Lu" <hjl.tools@gmail.com> writes: > Here is the complete patch. Tested on Linux/x86-64. It is also > available on hjl/pie/master branch in git mirror. As always, please keep generated files like configure and config.in out of the submission: it simplifies review. diff --git a/gcc/Makefile.in b/gcc/Makefile.in index ab9b637..e429274 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 compiler with -fPIE, it make PCH fail. ^s +COMPILER += @NO_PIE_CFLAGS@ @@ -750,6 +756,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@ Here and in several other places, you use += instead of just adding @NO_PIE_CFLAGS@ to the existing BUILD_CFLAGS variable. Please lets keep to the existing idiom instead of randomly introducing another. @@ -761,6 +769,7 @@ BUILD_LINKERFLAGS = $(BUILD_CXXFLAGS) # Native linker and preprocessor flags. For x-fragment overrides. BUILD_LDFLAGS=@BUILD_LDFLAGS@ +BUILD_LDFLAGS += @NO_PIE_FLAG@ Likewise. BUILD_CPPFLAGS= -I. -I$(@D) -I$(srcdir) -I$(srcdir)/$(@D) \ -I$(srcdir)/../include @INCINTL@ $(CPPINC) $(CPPFLAGS) @@ -1864,6 +1873,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"; \ Why literal -fno-PIE instead of @NO_PIE_CFLAGS@? + else \ + NO_PIE_CFLAGS=; \ + fi; \ + echo NO_PIE_CFLAGS = "$$NO_PIE_CFLAGS" >> tmp-libgcc.mvars mv tmp-libgcc.mvars libgcc.mvars Besides, we're trying to get away from libgcc.mvars, moving the detection to libgcc proper. It would be nice to do so here. diff --git a/gcc/ada/gcc-interface/Makefile.in b/gcc/ada/gcc-interface/Makefile.in index ecc443e..90aedb5 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@ Again, avoid += diff --git a/gcc/config/sol2.h b/gcc/config/sol2.h index 4dceb16..adf6f3b 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 \ This is ok once the rest goes in. I haven't reviewed the other target-specific parts, though. diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi index 04332c1..437a534 100644 --- a/gcc/doc/install.texi +++ b/gcc/doc/install.texi @@ -1585,6 +1585,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 This option was added in a seemingly completely random place, between options to enable/disable runtime libs. Please find a better place. diff --git a/gcc/opts.c b/gcc/opts.c index 9deb8df..4b6d978 100644 --- a/gcc/opts.c +++ b/gcc/opts.c @@ -739,8 +739,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 + Couldn't this be done in defaults.h, too? It seems confusing to provide DEFAULT_FLAG_PIE defaults both here and in defaults.h. Rainer -- ----------------------------------------------------------------------------- Rainer Orth, Center for Biotechnology, Bielefeld University ^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option 2015-05-21 14:42 ` Rainer Orth @ 2015-05-21 17:19 ` Joseph Myers 2015-05-21 17:57 ` H.J. Lu 1 sibling, 0 replies; 52+ messages in thread From: Joseph Myers @ 2015-05-21 17:19 UTC (permalink / raw) To: Rainer Orth; +Cc: H.J. Lu, Magnus Granberg, GCC Patches On Thu, 21 May 2015, Rainer Orth wrote: > @@ -1864,6 +1873,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"; \ > > Why literal -fno-PIE instead of @NO_PIE_CFLAGS@? Because this is for the target, but @NO_PIE_CFLAGS@ is for the host. -- Joseph S. Myers joseph@codesourcery.com ^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option 2015-05-21 14:42 ` Rainer Orth 2015-05-21 17:19 ` Joseph Myers @ 2015-05-21 17:57 ` H.J. Lu 2015-06-03 12:48 ` Rainer Orth 1 sibling, 1 reply; 52+ messages in thread From: H.J. Lu @ 2015-05-21 17:57 UTC (permalink / raw) To: Rainer Orth; +Cc: Joseph Myers, Magnus Granberg, GCC Patches On Thu, May 21, 2015 at 7:13 AM, Rainer Orth <ro@cebitec.uni-bielefeld.de> wrote: > "H.J. Lu" <hjl.tools@gmail.com> writes: > >> Here is the complete patch. Tested on Linux/x86-64. It is also >> available on hjl/pie/master branch in git mirror. > > As always, please keep generated files like configure and config.in out > of the submission: it simplifies review. Will do. > diff --git a/gcc/Makefile.in b/gcc/Makefile.in > index ab9b637..e429274 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 compiler with -fPIE, it make PCH fail. > ^s > +COMPILER += @NO_PIE_CFLAGS@ > > @@ -750,6 +756,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@ > > Here and in several other places, you use += instead of just adding > @NO_PIE_CFLAGS@ to the existing BUILD_CFLAGS variable. Please lets > keep to the existing idiom instead of randomly introducing another. I used += because 1. There are things: # library is not introduced. If HOST_LIBS is not set, link with # $(CXX) to pick up -lstdc++. ifeq ($(HOST_LIBS),) LINKER = $(CXX) LINKER_FLAGS = $(CXXFLAGS) else LINKER = $(CC) LINKER_FLAGS = $(CFLAGS) endif Use "+=" only needs one line. 2. There are many usages of "+=" in Makefile.in already. > @@ -761,6 +769,7 @@ BUILD_LINKERFLAGS = $(BUILD_CXXFLAGS) > > # Native linker and preprocessor flags. For x-fragment overrides. > BUILD_LDFLAGS=@BUILD_LDFLAGS@ > +BUILD_LDFLAGS += @NO_PIE_FLAG@ > > Likewise. > > BUILD_CPPFLAGS= -I. -I$(@D) -I$(srcdir) -I$(srcdir)/$(@D) \ > -I$(srcdir)/../include @INCINTL@ $(CPPINC) $(CPPFLAGS) > > @@ -1864,6 +1873,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"; \ > > Why literal -fno-PIE instead of @NO_PIE_CFLAGS@? Joseph already commented on it. > + else \ > + NO_PIE_CFLAGS=; \ > + fi; \ > + echo NO_PIE_CFLAGS = "$$NO_PIE_CFLAGS" >> tmp-libgcc.mvars > > mv tmp-libgcc.mvars libgcc.mvars > > Besides, we're trying to get away from libgcc.mvars, moving the > detection to libgcc proper. It would be nice to do so here. It will happen when libgcc.mvars is removed/moved. I don't want to duplicate the logic in libgcc/configure now. > diff --git a/gcc/ada/gcc-interface/Makefile.in b/gcc/ada/gcc-interface/Makefile.in > index ecc443e..90aedb5 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@ > > Again, avoid += > > diff --git a/gcc/config/sol2.h b/gcc/config/sol2.h > index 4dceb16..adf6f3b 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 \ > > This is ok once the rest goes in. I haven't reviewed the other > target-specific parts, though. > > diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi > index 04332c1..437a534 100644 > --- a/gcc/doc/install.texi > +++ b/gcc/doc/install.texi > @@ -1585,6 +1585,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 > > This option was added in a seemingly completely random place, between > options to enable/disable runtime libs. Please find a better place. I will move it to before "@item --enable-secureplt". If you aren't happy with it, can you suggest a better place? > diff --git a/gcc/opts.c b/gcc/opts.c > index 9deb8df..4b6d978 100644 > --- a/gcc/opts.c > +++ b/gcc/opts.c > @@ -739,8 +739,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 > + > > Couldn't this be done in defaults.h, too? It seems confusing to provide > DEFAULT_FLAG_PIE defaults both here and in defaults.h. I will try. Thanks. -- H.J. ^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option 2015-05-21 17:57 ` H.J. Lu @ 2015-06-03 12:48 ` Rainer Orth 0 siblings, 0 replies; 52+ messages in thread From: Rainer Orth @ 2015-06-03 12:48 UTC (permalink / raw) To: H.J. Lu; +Cc: Joseph Myers, Magnus Granberg, GCC Patches "H.J. Lu" <hjl.tools@gmail.com> writes: > On Thu, May 21, 2015 at 7:13 AM, Rainer Orth > <ro@cebitec.uni-bielefeld.de> wrote: >> "H.J. Lu" <hjl.tools@gmail.com> writes: >> >>> Here is the complete patch. Tested on Linux/x86-64. It is also >>> available on hjl/pie/master branch in git mirror. Now that the patch is in, I see a couple of testsuite regressions on both Linux/x86_64 and Solaris (both SPARC and x86, patches not yet submitted) with --enable-default-pie. Do you plan to fix those? Rainer -- ----------------------------------------------------------------------------- Rainer Orth, Center for Biotechnology, Bielefeld University ^ permalink raw reply [flat|nested] 52+ messages in thread
[parent not found: <CAMe9rOpZow4w3zcycLoTb5LZdLKP2QWNpsU5oLMJCyZGUTd1fg@mail.gmail.com>]
[parent not found: <87vbflkh05.fsf@igel.home>]
[parent not found: <CAMe9rOr0SApdtzeOrc-uNDRH8=z6c4EzHUkyXmERW_q9BYjrAQ@mail.gmail.com>]
[parent not found: <87k2w1k54t.fsf@igel.home>]
* Re: Fwd: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option [not found] ` <87k2w1k54t.fsf@igel.home> @ 2015-05-22 15:39 ` H.J. Lu 2015-05-26 22:42 ` Bill Schmidt ` (3 more replies) 0 siblings, 4 replies; 52+ messages in thread From: H.J. Lu @ 2015-05-22 15:39 UTC (permalink / raw) To: Andreas Schwab Cc: Richard Earnshaw, Bernd Schmidt, Hans-Peter Nilsson, Nick Clifton, Matthew Fortune, David Edelsohn, David S. Miller, Matt Thomas, Rainer Orth, Mike Stump, GCC Patches, Joseph S. Myers [-- Attachment #1: Type: text/plain, Size: 147 bytes --] I fixed a typo in gcc/config/openbsd.h. Here is the updated patch. The whole patch is also on hjl/pie/master branch in GCC git mirror. -- H.J. [-- Attachment #2: 0001-Add-enable-default-pie-option-to-GCC-configure.patch --] [-- Type: text/x-patch, Size: 35071 bytes --] From 64364101d6c888e20eb1146ee2baac4b08e684cf Mon Sep 17 00:00:00 2001 From: "H.J. Lu" <hjl.tools@gmail.com> Date: Tue, 19 May 2015 10:12:20 -0700 Subject: [PATCH] Add --enable-default-pie option to GCC configure Add --enable-default-pie option to configure GCC to generate PIE by default. gcc/ 2015-05-19 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. gcc/ada/ 2015-05-19 H.J. Lu <hongjiu.lu@intel.com> * gcc-interface/Makefile.in (TOOLS_LIBS): Add @NO_PIE_FLAG@. libgcc/ 2015-05-19 H.J. Lu <hongjiu.lu@intel.com> * Makefile.in (CRTSTUFF_CFLAGS): Add $(NO_PIE_CFLAGS). --- gcc/Makefile.in | 15 ++++++++ gcc/ada/gcc-interface/Makefile.in | 3 ++ gcc/common.opt | 10 +++-- gcc/config.in | 6 +++ gcc/config/arm/freebsd.h | 2 +- gcc/config/arm/netbsd-elf.h | 2 +- gcc/config/arm/semi.h | 2 +- gcc/config/c6x/elf-common.h | 6 ++- gcc/config/c6x/uclinux-elf.h | 2 +- gcc/config/cris/linux.h | 4 +- gcc/config/darwin.h | 4 +- gcc/config/darwin9.h | 4 +- gcc/config/frv/frv.h | 10 ++--- gcc/config/gnu-user.h | 7 +++- gcc/config/m32r/m32r.h | 2 +- gcc/config/m68k/m68k.h | 3 +- gcc/config/m68k/netbsd-elf.h | 3 +- gcc/config/m68k/openbsd.h | 3 +- gcc/config/m68k/uclinux.h | 2 +- gcc/config/mips/gnu-user.h | 2 +- gcc/config/mips/vxworks.h | 2 +- gcc/config/openbsd.h | 2 +- gcc/config/rs6000/freebsd64.h | 2 +- gcc/config/rs6000/linux64.h | 2 +- gcc/config/rs6000/sysv4.h | 2 +- gcc/config/rs6000/vxworks.h | 2 +- gcc/config/sol2.h | 2 +- gcc/config/sparc/freebsd.h | 2 +- gcc/config/sparc/linux.h | 2 +- gcc/config/sparc/linux64.h | 2 +- gcc/config/sparc/netbsd-elf.h | 2 +- gcc/config/sparc/openbsd64.h | 2 +- gcc/config/sparc/sp-elf.h | 2 +- gcc/config/sparc/sp64-elf.h | 2 +- gcc/config/sparc/sparc.h | 2 +- gcc/config/sparc/sysv4.h | 2 +- gcc/config/sparc/vxworks.h | 2 +- gcc/config/vax/linux.h | 2 +- gcc/configure | 79 ++++++++++++++++++++++++++++++++++++++- gcc/configure.ac | 40 ++++++++++++++++++++ gcc/defaults.h | 12 ++++++ gcc/doc/install.texi | 3 ++ gcc/doc/invoke.texi | 4 ++ gcc/gcc.c | 49 +++++++++++++++++++++++- gcc/opts.c | 9 +++++ libgcc/Makefile.in | 2 +- 46 files changed, 275 insertions(+), 51 deletions(-) diff --git a/gcc/Makefile.in b/gcc/Makefile.in index ab9b637..512e7c8 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) @@ -750,6 +756,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) @@ -761,6 +769,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) @@ -1864,6 +1873,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 ecc443e..90aedb5 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 562d34a..6e15af2 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/arm/freebsd.h b/gcc/config/arm/freebsd.h index 040d7c1..2febf4b 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 ee085a6..6546097 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 18a4443..1c938d3 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 844172d..2a7cd52 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 5048b71..5a04b9d 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 bd57986..262aac5 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 66f504e..9a31952 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 4204825..309c835 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 978fefa..2d4cbdd 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 2faa2e5..2fcb55d 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 66ceae0..2163de4 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 88356cc..74ebff7 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 3922d25..a180667 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 34ea77f..379ca85 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 a6c3f7f..ef6a3a0 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 28b00ed..dd4cf11 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 96512a2..0fa40b0 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 5890078..cf66548 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 84066f6..7e630231 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 1b7f695..bec0fd9 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 41ed4ef..24618e3 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 b4f88de..7440172 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 4dceb16..adf6f3b 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 fa40d4e..f469bf1 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 56def4b..17e1e86 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 fa805fd..43da848 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 165660c..6f99ed4 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 a84d210..b62f9c3 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 85da652..371bb6a 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 2fbdfd0..43adbb5 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 ce1b68b..106d993 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 ff886b1..0b358bb 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 c66dba8..e356b25 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 dfcad5b..0765ed9 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.ac b/gcc/configure.ac index 810725c..73de1ad 100644 --- a/gcc/configure.ac +++ b/gcc/configure.ac @@ -5826,6 +5826,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) diff --git a/gcc/defaults.h b/gcc/defaults.h index e7bbcb8..aa2a775 100644 --- a/gcc/defaults.h +++ b/gcc/defaults.h @@ -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 diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi index 04332c1..24c4a33 100644 --- a/gcc/doc/install.texi +++ b/gcc/doc/install.texi @@ -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 diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index a451537..e25bd62 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -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 diff --git a/gcc/gcc.c b/gcc/gcc.c index 8f01e42..a8e9c8c 100644 --- 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 diff --git a/gcc/opts.c b/gcc/opts.c index 9deb8df..9793999 100644 --- a/gcc/opts.c +++ b/gcc/opts.c @@ -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) diff --git a/libgcc/Makefile.in b/libgcc/Makefile.in index 1f2b806..527d87b 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) -- 1.9.3 ^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: Fwd: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option 2015-05-22 15:39 ` Fwd: " H.J. Lu @ 2015-05-26 22:42 ` Bill Schmidt 2015-05-26 22:53 ` Bill Schmidt 2015-05-30 15:45 ` Andreas Schwab ` (2 subsequent siblings) 3 siblings, 1 reply; 52+ messages in thread From: Bill Schmidt @ 2015-05-26 22:42 UTC (permalink / raw) To: H.J. Lu Cc: Andreas Schwab, Richard Earnshaw, Bernd Schmidt, Hans-Peter Nilsson, Nick Clifton, Matthew Fortune, David Edelsohn, David S. Miller, Matt Thomas, Rainer Orth, Mike Stump, GCC Patches, Joseph S. Myers Hi H.J., I tried your patch on powerpc64le-linux-gnu, and it fails to bootstrap as follows: > g++ -std=c++98 -c -g -DIN_GCC -fno-exceptions -fno-rtti -fasynchronous-unwi > nd-tables -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wno-format -Wmiss > ing-format-attribute -Woverloaded-virtual -pedantic -Wno-long-long -Wno-variadic > -macros -Wno-overlength-strings -fno-common -DHAVE_CONFIG_H -DGENERATOR_FILE @N > O_PIE_CFLAGS@ -I. -Ibuild -I/home/wschmidt/gcc/gcc-mainline-test/gcc -I/home/wsc > hmidt/gcc/gcc-mainline-test/gcc/build -I/home/wschmidt/gcc/gcc-mainline-test/gcc > /../include -I/home/wschmidt/gcc/gcc-mainline-test/gcc/../libcpp/include \ > -DBASEVER="\"6.0.0\"" -DDATESTAMP="\" 20150526\"" \ > -DREVISION="\" [trunk revision 223719]\"" \ > -DDEVPHASE="\" (experimental)\"" -DPKGVERSION="\"(GCC) \"" \ > -DBUGURL="\"<http://gcc.gnu.org/bugs.html>\"" -o build/version.o /home/wschmidt/gcc/gcc-mainline-test/gcc/version.c > g++: error: @NO_PIE_CFLAGS@: No such file or directory > make[3]: *** [build/version.o] Error 1 Thanks, Bill On Fri, 2015-05-22 at 08:18 -0700, H.J. Lu wrote: > I fixed a typo in gcc/config/openbsd.h. Here is the updated patch. The whole > patch is also on hjl/pie/master branch in GCC git mirror. > ^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: Fwd: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option 2015-05-26 22:42 ` Bill Schmidt @ 2015-05-26 22:53 ` Bill Schmidt 2015-05-27 15:42 ` Peter Bergner 0 siblings, 1 reply; 52+ messages in thread From: Bill Schmidt @ 2015-05-26 22:53 UTC (permalink / raw) To: H.J. Lu Cc: Andreas Schwab, Richard Earnshaw, Bernd Schmidt, Hans-Peter Nilsson, Nick Clifton, Matthew Fortune, David Edelsohn, David S. Miller, Matt Thomas, Rainer Orth, Mike Stump, GCC Patches, Joseph S. Myers Ah, never mind. I guess I need to run automake first. Bill On Tue, 2015-05-26 at 16:39 -0500, Bill Schmidt wrote: > Hi H.J., > > I tried your patch on powerpc64le-linux-gnu, and it fails to bootstrap > as follows: > > > g++ -std=c++98 -c -g -DIN_GCC -fno-exceptions -fno-rtti -fasynchronous-unwi > > nd-tables -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wno-format -Wmiss > > ing-format-attribute -Woverloaded-virtual -pedantic -Wno-long-long -Wno-variadic > > -macros -Wno-overlength-strings -fno-common -DHAVE_CONFIG_H -DGENERATOR_FILE @N > > O_PIE_CFLAGS@ -I. -Ibuild -I/home/wschmidt/gcc/gcc-mainline-test/gcc -I/home/wsc > > hmidt/gcc/gcc-mainline-test/gcc/build -I/home/wschmidt/gcc/gcc-mainline-test/gcc > > /../include -I/home/wschmidt/gcc/gcc-mainline-test/gcc/../libcpp/include \ > > -DBASEVER="\"6.0.0\"" -DDATESTAMP="\" 20150526\"" \ > > -DREVISION="\" [trunk revision 223719]\"" \ > > -DDEVPHASE="\" (experimental)\"" -DPKGVERSION="\"(GCC) \"" \ > > -DBUGURL="\"<http://gcc.gnu.org/bugs.html>\"" -o build/version.o /home/wschmidt/gcc/gcc-mainline-test/gcc/version.c > > g++: error: @NO_PIE_CFLAGS@: No such file or directory > > make[3]: *** [build/version.o] Error 1 > > Thanks, > Bill > > On Fri, 2015-05-22 at 08:18 -0700, H.J. Lu wrote: > > I fixed a typo in gcc/config/openbsd.h. Here is the updated patch. The whole > > patch is also on hjl/pie/master branch in GCC git mirror. > > > ^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: Fwd: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option 2015-05-26 22:53 ` Bill Schmidt @ 2015-05-27 15:42 ` Peter Bergner 2015-05-27 15:59 ` H.J. Lu 0 siblings, 1 reply; 52+ messages in thread From: Peter Bergner @ 2015-05-27 15:42 UTC (permalink / raw) To: Bill Schmidt Cc: H.J. Lu, Andreas Schwab, Richard Earnshaw, Bernd Schmidt, Hans-Peter Nilsson, Nick Clifton, Matthew Fortune, David Edelsohn, David S. Miller, Matt Thomas, Rainer Orth, Mike Stump, GCC Patches, Joseph S. Myers On Tue, 2015-05-26 at 16:40 -0500, Bill Schmidt wrote: > Ah, never mind. I guess I need to run automake first. I ran the patch on powerpc64-linux (ie, Big Endian) both with and without --enable-default-pie. Both bootstraps completed with no errors and the without --enable-default-pie regtested without any regressions. The --enable-default-pie regtesting shows massive failures that I have to look into. I'm haven't determined yet whether these are all -m32 FAILs or -m64 FAILS or both. I'll report back with more info after I dig into some of the failures. Peter ^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: Fwd: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option 2015-05-27 15:42 ` Peter Bergner @ 2015-05-27 15:59 ` H.J. Lu 2015-05-27 16:17 ` Peter Bergner 0 siblings, 1 reply; 52+ messages in thread From: H.J. Lu @ 2015-05-27 15:59 UTC (permalink / raw) To: Peter Bergner Cc: Bill Schmidt, Andreas Schwab, Richard Earnshaw, Bernd Schmidt, Hans-Peter Nilsson, Nick Clifton, Matthew Fortune, David Edelsohn, David S. Miller, Matt Thomas, Rainer Orth, Mike Stump, GCC Patches, Joseph S. Myers On Wed, May 27, 2015 at 8:24 AM, Peter Bergner <bergner@vnet.ibm.com> wrote: > On Tue, 2015-05-26 at 16:40 -0500, Bill Schmidt wrote: >> Ah, never mind. I guess I need to run automake first. > > I ran the patch on powerpc64-linux (ie, Big Endian) both with and > without --enable-default-pie. Both bootstraps completed with no > errors and the without --enable-default-pie regtested without any > regressions. > > The --enable-default-pie regtesting shows massive failures that I > have to look into. I'm haven't determined yet whether these are > all -m32 FAILs or -m64 FAILS or both. I'll report back with more > info after I dig into some of the failures. Does --enable-default-pie work on powerpc64-linux? Do you get working PIE by default? Some GCC tests expect non-PIE. I fixed some of them: commit 82923064d660e4183933b014ee3f645799a945b0 Author: hjl <hjl@138bc75d-0d04-0410-961f-82ee72b054a4> Date: Thu Jan 15 16:33:37 2015 +0000 Ignore additional linker messages on Linux/x86 with PIE g++.dg/other/anon5.C is expected to fail to link. On Linux/x86 with PIE and the new linker, there are additional messages from linker: [hjl@gnu-tools-1 gcc]$ g++ -fPIE -pie /export/gnu/import/git/sources/gcc/gcc/testsuite/g++.dg/other/anon5.C /tmp/ccwg53fj.o: In function `f()': anon5.C:(.text+0x7): undefined reference to `(anonymous namespace)::c::t' /usr/local/bin/ld: /tmp/ccwg53fj.o: relocation R_X86_64_PC32 against undefined symbol `_ZN12_GLOBAL__N_11c1tE' can not be used when making a shared object; recompile with -fPIC /usr/local/bin/ld: final link failed: Bad value collect2: error: ld returned 1 exit status [hjl@gnu-tools-1 gcc]$ This patch ignores additional linker messages on Linux/x86 with PIE. * g++.dg/other/anon5.C: Ignore additional messages on Linux/x86 with PIE. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@219667 138bc75d-0d04-0410-961f-82ee72b054a4 -- H.J. ^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: Fwd: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option 2015-05-27 15:59 ` H.J. Lu @ 2015-05-27 16:17 ` Peter Bergner 2015-05-27 16:34 ` H.J. Lu 0 siblings, 1 reply; 52+ messages in thread From: Peter Bergner @ 2015-05-27 16:17 UTC (permalink / raw) To: H.J. Lu Cc: Bill Schmidt, Andreas Schwab, Richard Earnshaw, Bernd Schmidt, Hans-Peter Nilsson, Nick Clifton, Matthew Fortune, David Edelsohn, David S. Miller, Matt Thomas, Rainer Orth, Mike Stump, GCC Patches, Joseph S. Myers On Wed, 2015-05-27 at 08:36 -0700, H.J. Lu wrote: > On Wed, May 27, 2015 at 8:24 AM, Peter Bergner <bergner@vnet.ibm.com> wrote: > > On Tue, 2015-05-26 at 16:40 -0500, Bill Schmidt wrote: > >> Ah, never mind. I guess I need to run automake first. > > > > I ran the patch on powerpc64-linux (ie, Big Endian) both with and > > without --enable-default-pie. Both bootstraps completed with no > > errors and the without --enable-default-pie regtested without any > > regressions. > > > > The --enable-default-pie regtesting shows massive failures that I > > have to look into. I'm haven't determined yet whether these are > > all -m32 FAILs or -m64 FAILS or both. I'll report back with more > > info after I dig into some of the failures. > > Does --enable-default-pie work on powerpc64-linux? Do you > get working PIE by default? Some GCC tests expect non-PIE. > I fixed some of them: I haven't looked into any of the failures yet. That said, powerpc64-linux is PIC by default, so I thought maybe PIE would just work. Maybe it does and it's just powerpc-linux tests that are failing (I run the testsuite with both -m32 and -m64). I won't know until I get some time to have a deeper look. That said, if there is something you know of that I should look for or at, I'd appreciate it. Peter ^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: Fwd: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option 2015-05-27 16:17 ` Peter Bergner @ 2015-05-27 16:34 ` H.J. Lu 2015-05-27 17:43 ` David Edelsohn 0 siblings, 1 reply; 52+ messages in thread From: H.J. Lu @ 2015-05-27 16:34 UTC (permalink / raw) To: Peter Bergner Cc: Bill Schmidt, Andreas Schwab, Richard Earnshaw, Bernd Schmidt, Hans-Peter Nilsson, Nick Clifton, Matthew Fortune, David Edelsohn, David S. Miller, Matt Thomas, Rainer Orth, Mike Stump, GCC Patches, Joseph S. Myers On Wed, May 27, 2015 at 9:05 AM, Peter Bergner <bergner@vnet.ibm.com> wrote: > On Wed, 2015-05-27 at 08:36 -0700, H.J. Lu wrote: >> On Wed, May 27, 2015 at 8:24 AM, Peter Bergner <bergner@vnet.ibm.com> wrote: >> > On Tue, 2015-05-26 at 16:40 -0500, Bill Schmidt wrote: >> >> Ah, never mind. I guess I need to run automake first. >> > >> > I ran the patch on powerpc64-linux (ie, Big Endian) both with and >> > without --enable-default-pie. Both bootstraps completed with no >> > errors and the without --enable-default-pie regtested without any >> > regressions. >> > >> > The --enable-default-pie regtesting shows massive failures that I >> > have to look into. I'm haven't determined yet whether these are >> > all -m32 FAILs or -m64 FAILS or both. I'll report back with more >> > info after I dig into some of the failures. >> >> Does --enable-default-pie work on powerpc64-linux? Do you >> get working PIE by default? Some GCC tests expect non-PIE. >> I fixed some of them: > > I haven't looked into any of the failures yet. That said, > powerpc64-linux is PIC by default, so I thought maybe PIE PIC != PIE. Is PIE the default for powerpc64-linux? Please show me # readelf -h /bin/ls on powerpc64-linux. > would just work. Maybe it does and it's just powerpc-linux > tests that are failing (I run the testsuite with both > -m32 and -m64). I won't know until I get some time to have > a deeper look. That said, if there is something you know > of that I should look for or at, I'd appreciate it. > You should first verify if --enable-default-pie generates a GCC which can produce a simple hello program. -- H.J. ^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: Fwd: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option 2015-05-27 16:34 ` H.J. Lu @ 2015-05-27 17:43 ` David Edelsohn 2015-05-27 17:44 ` H.J. Lu 0 siblings, 1 reply; 52+ messages in thread From: David Edelsohn @ 2015-05-27 17:43 UTC (permalink / raw) To: H.J. Lu Cc: Peter Bergner, Bill Schmidt, Andreas Schwab, Richard Earnshaw, Bernd Schmidt, Hans-Peter Nilsson, Nick Clifton, Matthew Fortune, David S. Miller, Matt Thomas, Rainer Orth, Mike Stump, GCC Patches, Joseph S. Myers On Wed, May 27, 2015 at 12:18 PM, H.J. Lu <hjl.tools@gmail.com> wrote: > On Wed, May 27, 2015 at 9:05 AM, Peter Bergner <bergner@vnet.ibm.com> wrote: >> On Wed, 2015-05-27 at 08:36 -0700, H.J. Lu wrote: >>> On Wed, May 27, 2015 at 8:24 AM, Peter Bergner <bergner@vnet.ibm.com> wrote: >>> > On Tue, 2015-05-26 at 16:40 -0500, Bill Schmidt wrote: >>> >> Ah, never mind. I guess I need to run automake first. >>> > >>> > I ran the patch on powerpc64-linux (ie, Big Endian) both with and >>> > without --enable-default-pie. Both bootstraps completed with no >>> > errors and the without --enable-default-pie regtested without any >>> > regressions. >>> > >>> > The --enable-default-pie regtesting shows massive failures that I >>> > have to look into. I'm haven't determined yet whether these are >>> > all -m32 FAILs or -m64 FAILS or both. I'll report back with more >>> > info after I dig into some of the failures. >>> >>> Does --enable-default-pie work on powerpc64-linux? Do you >>> get working PIE by default? Some GCC tests expect non-PIE. >>> I fixed some of them: >> >> I haven't looked into any of the failures yet. That said, >> powerpc64-linux is PIC by default, so I thought maybe PIE > > PIC != PIE. Is PIE the default for powerpc64-linux? Please > show me > > # readelf -h /bin/ls > > on powerpc64-linux. > >> would just work. Maybe it does and it's just powerpc-linux >> tests that are failing (I run the testsuite with both >> -m32 and -m64). I won't know until I get some time to have >> a deeper look. That said, if there is something you know >> of that I should look for or at, I'd appreciate it. >> > > You should first verify if --enable-default-pie generates a GCC which > can produce a simple hello program. The --enable-default-pie patch itself works correctly -- as intended -- for powerpc64-linux and powerpc64le-linux and the rs6000 parts of the patch are okay with me. In other words, the option is fine but is not enabled by default so it will not cause any problems. Debugging the testsuite failures is a separate issue. Thanks, David ^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: Fwd: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option 2015-05-27 17:43 ` David Edelsohn @ 2015-05-27 17:44 ` H.J. Lu 0 siblings, 0 replies; 52+ messages in thread From: H.J. Lu @ 2015-05-27 17:44 UTC (permalink / raw) To: David Edelsohn Cc: Peter Bergner, Bill Schmidt, Andreas Schwab, Richard Earnshaw, Bernd Schmidt, Hans-Peter Nilsson, Nick Clifton, Matthew Fortune, David S. Miller, Matt Thomas, Rainer Orth, Mike Stump, GCC Patches, Joseph S. Myers On Wed, May 27, 2015 at 9:59 AM, David Edelsohn <dje.gcc@gmail.com> wrote: > On Wed, May 27, 2015 at 12:18 PM, H.J. Lu <hjl.tools@gmail.com> wrote: >> On Wed, May 27, 2015 at 9:05 AM, Peter Bergner <bergner@vnet.ibm.com> wrote: >>> On Wed, 2015-05-27 at 08:36 -0700, H.J. Lu wrote: >>>> On Wed, May 27, 2015 at 8:24 AM, Peter Bergner <bergner@vnet.ibm.com> wrote: >>>> > On Tue, 2015-05-26 at 16:40 -0500, Bill Schmidt wrote: >>>> >> Ah, never mind. I guess I need to run automake first. >>>> > >>>> > I ran the patch on powerpc64-linux (ie, Big Endian) both with and >>>> > without --enable-default-pie. Both bootstraps completed with no >>>> > errors and the without --enable-default-pie regtested without any >>>> > regressions. >>>> > >>>> > The --enable-default-pie regtesting shows massive failures that I >>>> > have to look into. I'm haven't determined yet whether these are >>>> > all -m32 FAILs or -m64 FAILS or both. I'll report back with more >>>> > info after I dig into some of the failures. >>>> >>>> Does --enable-default-pie work on powerpc64-linux? Do you >>>> get working PIE by default? Some GCC tests expect non-PIE. >>>> I fixed some of them: >>> >>> I haven't looked into any of the failures yet. That said, >>> powerpc64-linux is PIC by default, so I thought maybe PIE >> >> PIC != PIE. Is PIE the default for powerpc64-linux? Please >> show me >> >> # readelf -h /bin/ls >> >> on powerpc64-linux. >> >>> would just work. Maybe it does and it's just powerpc-linux >>> tests that are failing (I run the testsuite with both >>> -m32 and -m64). I won't know until I get some time to have >>> a deeper look. That said, if there is something you know >>> of that I should look for or at, I'd appreciate it. >>> >> >> You should first verify if --enable-default-pie generates a GCC which >> can produce a simple hello program. > > The --enable-default-pie patch itself works correctly -- as intended > -- for powerpc64-linux and powerpc64le-linux and the rs6000 parts of > the patch are okay with me. In other words, the option is fine but is > not enabled by default so it will not cause any problems. Good to know. > Debugging the testsuite failures is a separate issue. Thanks. -- H.J. ^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: Fwd: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option 2015-05-22 15:39 ` Fwd: " H.J. Lu 2015-05-26 22:42 ` Bill Schmidt @ 2015-05-30 15:45 ` Andreas Schwab 2015-05-30 16:24 ` H.J. Lu 2015-05-30 20:04 ` Andreas Schwab 2015-10-23 11:57 ` Marcus Shawcroft 3 siblings, 1 reply; 52+ messages in thread From: Andreas Schwab @ 2015-05-30 15:45 UTC (permalink / raw) To: H.J. Lu Cc: Richard Earnshaw, Bernd Schmidt, Hans-Peter Nilsson, Nick Clifton, Matthew Fortune, David Edelsohn, David S. Miller, Matt Thomas, Rainer Orth, Mike Stump, GCC Patches, Joseph S. Myers "H.J. Lu" <hjl.tools@gmail.com> writes: > +# 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]) > + That doesn't work: configure:28726: checking for -fno-PIE option configure:28737: g++ -c -g conftest.cpp >&5 configure:28737: $? = 0 configure:28745: result: yes > +# 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]) > + That doesn't work with gcc 4.3: configure:28753: checking for -no-pie option configure:28764: g++ -std=c++98 -o conftest -g -no-pie conftest.cpp >&5 g++: unrecognized option '-no-pie' configure:28764: $? = 0 configure:28773: result: yes Andreas. -- Andreas Schwab, schwab@linux-m68k.org GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 "And now for something completely different." ^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: Fwd: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option 2015-05-30 15:45 ` Andreas Schwab @ 2015-05-30 16:24 ` H.J. Lu 2015-05-30 16:44 ` Andreas Schwab 0 siblings, 1 reply; 52+ messages in thread From: H.J. Lu @ 2015-05-30 16:24 UTC (permalink / raw) To: Andreas Schwab Cc: Richard Earnshaw, Bernd Schmidt, Hans-Peter Nilsson, Nick Clifton, Matthew Fortune, David Edelsohn, David S. Miller, Matt Thomas, Rainer Orth, Mike Stump, GCC Patches, Joseph S. Myers On Sat, May 30, 2015 at 8:10 AM, Andreas Schwab <schwab@linux-m68k.org> wrote: > "H.J. Lu" <hjl.tools@gmail.com> writes: > >> +# 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]) >> + > > That doesn't work: > > configure:28726: checking for -fno-PIE option > configure:28737: g++ -c -g conftest.cpp >&5 > configure:28737: $? = 0 > configure:28745: result: yes > >> +# 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]) >> + > > That doesn't work with gcc 4.3: > > configure:28753: checking for -no-pie option > configure:28764: g++ -std=c++98 -o conftest -g -no-pie conftest.cpp >&5 > g++: unrecognized option '-no-pie' > configure:28764: $? = 0 > configure:28773: result: yes > Starting GCC 4.6, the unrecognized option became an error. Before 4.6, it was ignored. Does it cause any problems for bootstrap? -- H.J. ^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: Fwd: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option 2015-05-30 16:24 ` H.J. Lu @ 2015-05-30 16:44 ` Andreas Schwab 2015-05-30 17:04 ` H.J. Lu 0 siblings, 1 reply; 52+ messages in thread From: Andreas Schwab @ 2015-05-30 16:44 UTC (permalink / raw) To: H.J. Lu Cc: Richard Earnshaw, Bernd Schmidt, Hans-Peter Nilsson, Nick Clifton, Matthew Fortune, David Edelsohn, David S. Miller, Matt Thomas, Rainer Orth, Mike Stump, GCC Patches, Joseph S. Myers "H.J. Lu" <hjl.tools@gmail.com> writes: > Starting GCC 4.6, the unrecognized option became an error. > Before 4.6, it was ignored. Does it cause any problems for > bootstrap? No, only spurious messages. Andreas. -- Andreas Schwab, schwab@linux-m68k.org GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 "And now for something completely different." ^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: Fwd: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option 2015-05-30 16:44 ` Andreas Schwab @ 2015-05-30 17:04 ` H.J. Lu 2015-05-30 20:08 ` Andreas Schwab 0 siblings, 1 reply; 52+ messages in thread From: H.J. Lu @ 2015-05-30 17:04 UTC (permalink / raw) To: Andreas Schwab Cc: Richard Earnshaw, Bernd Schmidt, Hans-Peter Nilsson, Nick Clifton, Matthew Fortune, David Edelsohn, David S. Miller, Matt Thomas, Rainer Orth, Mike Stump, GCC Patches, Joseph S. Myers On Sat, May 30, 2015 at 8:54 AM, Andreas Schwab <schwab@linux-m68k.org> wrote: > "H.J. Lu" <hjl.tools@gmail.com> writes: > >> Starting GCC 4.6, the unrecognized option became an error. >> Before 4.6, it was ignored. Does it cause any problems for >> bootstrap? > > No, only spurious messages. > There is no harm and the message is gone in stage 2 and 3, We can treat it the same as other spurious messages from the bootstrap compiler. -- H.J. ^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: Fwd: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option 2015-05-30 17:04 ` H.J. Lu @ 2015-05-30 20:08 ` Andreas Schwab 2015-05-30 21:42 ` H.J. Lu 0 siblings, 1 reply; 52+ messages in thread From: Andreas Schwab @ 2015-05-30 20:08 UTC (permalink / raw) To: H.J. Lu; +Cc: GCC Patches "H.J. Lu" <hjl.tools@gmail.com> writes: > There is no harm and the message is gone in stage 2 and 3, > We can treat it the same as other spurious messages from the > bootstrap compiler. But you still need to fix the first test, since it doesn't test anything. Andreas. -- Andreas Schwab, schwab@linux-m68k.org GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 "And now for something completely different." ^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: Fwd: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option 2015-05-30 20:08 ` Andreas Schwab @ 2015-05-30 21:42 ` H.J. Lu 2015-05-31 0:52 ` Andreas Schwab 0 siblings, 1 reply; 52+ messages in thread From: H.J. Lu @ 2015-05-30 21:42 UTC (permalink / raw) To: Andreas Schwab; +Cc: GCC Patches On Sat, May 30, 2015 at 9:44 AM, Andreas Schwab <schwab@linux-m68k.org> wrote: > "H.J. Lu" <hjl.tools@gmail.com> writes: > >> There is no harm and the message is gone in stage 2 and 3, >> We can treat it the same as other spurious messages from the >> bootstrap compiler. > > But you still need to fix the first test, since it doesn't test > anything. > What is wrong with it? Its purpose is to always compile GCC without PIE. If the bootstrap compiler allows -fno-PIE, we add it. Does the test pass when the bootstrap compiler errors on -fno-PIE? -- H.J. ^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: Fwd: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option 2015-05-30 21:42 ` H.J. Lu @ 2015-05-31 0:52 ` Andreas Schwab 2015-05-31 7:13 ` H.J. Lu 0 siblings, 1 reply; 52+ messages in thread From: Andreas Schwab @ 2015-05-31 0:52 UTC (permalink / raw) To: H.J. Lu; +Cc: GCC Patches "H.J. Lu" <hjl.tools@gmail.com> writes: > What is wrong with it? It tests nothing. Andreas. -- Andreas Schwab, schwab@linux-m68k.org GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 "And now for something completely different." ^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: Fwd: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option 2015-05-31 0:52 ` Andreas Schwab @ 2015-05-31 7:13 ` H.J. Lu 2015-05-31 8:23 ` Andreas Schwab 0 siblings, 1 reply; 52+ messages in thread From: H.J. Lu @ 2015-05-31 7:13 UTC (permalink / raw) To: Andreas Schwab; +Cc: GCC Patches On Sat, May 30, 2015 at 2:18 PM, Andreas Schwab <schwab@linux-m68k.org> wrote: > "H.J. Lu" <hjl.tools@gmail.com> writes: > >> What is wrong with it? > > It tests nothing. > Can you explain? -- H.J. ^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: Fwd: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option 2015-05-31 7:13 ` H.J. Lu @ 2015-05-31 8:23 ` Andreas Schwab 2015-05-31 15:52 ` H.J. Lu 0 siblings, 1 reply; 52+ messages in thread From: Andreas Schwab @ 2015-05-31 8:23 UTC (permalink / raw) To: H.J. Lu; +Cc: GCC Patches configure:28726: checking for -fno-PIE option configure:28737: g++ -c -g conftest.cpp >&5 configure:28737: $? = 0 configure:28745: result: yes Andreas. -- Andreas Schwab, schwab@linux-m68k.org GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 "And now for something completely different." ^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: Fwd: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option 2015-05-31 8:23 ` Andreas Schwab @ 2015-05-31 15:52 ` H.J. Lu 0 siblings, 0 replies; 52+ messages in thread From: H.J. Lu @ 2015-05-31 15:52 UTC (permalink / raw) To: Andreas Schwab; +Cc: GCC Patches On Sun, May 31, 2015 at 12:04 AM, Andreas Schwab <schwab@linux-m68k.org> wrote: > configure:28726: checking for -fno-PIE option > configure:28737: g++ -c -g conftest.cpp >&5 > configure:28737: $? = 0 > configure:28745: result: yes Since GCC is written in C++ now, we need to check CXXFLAGS instead of CFLAGS for NO_PIE_CFLAGS. I checked it in as an obvious fix. Thanks. -- H.J. --- Index: ChangeLog =================================================================== --- ChangeLog (revision 223898) +++ ChangeLog (working copy) @@ -1,3 +1,8 @@ +2015-05-31 H.J. Lu <hongjiu.lu@intel.com> + + * configure.ac (NO_PIE_CFLAGS): Check CXXFLAGS instead of CFLAGS. + * configure: Regenerated. + 2015-05-31 Mikhail Maltsev <maltsevm@gmail.com> * config/cris/cris.h (CRIS_ARCH_CPP_DEFAULT): Fix C++11 compatibility Index: configure =================================================================== --- configure (revision 223898) +++ configure (working copy) @@ -28728,8 +28728,8 @@ $as_echo_n "checking for -fno-PIE option if test "${gcc_cv_c_no_fpie+set}" = set; then : $as_echo_n "(cached) " >&6 else - saved_CFLAGS="$CFLAGS" - CFLAGS="$CFLAGS -fno-PIE" + saved_CXXFLAGS="$CXXFLAGS" + CXXFLAGS="$CXXFLAGS -fno-PIE" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main(void) {return 0;} @@ -28740,7 +28740,7 @@ else gcc_cv_c_no_fpie=no fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - CFLAGS="$saved_CFLAGS" + CXXFLAGS="$saved_CXXFLAGS" fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_c_no_fpie" >&5 $as_echo "$gcc_cv_c_no_fpie" >&6; } Index: configure.ac =================================================================== --- configure.ac (revision 223898) +++ configure.ac (working copy) @@ -5834,12 +5834,12 @@ 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" + [saved_CXXFLAGS="$CXXFLAGS" + CXXFLAGS="$CXXFLAGS -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"]) + CXXFLAGS="$saved_CXXFLAGS"]) if test "$gcc_cv_c_no_fpie" = "yes"; then NO_PIE_CFLAGS="-fno-PIE" fi ^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: Fwd: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option 2015-05-22 15:39 ` Fwd: " H.J. Lu 2015-05-26 22:42 ` Bill Schmidt 2015-05-30 15:45 ` Andreas Schwab @ 2015-05-30 20:04 ` Andreas Schwab 2015-05-30 21:08 ` Andreas Schwab 2015-10-23 11:57 ` Marcus Shawcroft 3 siblings, 1 reply; 52+ messages in thread From: Andreas Schwab @ 2015-05-30 20:04 UTC (permalink / raw) To: H.J. Lu; +Cc: GCC Patches "H.J. Lu" <hjl.tools@gmail.com> writes: > diff --git a/gcc/config/m68k/m68k.h b/gcc/config/m68k/m68k.h > index 88356cc..74ebff7 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} \ That expands to a spurious --pcrel with -fno-PIE, causing the assembler to error out while compiling crtstuff if the compiler is configured with --enable-default-pie. Andreas. -- Andreas Schwab, schwab@linux-m68k.org GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 "And now for something completely different." ^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: Fwd: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option 2015-05-30 20:04 ` Andreas Schwab @ 2015-05-30 21:08 ` Andreas Schwab 0 siblings, 0 replies; 52+ messages in thread From: Andreas Schwab @ 2015-05-30 21:08 UTC (permalink / raw) To: H.J. Lu; +Cc: GCC Patches Andreas Schwab <schwab@linux-m68k.org> writes: > "H.J. Lu" <hjl.tools@gmail.com> writes: > >> diff --git a/gcc/config/m68k/m68k.h b/gcc/config/m68k/m68k.h >> index 88356cc..74ebff7 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} \ > > That expands to a spurious --pcrel with -fno-PIE, causing the assembler > to error out while compiling crtstuff if the compiler is configured with > --enable-default-pie. This was already buggy before, -fpie should always have implied --pcrel. Fixed as below. Andreas. * config/m68k/m68k.h (ASM_PCREL_SPEC): Pass --pcrel also for implict or explicit -fPIE or -fpie. diff --git a/gcc/config/m68k/m68k.h b/gcc/config/m68k/m68k.h index 74ebff7..b227c67 100644 --- a/gcc/config/m68k/m68k.h +++ b/gcc/config/m68k/m68k.h @@ -40,8 +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_SPEC ":--pcrel} \ - %{mpcrel:%{" NO_FPIC_SPEC ":--pcrel}} \ +#define ASM_PCREL_SPEC "%{" FPIE_OR_FPIC_SPEC ":--pcrel} \ + %{mpcrel:%{" NO_FPIE_AND_FPIC_SPEC ":--pcrel}} \ %{msep-data|mid-shared-library:--pcrel} \ " -- 2.4.2 -- Andreas Schwab, schwab@linux-m68k.org GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 "And now for something completely different." ^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: Fwd: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option 2015-05-22 15:39 ` Fwd: " H.J. Lu ` (2 preceding siblings ...) 2015-05-30 20:04 ` Andreas Schwab @ 2015-10-23 11:57 ` Marcus Shawcroft 2015-10-23 12:44 ` H.J. Lu 3 siblings, 1 reply; 52+ messages in thread From: Marcus Shawcroft @ 2015-10-23 11:57 UTC (permalink / raw) To: H.J. Lu; +Cc: GCC Patches Hi, This patch breaks the distinction between build and host. For example consider a configure along these lines: ./configure --host=aarch64-none-linux-gnu --target=aarch64-none-linux-gnu --build=x86_64-pc-linux-gnu Will result in: CXX_FOR_BUILD='g++' CXX='aarch64-none-linux-gnu-g++' the gcc/configure fragment: +# 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]) will check if CXX supports -no-pic and set NO_PIE_FLAG accordingly. The gcc/Makefile.in fragment: @@ -761,6 +769,7 @@ BUILD_LINKERFLAGS = $(BUILD_CXXFLAGS) # Native linker and preprocessor flags. For x-fragment overrides. BUILD_LDFLAGS=@BUILD_LDFLAGS@ +BUILD_LDFLAGS += @NO_PIE_FLAG@ constructs the flags which will ultimately be used to compile the build machines gen* programs. That compilation uses CXX_FOR_BUILD with the NO_PIE_FLAG that was originally probed for CXX. This is incorrect if CXX_FOR_BUILD != CXX HJ, could you take a look into this issue? Thanks /Marcus ^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: Fwd: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option 2015-10-23 11:57 ` Marcus Shawcroft @ 2015-10-23 12:44 ` H.J. Lu 2015-10-23 14:27 ` Marcus Shawcroft ` (2 more replies) 0 siblings, 3 replies; 52+ messages in thread From: H.J. Lu @ 2015-10-23 12:44 UTC (permalink / raw) To: Marcus Shawcroft; +Cc: GCC Patches [-- Attachment #1: Type: text/plain, Size: 1445 bytes --] On Fri, Oct 23, 2015 at 4:54 AM, Marcus Shawcroft <marcus.shawcroft@gmail.com> wrote: > Hi, > > This patch breaks the distinction between build and host. For example > consider a configure along these lines: > > ./configure --host=aarch64-none-linux-gnu > --target=aarch64-none-linux-gnu --build=x86_64-pc-linux-gnu > > Will result in: > > CXX_FOR_BUILD='g++' > CXX='aarch64-none-linux-gnu-g++' > > the gcc/configure fragment: > > +# 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]) > > will check if CXX supports -no-pic and set NO_PIE_FLAG accordingly. > The gcc/Makefile.in fragment: > > @@ -761,6 +769,7 @@ BUILD_LINKERFLAGS = $(BUILD_CXXFLAGS) > > # Native linker and preprocessor flags. For x-fragment overrides. > BUILD_LDFLAGS=@BUILD_LDFLAGS@ > +BUILD_LDFLAGS += @NO_PIE_FLAG@ > > constructs the flags which will ultimately be used to compile the > build machines gen* programs. That compilation uses CXX_FOR_BUILD > with the NO_PIE_FLAG that was originally probed for CXX. This is > incorrect if CXX_FOR_BUILD != CXX > > HJ, could you take a look into this issue? > Try this. -- H.J. [-- Attachment #2: pie.patch --] [-- Type: text/x-patch, Size: 4739 bytes --] diff --git a/gcc/Makefile.in b/gcc/Makefile.in index b91b8dc..d9d2de9 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -258,11 +258,14 @@ LINKER = $(CC) LINKER_FLAGS = $(CFLAGS) endif +NO_PIE_CFLAG = @NO_PIE_CFLAGS@ +NO_PIE_FLAG = @NO_PIE_FLAG@ + # We don't want to compile the compilers with -fPIE, it make PCH fail. -COMPILER += @NO_PIE_CFLAGS@ +COMPILER += $(NO_PIE_CFLAG) # Link with -no-pie since we compile the compiler with -fno-PIE. -LINKER += @NO_PIE_FLAG@ +LINKER += $(NO_PIE_FLAG) # Like LINKER, but use a mutex for serializing front end links. ifeq (@DO_LINK_MUTEX@,true) @@ -755,10 +758,13 @@ DIR = ../gcc # Native compiler for the build machine and its switches. CC_FOR_BUILD = @CC_FOR_BUILD@ CXX_FOR_BUILD = @CXX_FOR_BUILD@ +NO_PIE_CFLAGS_FOR_BUILD = @NO_PIE_CFLAGS_FOR_BUILD@ +NO_PIE_FLAG_FOR_BUILD = @NO_PIE_FLAG_FOR_BUILD@ BUILD_CFLAGS= @BUILD_CFLAGS@ -DGENERATOR_FILE BUILD_CXXFLAGS = @BUILD_CXXFLAGS@ -DGENERATOR_FILE -BUILD_CFLAGS += @NO_PIE_CFLAGS@ -BUILD_CXXFLAGS += @NO_PIE_CFLAGS@ +BUILD_NO_PIE_CFLAGS = @BUILD_NO_PIE_CFLAGS@ +BUILD_CFLAGS += $(BUILD_NO_PIE_CFLAGS) +BUILD_CXXFLAGS += $(BUILD_NO_PIE_CFLAGS) # Native compiler that we use. This may be C++ some day. COMPILER_FOR_BUILD = $(CXX_FOR_BUILD) @@ -770,7 +776,8 @@ BUILD_LINKERFLAGS = $(BUILD_CXXFLAGS) # Native linker and preprocessor flags. For x-fragment overrides. BUILD_LDFLAGS=@BUILD_LDFLAGS@ -BUILD_LDFLAGS += @NO_PIE_FLAG@ +BUILD_NO_PIE_FLAG = @BUILD_NO_PIE_FLAG@ +BUILD_LDFLAGS += $(BUILD_NO_PIE_FLAG) BUILD_CPPFLAGS= -I. -I$(@D) -I$(srcdir) -I$(srcdir)/$(@D) \ -I$(srcdir)/../include @INCINTL@ $(CPPINC) $(CPPFLAGS) diff --git a/gcc/configure b/gcc/configure index 3122499..92bda6c 100755 --- a/gcc/configure +++ b/gcc/configure @@ -707,6 +707,10 @@ FGREP SED LIBTOOL collect2 +NO_PIE_FLAG_FOR_BUILD +NO_PIE_CFLAGS_FOR_BUILD +BUILD_NO_PIE_FLAG +BUILD_NO_PIE_CFLAGS STMP_FIXINC BUILD_LDFLAGS BUILD_CXXFLAGS @@ -7096,7 +7100,8 @@ if test x$ac_checking != x ; then $as_echo "#define ENABLE_CHECKING 1" >>confdefs.h - $as_echo "#define CHECKING_P 1" >>confdefs.h + +$as_echo "#define CHECKING_P 1" >>confdefs.h nocommon_flag=-fno-common else @@ -12253,14 +12258,24 @@ BUILD_CXXFLAGS='$(ALL_CXXFLAGS)' BUILD_LDFLAGS='$(LDFLAGS)' STMP_FIXINC=stmp-fixinc +BUILD_NO_PIE_CFLAGS='$(NO_PIE_CFLAGS)' +BUILD_NO_PIE_FLAG='$(NO_PIE_FLAG)' + # And these apply if build != host, or we are generating coverage data if test x$build != x$host || test "x$coverage_flags" != x then BUILD_CFLAGS='$(INTERNAL_CFLAGS) $(T_CFLAGS) $(CFLAGS_FOR_BUILD)' BUILD_CXXFLAGS='$(INTERNAL_CFLAGS) $(T_CFLAGS) $(CXXFLAGS_FOR_BUILD)' BUILD_LDFLAGS='$(LDFLAGS_FOR_BUILD)' + + NO_PIE_CFLAGS_FOR_BUILD=${NO_PIE_CFLAGS_FOR_BUILD-${NO_PIE_CFLAGS}} + NO_PIE_FLAG_FOR_BUILD=${NO_PIE_FLAG_FOR_BUILD-${NO_PIE_FLAG}} + BUILD_NO_PIE_CFLAGS='$(NO_PIE_CFLAGS_FOR_BUILD)' + BUILD_NO_PIE_FLAG='$(NO_PIE_FLAG_FOR_BUILD)' fi + + # Expand extra_headers to include complete path. # This substitutes for lots of t-* files. extra_headers_list= @@ -18390,7 +18405,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 18393 "configure" +#line 18408 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -18496,7 +18511,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 18499 "configure" +#line 18514 "configure" #include "confdefs.h" #if HAVE_DLFCN_H diff --git a/gcc/configure.ac b/gcc/configure.ac index a30bb3b..7e22267 100644 --- a/gcc/configure.ac +++ b/gcc/configure.ac @@ -2041,13 +2041,23 @@ BUILD_CXXFLAGS='$(ALL_CXXFLAGS)' AC_SUBST(BUILD_CXXFLAGS) BUILD_LDFLAGS='$(LDFLAGS)' AC_SUBST(BUILD_LDFLAGS) STMP_FIXINC=stmp-fixinc AC_SUBST(STMP_FIXINC) +BUILD_NO_PIE_CFLAGS='$(NO_PIE_CFLAGS)' AC_SUBST(BUILD_NO_PIE_CFLAGS) +BUILD_NO_PIE_FLAG='$(NO_PIE_FLAG)' AC_SUBST(BUILD_NO_PIE_FLAG) + # And these apply if build != host, or we are generating coverage data if test x$build != x$host || test "x$coverage_flags" != x then BUILD_CFLAGS='$(INTERNAL_CFLAGS) $(T_CFLAGS) $(CFLAGS_FOR_BUILD)' BUILD_CXXFLAGS='$(INTERNAL_CFLAGS) $(T_CFLAGS) $(CXXFLAGS_FOR_BUILD)' BUILD_LDFLAGS='$(LDFLAGS_FOR_BUILD)' + + NO_PIE_CFLAGS_FOR_BUILD=${NO_PIE_CFLAGS_FOR_BUILD-${NO_PIE_CFLAGS}} + NO_PIE_FLAG_FOR_BUILD=${NO_PIE_FLAG_FOR_BUILD-${NO_PIE_FLAG}} + BUILD_NO_PIE_CFLAGS='$(NO_PIE_CFLAGS_FOR_BUILD)' + BUILD_NO_PIE_FLAG='$(NO_PIE_FLAG_FOR_BUILD)' fi +AC_SUBST(NO_PIE_CFLAGS_FOR_BUILD) +AC_SUBST(NO_PIE_FLAG_FOR_BUILD) # Expand extra_headers to include complete path. # This substitutes for lots of t-* files. ^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: Fwd: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option 2015-10-23 12:44 ` H.J. Lu @ 2015-10-23 14:27 ` Marcus Shawcroft 2015-10-28 16:06 ` Marcus Shawcroft 2015-10-29 11:02 ` Richard Earnshaw 2 siblings, 0 replies; 52+ messages in thread From: Marcus Shawcroft @ 2015-10-23 14:27 UTC (permalink / raw) To: H.J. Lu; +Cc: GCC Patches On 23 October 2015 at 13:34, H.J. Lu <hjl.tools@gmail.com> wrote: > On Fri, Oct 23, 2015 at 4:54 AM, Marcus Shawcroft > <marcus.shawcroft@gmail.com> wrote: >> Hi, >> >> This patch breaks the distinction between build and host. For example >> consider a configure along these lines: >> >> ./configure --host=aarch64-none-linux-gnu >> --target=aarch64-none-linux-gnu --build=x86_64-pc-linux-gnu >> HJ, could you take a look into this issue? >> > > Try this. Thanks HJ. This solves the issue I was seeing. Cheers /Marcus ^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: Fwd: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option 2015-10-23 12:44 ` H.J. Lu 2015-10-23 14:27 ` Marcus Shawcroft @ 2015-10-28 16:06 ` Marcus Shawcroft 2015-10-29 11:02 ` Richard Earnshaw 2 siblings, 0 replies; 52+ messages in thread From: Marcus Shawcroft @ 2015-10-28 16:06 UTC (permalink / raw) To: H.J. Lu, bonzini; +Cc: GCC Patches On 23 October 2015 at 13:34, H.J. Lu <hjl.tools@gmail.com> wrote: > On Fri, Oct 23, 2015 at 4:54 AM, Marcus Shawcroft > <marcus.shawcroft@gmail.com> wrote: >> Hi, >> >> This patch breaks the distinction between build and host. For example >> consider a configure along these lines: >> >> ./configure --host=aarch64-none-linux-gnu >> --target=aarch64-none-linux-gnu --build=x86_64-pc-linux-gnu >> HJ, could you take a look into this issue? >> > > Try this. Hi, Can we get a review from one of the build machinery maintainers for this patch? Cheers /Marcus ^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: Fwd: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option 2015-10-23 12:44 ` H.J. Lu 2015-10-23 14:27 ` Marcus Shawcroft 2015-10-28 16:06 ` Marcus Shawcroft @ 2015-10-29 11:02 ` Richard Earnshaw 2015-10-29 11:18 ` H.J. Lu 2 siblings, 1 reply; 52+ messages in thread From: Richard Earnshaw @ 2015-10-29 11:02 UTC (permalink / raw) To: H.J. Lu, Marcus Shawcroft; +Cc: GCC Patches On 23/10/15 13:34, H.J. Lu wrote: > On Fri, Oct 23, 2015 at 4:54 AM, Marcus Shawcroft > <marcus.shawcroft@gmail.com> wrote: >> Hi, >> >> This patch breaks the distinction between build and host. For example >> consider a configure along these lines: >> >> ./configure --host=aarch64-none-linux-gnu >> --target=aarch64-none-linux-gnu --build=x86_64-pc-linux-gnu >> >> Will result in: >> >> CXX_FOR_BUILD='g++' >> CXX='aarch64-none-linux-gnu-g++' >> >> the gcc/configure fragment: >> >> +# 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]) >> >> will check if CXX supports -no-pic and set NO_PIE_FLAG accordingly. >> The gcc/Makefile.in fragment: >> >> @@ -761,6 +769,7 @@ BUILD_LINKERFLAGS = $(BUILD_CXXFLAGS) >> >> # Native linker and preprocessor flags. For x-fragment overrides. >> BUILD_LDFLAGS=@BUILD_LDFLAGS@ >> +BUILD_LDFLAGS += @NO_PIE_FLAG@ >> >> constructs the flags which will ultimately be used to compile the >> build machines gen* programs. That compilation uses CXX_FOR_BUILD >> with the NO_PIE_FLAG that was originally probed for CXX. This is >> incorrect if CXX_FOR_BUILD != CXX >> >> HJ, could you take a look into this issue? >> > > Try this. > Where's the ChangeLog? R. > > pie.patch > > > diff --git a/gcc/Makefile.in b/gcc/Makefile.in > index b91b8dc..d9d2de9 100644 > --- a/gcc/Makefile.in > +++ b/gcc/Makefile.in > @@ -258,11 +258,14 @@ LINKER = $(CC) > LINKER_FLAGS = $(CFLAGS) > endif > > +NO_PIE_CFLAG = @NO_PIE_CFLAGS@ > +NO_PIE_FLAG = @NO_PIE_FLAG@ > + > # We don't want to compile the compilers with -fPIE, it make PCH fail. > -COMPILER += @NO_PIE_CFLAGS@ > +COMPILER += $(NO_PIE_CFLAG) > > # Link with -no-pie since we compile the compiler with -fno-PIE. > -LINKER += @NO_PIE_FLAG@ > +LINKER += $(NO_PIE_FLAG) > > # Like LINKER, but use a mutex for serializing front end links. > ifeq (@DO_LINK_MUTEX@,true) > @@ -755,10 +758,13 @@ DIR = ../gcc > # Native compiler for the build machine and its switches. > CC_FOR_BUILD = @CC_FOR_BUILD@ > CXX_FOR_BUILD = @CXX_FOR_BUILD@ > +NO_PIE_CFLAGS_FOR_BUILD = @NO_PIE_CFLAGS_FOR_BUILD@ > +NO_PIE_FLAG_FOR_BUILD = @NO_PIE_FLAG_FOR_BUILD@ > BUILD_CFLAGS= @BUILD_CFLAGS@ -DGENERATOR_FILE > BUILD_CXXFLAGS = @BUILD_CXXFLAGS@ -DGENERATOR_FILE > -BUILD_CFLAGS += @NO_PIE_CFLAGS@ > -BUILD_CXXFLAGS += @NO_PIE_CFLAGS@ > +BUILD_NO_PIE_CFLAGS = @BUILD_NO_PIE_CFLAGS@ > +BUILD_CFLAGS += $(BUILD_NO_PIE_CFLAGS) > +BUILD_CXXFLAGS += $(BUILD_NO_PIE_CFLAGS) > > # Native compiler that we use. This may be C++ some day. > COMPILER_FOR_BUILD = $(CXX_FOR_BUILD) > @@ -770,7 +776,8 @@ BUILD_LINKERFLAGS = $(BUILD_CXXFLAGS) > > # Native linker and preprocessor flags. For x-fragment overrides. > BUILD_LDFLAGS=@BUILD_LDFLAGS@ > -BUILD_LDFLAGS += @NO_PIE_FLAG@ > +BUILD_NO_PIE_FLAG = @BUILD_NO_PIE_FLAG@ > +BUILD_LDFLAGS += $(BUILD_NO_PIE_FLAG) > BUILD_CPPFLAGS= -I. -I$(@D) -I$(srcdir) -I$(srcdir)/$(@D) \ > -I$(srcdir)/../include @INCINTL@ $(CPPINC) $(CPPFLAGS) > > diff --git a/gcc/configure b/gcc/configure > index 3122499..92bda6c 100755 > --- a/gcc/configure > +++ b/gcc/configure > @@ -707,6 +707,10 @@ FGREP > SED > LIBTOOL > collect2 > +NO_PIE_FLAG_FOR_BUILD > +NO_PIE_CFLAGS_FOR_BUILD > +BUILD_NO_PIE_FLAG > +BUILD_NO_PIE_CFLAGS > STMP_FIXINC > BUILD_LDFLAGS > BUILD_CXXFLAGS > @@ -7096,7 +7100,8 @@ if test x$ac_checking != x ; then > > $as_echo "#define ENABLE_CHECKING 1" >>confdefs.h > > - $as_echo "#define CHECKING_P 1" >>confdefs.h > + > +$as_echo "#define CHECKING_P 1" >>confdefs.h > > nocommon_flag=-fno-common > else > @@ -12253,14 +12258,24 @@ BUILD_CXXFLAGS='$(ALL_CXXFLAGS)' > BUILD_LDFLAGS='$(LDFLAGS)' > STMP_FIXINC=stmp-fixinc > > +BUILD_NO_PIE_CFLAGS='$(NO_PIE_CFLAGS)' > +BUILD_NO_PIE_FLAG='$(NO_PIE_FLAG)' > + > # And these apply if build != host, or we are generating coverage data > if test x$build != x$host || test "x$coverage_flags" != x > then > BUILD_CFLAGS='$(INTERNAL_CFLAGS) $(T_CFLAGS) $(CFLAGS_FOR_BUILD)' > BUILD_CXXFLAGS='$(INTERNAL_CFLAGS) $(T_CFLAGS) $(CXXFLAGS_FOR_BUILD)' > BUILD_LDFLAGS='$(LDFLAGS_FOR_BUILD)' > + > + NO_PIE_CFLAGS_FOR_BUILD=${NO_PIE_CFLAGS_FOR_BUILD-${NO_PIE_CFLAGS}} > + NO_PIE_FLAG_FOR_BUILD=${NO_PIE_FLAG_FOR_BUILD-${NO_PIE_FLAG}} > + BUILD_NO_PIE_CFLAGS='$(NO_PIE_CFLAGS_FOR_BUILD)' > + BUILD_NO_PIE_FLAG='$(NO_PIE_FLAG_FOR_BUILD)' > fi > > + > + > # Expand extra_headers to include complete path. > # This substitutes for lots of t-* files. > extra_headers_list= > @@ -18390,7 +18405,7 @@ else > lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 > lt_status=$lt_dlunknown > cat > conftest.$ac_ext <<_LT_EOF > -#line 18393 "configure" > +#line 18408 "configure" > #include "confdefs.h" > > #if HAVE_DLFCN_H > @@ -18496,7 +18511,7 @@ else > lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 > lt_status=$lt_dlunknown > cat > conftest.$ac_ext <<_LT_EOF > -#line 18499 "configure" > +#line 18514 "configure" > #include "confdefs.h" > > #if HAVE_DLFCN_H > diff --git a/gcc/configure.ac b/gcc/configure.ac > index a30bb3b..7e22267 100644 > --- a/gcc/configure.ac > +++ b/gcc/configure.ac > @@ -2041,13 +2041,23 @@ BUILD_CXXFLAGS='$(ALL_CXXFLAGS)' AC_SUBST(BUILD_CXXFLAGS) > BUILD_LDFLAGS='$(LDFLAGS)' AC_SUBST(BUILD_LDFLAGS) > STMP_FIXINC=stmp-fixinc AC_SUBST(STMP_FIXINC) > > +BUILD_NO_PIE_CFLAGS='$(NO_PIE_CFLAGS)' AC_SUBST(BUILD_NO_PIE_CFLAGS) > +BUILD_NO_PIE_FLAG='$(NO_PIE_FLAG)' AC_SUBST(BUILD_NO_PIE_FLAG) > + > # And these apply if build != host, or we are generating coverage data > if test x$build != x$host || test "x$coverage_flags" != x > then > BUILD_CFLAGS='$(INTERNAL_CFLAGS) $(T_CFLAGS) $(CFLAGS_FOR_BUILD)' > BUILD_CXXFLAGS='$(INTERNAL_CFLAGS) $(T_CFLAGS) $(CXXFLAGS_FOR_BUILD)' > BUILD_LDFLAGS='$(LDFLAGS_FOR_BUILD)' > + > + NO_PIE_CFLAGS_FOR_BUILD=${NO_PIE_CFLAGS_FOR_BUILD-${NO_PIE_CFLAGS}} > + NO_PIE_FLAG_FOR_BUILD=${NO_PIE_FLAG_FOR_BUILD-${NO_PIE_FLAG}} > + BUILD_NO_PIE_CFLAGS='$(NO_PIE_CFLAGS_FOR_BUILD)' > + BUILD_NO_PIE_FLAG='$(NO_PIE_FLAG_FOR_BUILD)' > fi > +AC_SUBST(NO_PIE_CFLAGS_FOR_BUILD) > +AC_SUBST(NO_PIE_FLAG_FOR_BUILD) > > # Expand extra_headers to include complete path. > # This substitutes for lots of t-* files. > ^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: Fwd: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option 2015-10-29 11:02 ` Richard Earnshaw @ 2015-10-29 11:18 ` H.J. Lu 0 siblings, 0 replies; 52+ messages in thread From: H.J. Lu @ 2015-10-29 11:18 UTC (permalink / raw) To: Richard Earnshaw; +Cc: Marcus Shawcroft, GCC Patches On Thu, Oct 29, 2015 at 4:00 AM, Richard Earnshaw <Richard.Earnshaw@foss.arm.com> wrote: > On 23/10/15 13:34, H.J. Lu wrote: >> On Fri, Oct 23, 2015 at 4:54 AM, Marcus Shawcroft >> <marcus.shawcroft@gmail.com> wrote: >>> Hi, >>> >>> This patch breaks the distinction between build and host. For example >>> consider a configure along these lines: >>> >>> ./configure --host=aarch64-none-linux-gnu >>> --target=aarch64-none-linux-gnu --build=x86_64-pc-linux-gnu >>> >>> Will result in: >>> >>> CXX_FOR_BUILD='g++' >>> CXX='aarch64-none-linux-gnu-g++' >>> >>> the gcc/configure fragment: >>> >>> +# 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]) >>> >>> will check if CXX supports -no-pic and set NO_PIE_FLAG accordingly. >>> The gcc/Makefile.in fragment: >>> >>> @@ -761,6 +769,7 @@ BUILD_LINKERFLAGS = $(BUILD_CXXFLAGS) >>> >>> # Native linker and preprocessor flags. For x-fragment overrides. >>> BUILD_LDFLAGS=@BUILD_LDFLAGS@ >>> +BUILD_LDFLAGS += @NO_PIE_FLAG@ >>> >>> constructs the flags which will ultimately be used to compile the >>> build machines gen* programs. That compilation uses CXX_FOR_BUILD >>> with the NO_PIE_FLAG that was originally probed for CXX. This is >>> incorrect if CXX_FOR_BUILD != CXX >>> >>> HJ, could you take a look into this issue? >>> >> >> Try this. >> > > Where's the ChangeLog? > You can follow up here: https://gcc.gnu.org/ml/gcc-patches/2015-10/msg02468.html -- H.J. ^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option 2015-05-19 19:33 ` H.J. Lu ` (3 preceding siblings ...) [not found] ` <CAMe9rOpZow4w3zcycLoTb5LZdLKP2QWNpsU5oLMJCyZGUTd1fg@mail.gmail.com> @ 2015-06-10 13:26 ` Rainer Orth 4 siblings, 0 replies; 52+ messages in thread From: Rainer Orth @ 2015-06-10 13:26 UTC (permalink / raw) To: H.J. Lu; +Cc: Joseph Myers, Magnus Granberg, GCC Patches "H.J. Lu" <hjl.tools@gmail.com> writes: > On Tue, May 19, 2015 at 8:33 AM, Joseph Myers <joseph@codesourcery.com> wrote: >> On Tue, 19 May 2015, H.J. Lu wrote: >> >>> > I think the whole thing should be posted as one patch, with both the >>> > target-independent changes and the target-specific changes for all >>> > targets. >>> > >>> >>> That is what makes me concerned. I have some simple target-specified >>> patches which weren't reviewed for years. What will happen if no one >> >> For any unreviewed patch, keep pinging weekly. >> >>> reviews some simple target-specified changes due to >>> >>> 1. Reviewers don't have access to those targets. >>> 2. Target maintainers aren't review them. >>> 3. There are no clear maintainers for those targets. >> >> I've already said in >> <https://gcc.gnu.org/ml/gcc-patches/2015-05/msg00593.html> that, given >> target maintainers CC:ed, I might be inclined to approve the patch on the >> basis of allowing them a week to test their target changes. >> > > Here is the complete patch. Tested on Linux/x86-64. It is also > available on hjl/pie/master branch in git mirror. I just noticed that with --enable-default-pie, while crtbeginS.o is linked into the executable, crtend.o is used, while with an explicit -pie, crtendS.o is taken. Shouldn't GNU_USER_TARGET_ENDFILE_SPEC have the same treatment as GNU_USER_TARGET_STARTFILE_SPEC already did? * config/gnu-user.h (GNU_USER_TARGET_STARTFILE_SPEC): Use PIE_SPEC and NO_PIE_SPEC if HAVE_LD_PIE is defined. Rainer -- ----------------------------------------------------------------------------- Rainer Orth, Center for Biotechnology, Bielefeld University ^ permalink raw reply [flat|nested] 52+ messages in thread
* RE: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option 2015-05-08 17:35 ` H.J. Lu 2015-05-18 22:53 ` Magnus Granberg @ 2015-05-26 23:09 ` Matthew Fortune 2015-05-27 2:49 ` Matthew Fortune 2015-05-27 4:59 ` H.J. Lu 1 sibling, 2 replies; 52+ messages in thread From: Matthew Fortune @ 2015-05-26 23:09 UTC (permalink / raw) To: H.J. Lu, Joseph Myers Cc: Richard Biener, Magnus Granberg, GCC Patches, danielmicay The change for MIPS looks fine by visual inspection and I've built both a default pie and default no-pie compiler. The default pie won't build glibc but I am pretty sure it is not down to this patch. I haven't had time to look into why it won't build though, something related to selecting the CRT files. Thanks, Matthew ^ permalink raw reply [flat|nested] 52+ messages in thread
* RE: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option 2015-05-26 23:09 ` Matthew Fortune @ 2015-05-27 2:49 ` Matthew Fortune 2015-05-27 4:59 ` H.J. Lu 1 sibling, 0 replies; 52+ messages in thread From: Matthew Fortune @ 2015-05-27 2:49 UTC (permalink / raw) To: H.J. Lu, Joseph Myers Cc: Richard Biener, Magnus Granberg, GCC Patches, danielmicay The change for MIPS looks fine by visual inspection and I've built both a default pie and default no-pie compiler. The default pie won't build glibc but I am pretty sure it is not down to this patch. I haven't had time to look into why it won't build though, something related to selecting the CRT files. Thanks, Matthew ^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option 2015-05-26 23:09 ` Matthew Fortune 2015-05-27 2:49 ` Matthew Fortune @ 2015-05-27 4:59 ` H.J. Lu 1 sibling, 0 replies; 52+ messages in thread From: H.J. Lu @ 2015-05-27 4:59 UTC (permalink / raw) To: Matthew Fortune Cc: Joseph Myers, Richard Biener, Magnus Granberg, GCC Patches, danielmicay On Tue, May 26, 2015 at 3:11 PM, Matthew Fortune <Matthew.Fortune@imgtec.com> wrote: > The change for MIPS looks fine by visual inspection and I've built both > a default pie and default no-pie compiler. The default pie won't build > glibc but I am pretty sure it is not down to this patch. I haven't had > time to look into why it won't build though, something related to > selecting the CRT files. It is: https://sourceware.org/bugzilla/show_bug.cgi?id=17841 I will submit my glibc patch after GCC change is checked in. -- H.J. ^ permalink raw reply [flat|nested] 52+ messages in thread
end of thread, other threads:[~2015-10-29 11:16 UTC | newest] Thread overview: 52+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2015-03-06 17:31 PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option H.J. Lu 2015-03-06 20:22 ` Magnus Granberg 2015-03-06 20:25 ` H.J. Lu 2015-05-07 21:17 ` Joseph Myers 2015-05-08 17:35 ` H.J. Lu 2015-05-18 22:53 ` Magnus Granberg 2015-05-19 1:25 ` Joseph Myers 2015-05-19 1:34 ` H.J. Lu 2015-05-19 15:27 ` Joseph Myers 2015-05-19 15:33 ` H.J. Lu 2015-05-19 15:33 ` Paul_Koning 2015-05-19 15:43 ` H.J. Lu 2015-05-19 15:37 ` Joseph Myers 2015-05-19 19:33 ` H.J. Lu 2015-05-20 21:29 ` Joseph Myers 2015-05-20 23:01 ` Hans-Peter Nilsson 2015-05-20 23:54 ` H.J. Lu 2015-05-21 14:42 ` Rainer Orth 2015-05-21 17:19 ` Joseph Myers 2015-05-21 17:57 ` H.J. Lu 2015-06-03 12:48 ` Rainer Orth [not found] ` <CAMe9rOpZow4w3zcycLoTb5LZdLKP2QWNpsU5oLMJCyZGUTd1fg@mail.gmail.com> [not found] ` <87vbflkh05.fsf@igel.home> [not found] ` <CAMe9rOr0SApdtzeOrc-uNDRH8=z6c4EzHUkyXmERW_q9BYjrAQ@mail.gmail.com> [not found] ` <87k2w1k54t.fsf@igel.home> 2015-05-22 15:39 ` Fwd: " H.J. Lu 2015-05-26 22:42 ` Bill Schmidt 2015-05-26 22:53 ` Bill Schmidt 2015-05-27 15:42 ` Peter Bergner 2015-05-27 15:59 ` H.J. Lu 2015-05-27 16:17 ` Peter Bergner 2015-05-27 16:34 ` H.J. Lu 2015-05-27 17:43 ` David Edelsohn 2015-05-27 17:44 ` H.J. Lu 2015-05-30 15:45 ` Andreas Schwab 2015-05-30 16:24 ` H.J. Lu 2015-05-30 16:44 ` Andreas Schwab 2015-05-30 17:04 ` H.J. Lu 2015-05-30 20:08 ` Andreas Schwab 2015-05-30 21:42 ` H.J. Lu 2015-05-31 0:52 ` Andreas Schwab 2015-05-31 7:13 ` H.J. Lu 2015-05-31 8:23 ` Andreas Schwab 2015-05-31 15:52 ` H.J. Lu 2015-05-30 20:04 ` Andreas Schwab 2015-05-30 21:08 ` Andreas Schwab 2015-10-23 11:57 ` Marcus Shawcroft 2015-10-23 12:44 ` H.J. Lu 2015-10-23 14:27 ` Marcus Shawcroft 2015-10-28 16:06 ` Marcus Shawcroft 2015-10-29 11:02 ` Richard Earnshaw 2015-10-29 11:18 ` H.J. Lu 2015-06-10 13:26 ` Rainer Orth 2015-05-26 23:09 ` Matthew Fortune 2015-05-27 2:49 ` Matthew Fortune 2015-05-27 4:59 ` H.J. Lu
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).