This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option

"H.J. Lu" <> 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 out
of the submission: it simplifies review.

diff --git a/gcc/ b/gcc/
index ab9b637..e429274 100644
--- a/gcc/
+++ b/gcc/
@@ -253,6 +253,12 @@ LINKER = $(CC)
+# We don't want to compile the compiler with -fPIE, it make PCH fail.

@@ -750,6 +756,8 @@ CC_FOR_BUILD = @CC_FOR_BUILD@
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.

 # Native linker and preprocessor flags.  For x-fragment overrides.


 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 \
+	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/ b/gcc/ada/gcc-interface/
index ecc443e..90aedb5 100644
--- a/gcc/ada/gcc-interface/
+++ b/gcc/ada/gcc-interface/
@@ -267,6 +267,9 @@ TOOLS_LIBS = ../link.o ../targext.o ../../ggc-none.o ../../libcommon-target.a \
   ../../libcommon.a ../../../libcpp/libcpp.a $(LIBGNAT) $(LIBINTL) $(LIBICONV) \
+# Add -no-pie to TOOLS_LIBS since some of them are compiled with -fno-PIE.

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

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;

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 Orth, Center for Biotechnology, Bielefeld University

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]