Submitted By: Robert Connolly <robert at linuxfromscratch dot org> (ashes)
Date: 2005-02-01
Initial Package Version: 3.4.3
Upstream Status: Not submitted
Origin: None
Description: Use gcc -fpie, -fpic, and ld -pie, -z relro, -z now.
This patch also fixes it so 'make BOOT_CFLAGS' and 'BOOT_LDFLAGS' are not
needed. It does 'BOOT_CFLAGS=$(CFLAGS)'.

See:
http://www.linuxfromscratch.org/~robert/Homogenic/

diff -Naur gcc-3.4.3.orig/Makefile.in gcc-3.4.3/Makefile.in
--- gcc-3.4.3.orig/Makefile.in	2004-11-05 04:14:05.000000000 +0000
+++ gcc-3.4.3/Makefile.in	2005-02-01 04:10:20.185976544 +0000
@@ -229,7 +229,7 @@
 NM = @NM@
 
 LD = @LD@
-LDFLAGS = 
+LDFLAGS = -z relro -z now -pie
 
 RANLIB = @RANLIB@
 
@@ -428,17 +428,11 @@
 	"SHELL=$(SHELL)" \
 	"YACC=$(YACC)" \
 	"AR_FLAGS=$(AR_FLAGS)" \
-	"CFLAGS=$(CFLAGS)" \
-	"CXXFLAGS=$(CXXFLAGS)" \
 	"LDFLAGS=$(LDFLAGS)" \
-	"LIBCFLAGS=$(LIBCFLAGS)" \
-	"LIBCXXFLAGS=$(LIBCXXFLAGS)" \
 	"AR_FOR_TARGET=$(AR_FOR_TARGET)" \
 	"AS_FOR_TARGET=$(AS_FOR_TARGET)" \
 	"CC_FOR_TARGET=$(CC_FOR_TARGET)" \
-	"CFLAGS_FOR_TARGET=$(CFLAGS_FOR_TARGET)" \
 	"CXX_FOR_TARGET=$(CXX_FOR_TARGET)" \
-	"CXXFLAGS_FOR_TARGET=$(CXXFLAGS_FOR_TARGET)" \
 	"DLLTOOL_FOR_TARGET=$(DLLTOOL_FOR_TARGET)" \
 	"GCJ_FOR_TARGET=$(GCJ_FOR_TARGET)" \
 	"LD_FOR_TARGET=$(LD_FOR_TARGET)" \
@@ -493,13 +487,9 @@
 	'AR=$$(AR_FOR_TARGET)' \
 	'AS=$$(AS_FOR_TARGET)' \
 	'CC=$$(CC_FOR_TARGET)' \
-	'CFLAGS=$$(CFLAGS_FOR_TARGET)' \
 	'CXX=$$(CXX_FOR_TARGET)' \
-	'CXXFLAGS=$$(CXXFLAGS_FOR_TARGET)' \
 	'DLLTOOL=$$(DLLTOOL_FOR_TARGET)' \
 	'LD=$$(LD_FOR_TARGET)' \
-	'LIBCFLAGS=$$(LIBCFLAGS_FOR_TARGET)' \
-	'LIBCXXFLAGS=$$(LIBCXXFLAGS_FOR_TARGET)' \
 	'NM=$$(NM_FOR_TARGET)' \
 	'RANLIB=$$(RANLIB_FOR_TARGET)' \
 	'WINDRES=$$(WINDRES_FOR_TARGET)'
@@ -516,11 +506,9 @@
 	'BUILD_PREFIX=$(BUILD_PREFIX)' \
 	'BUILD_PREFIX_1=$(BUILD_PREFIX_1)' \
 	"GCC_FOR_TARGET=$(GCC_FOR_TARGET)" \
-	"CFLAGS_FOR_BUILD=$(CFLAGS_FOR_BUILD)" \
 	"`echo 'LANGUAGES=$(LANGUAGES)' | sed -e s/.*=$$/XFOO=/`" \
 	"`echo 'STMP_FIXPROTO=$(STMP_FIXPROTO)' | sed -e s/.*=$$/XFOO=/`" \
 	"`echo 'LIMITS_H_TEST=$(LIMITS_H_TEST)' | sed -e s/.*=$$/XFOO=/`" \
-	"`echo 'LIBGCC2_CFLAGS=$(LIBGCC2_CFLAGS)' | sed -e s/.*=$$/XFOO=/`" \
 	"`echo 'LIBGCC2_DEBUG_CFLAGS=$(LIBGCC2_DEBUG_CFLAGS)' | sed -e s/.*=$$/XFOO=/`" \
 	"`echo 'LIBGCC2_INCLUDES=$(LIBGCC2_INCLUDES)' | sed -e s/.*=$$/XFOO=/`" \
 	"`echo 'STAGE1_CFLAGS=$(STAGE1_CFLAGS)' | sed -e s/.*=$$/XFOO=/`" \
diff -Naur gcc-3.4.3.orig/gcc/Makefile.in gcc-3.4.3/gcc/Makefile.in
--- gcc-3.4.3.orig/gcc/Makefile.in	2004-10-18 16:00:39.000000000 +0000
+++ gcc-3.4.3/gcc/Makefile.in	2005-02-01 04:15:30.038448392 +0000
@@ -138,9 +138,11 @@
 # TCFLAGS is used for compilations with the GCC just built.
 XCFLAGS =
 TCFLAGS =
-CFLAGS = -g
+CFLAGS = @CFLAGS@ -pie -fpie -fstack-protector-all
+LIBCFLAGS = @CFLAGS@ -fpic -fstack-protector-all
 STAGE1_CFLAGS = -g @stage1_cflags@
-BOOT_CFLAGS = -g -O2
+BOOT_CFLAGS = $(CFLAGS)
+BOOT_LDFLAGS = $(LDFLAGS)
 
 # Flags to determine code coverage. When coverage is disabled, this will
 # contain the optimization flags, as you normally want code coverage
@@ -291,7 +293,8 @@
 # This is used instead of ALL_CFLAGS when compiling with GCC_FOR_TARGET.
 # It omits XCFLAGS, and specifies -B./.
 # It also specifies -isystem ./include to find, e.g., stddef.h.
-GCC_CFLAGS=$(INTERNAL_CFLAGS) $(X_CFLAGS) $(T_CFLAGS) $(LOOSE_WARN) -Wold-style-definition $($@-warn) -isystem ./include $(TCFLAGS)
+GCC_CFLAGS=$(INTERNAL_CFLAGS) $(CFLAGS) $(X_CFLAGS) $(T_CFLAGS) $(LOOSE_WARN) -Wold-style-definition $($@-warn) -isystem ./include $(TCFLAGS)
+GCC_LIBCFLAGS=$(INTERNAL_CFLAGS) $(LIBCFLAGS) $(X_CFLAGS) $(T_CFLAGS) $(LOOSE_WARN) -Wold-style-definition $($@-warn) -isystem ./include $(TCFLAGS)
 
 # ---------------------------------------------------
 # Programs which produce files for the target machine
@@ -488,7 +491,7 @@
 # Options to use when compiling libgcc2.a.
 #
 LIBGCC2_DEBUG_CFLAGS = -g
-LIBGCC2_CFLAGS = -O2 $(LIBGCC2_INCLUDES) $(GCC_CFLAGS) $(TARGET_LIBGCC2_CFLAGS) $(LIBGCC2_DEBUG_CFLAGS) $(GTHREAD_FLAGS) -DIN_LIBGCC2 -D__GCC_FLOAT_NOT_NEEDED @inhibit_libc@
+LIBGCC2_CFLAGS = -O2 $(LIBGCC2_INCLUDES) $(GCC_LIBCFLAGS) $(TARGET_LIBGCC2_CFLAGS) $(LIBGCC2_DEBUG_CFLAGS) $(GTHREAD_FLAGS) -DIN_LIBGCC2 -D__GCC_FLOAT_NOT_NEEDED @inhibit_libc@
 
 # Additional options to use when compiling libgcc2.a.
 # Some targets override this to -isystem include
diff -Naur gcc-3.4.3.orig/libiberty/Makefile.in gcc-3.4.3/libiberty/Makefile.in
--- gcc-3.4.3.orig/libiberty/Makefile.in	2004-01-14 21:27:28.000000000 +0000
+++ gcc-3.4.3/libiberty/Makefile.in	2005-02-01 04:16:00.843765272 +0000
@@ -60,7 +60,7 @@
 AR_FLAGS = rc
 
 CC = @CC@
-CFLAGS = @CFLAGS@
+CFLAGS = @CFLAGS@ -fpic -fstack-protector-all
 LIBCFLAGS = $(CFLAGS)
 RANLIB = @RANLIB@
 MAKEINFO = @MAKEINFO@
diff -Naur gcc-3.4.3.orig/libstdc++-v3/Makefile.in gcc-3.4.3/libstdc++-v3/Makefile.in
--- gcc-3.4.3.orig/libstdc++-v3/Makefile.in	2004-03-18 17:35:12.000000000 +0000
+++ gcc-3.4.3/libstdc++-v3/Makefile.in	2005-02-01 04:16:27.335737880 +0000
@@ -57,7 +57,7 @@
 CCODECVT_H = @CCODECVT_H@
 CCOLLATE_CC = @CCOLLATE_CC@
 CCTYPE_CC = @CCTYPE_CC@
-CFLAGS = @CFLAGS@
+CFLAGS = @CFLAGS@ -fpic -fstack-protector-all
 CLOCALE_CC = @CLOCALE_CC@
 CLOCALE_H = @CLOCALE_H@
 CLOCALE_INTERNAL_H = @CLOCALE_INTERNAL_H@
@@ -72,7 +72,7 @@
 CTIME_H = @CTIME_H@
 CXX = @CXX@
 CXXCPP = @CXXCPP@
-CXXFLAGS = @CXXFLAGS@
+CXXFLAGS = @CXXFLAGS@ -fpic -fstack-protector-all
 CYGPATH_W = @CYGPATH_W@
 C_INCLUDE_DIR = @C_INCLUDE_DIR@
 DEBUG_FLAGS = @DEBUG_FLAGS@
