aboutsummaryrefslogtreecommitdiff
blob: c3e18bdf46a80a1fa941a295c997a795d02eb62c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
2011-12-21	Magnus Granberg		<zorry@gentoo.org> Anthony G. Basile	<basile@opensource.dyc.edu>

		* Makefile.in	We add -fno-stack-protector to BOOT_CFLAGS, LIBCFLAGS and LIBCXXFLAGS if enable_esp yes.
		* gcc/Makefile.in	Add -fno-PIE and -fno-stack-protector.
	    Libgcc2 doesn't compile with -fstack-protector.
	    Crtstuff doesn't compile with -fPIE and -fstack-protector.
		$(out_object_file): ix86_split_to_parts() stack smashing attack b.g.o #149292.
		Add crtbeginÅ.o to EXTRA_PARTS if enable_crtbeginP yes
		We add new file crtbeginP.o if enable_crtbeginP yes
		* libgcc/Makefile.in	Add crtbeginP.o to EXTRA_PARTS if enable_crtbeginP yes
		We add new file crtbeginP.o if enable_crtbeginP yes
 
2010-04-25	Magnus Granberg		<zorry@gentoo.org>,	Kees Cook	<kees@outflux.net>

		LP #344502
		* libmudflap/Makefiles.in	Add -fno-stack-protector -U_FORTIFY_SOURCE
		to AM_CFLAGS ifdef enable_esp.

--- Makefile.in	2010-01-22 08:35:38.000000000 -0500
+++ Makefile.in	2010-02-07 15:10:59.000000000 -0500
@@ -350,9 +350,17 @@
 BUILD_PREFIX = @BUILD_PREFIX@
 BUILD_PREFIX_1 = @BUILD_PREFIX_1@
 
+# Some stuff don't compile with SSP
+enable_esp = @enable_esp@
+ifeq ($(enable_esp),yes)
+ESP_NOSSP_CFLAGS = -fno-stack-protector
+else
+ESP_NOSSP_CFLAGS=
+endif
+
 # Flags to pass to stage2 and later makes.  They are defined
 # here so that they can be overridden by Makefile fragments.
-BOOT_CFLAGS= -g -O2
+BOOT_CFLAGS= -g -O2 $(ESP_NOSSP_CFLAGS)
 BOOT_LDFLAGS=
 BOOT_ADAFLAGS=-gnatpg -gnata
 
@@ -397,9 +405,9 @@
 
 CFLAGS = @CFLAGS@
 LDFLAGS = @LDFLAGS@
-LIBCFLAGS = $(CFLAGS)
+LIBCFLAGS = $(CFLAGS) $(ESP_NOSSP_CFLAGS)
 CXXFLAGS = @CXXFLAGS@
-LIBCXXFLAGS = $(CXXFLAGS) -fno-implicit-templates
+LIBCXXFLAGS = $(CXXFLAGS) -fno-implicit-templates $(ESP_NOSSP_CFLAGS)
 
 TFLAGS =
 
--- gcc/Makefile.in	2010-01-22 17:22:51.000000000 -0500
+++ gcc/Makefile.in	2010-02-07 15:15:13.000000000 -0500
@@ -629,13 +629,24 @@
 INHIBIT_LIBC_CFLAGS = -Dinhibit_libc
 endif
 
+# We don't want __stack_chk_fail in crt* and libgcc2.a.
+# We don't want to compile crtbegin, crtend and crtbeginT with -fPIE.
+enable_esp = @enable_esp@
+ifeq ($(enable_esp),yes)
+ESP_NOPIE_CFLAGS = -fno-PIE
+ESP_NOSSP_CFLAGS = -fno-stack-protector
+else
+ESP_NOPIE_CFLAGS=
+ESP_NOSSP_CFLAGS=
+endif
+
 # 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_CFLAGS)
+		 $(INHIBIT_LIBC_CFLAGS) $(ESP_NOSSP_CFLAGS)
 
 # Additional options to use when compiling libgcc2.a.
 # Some targets override this to -isystem include
@@ -648,7 +659,7 @@
 CRTSTUFF_CFLAGS = -O2 $(GCC_CFLAGS) $(INCLUDES) $(MULTILIB_CFLAGS) -g0 \
   -finhibit-size-directive -fno-inline -fno-exceptions \
   -fno-zero-initialized-in-bss -fno-toplevel-reorder -fno-tree-vectorize \
-  $(INHIBIT_LIBC_CFLAGS)
+  $(INHIBIT_LIBC_CFLAGS) $(ESP_NOSSP_CFLAGS)
 
 # Additional sources to handle exceptions; overridden by targets as needed.
 LIB2ADDEH = $(srcdir)/unwind-dw2.c $(srcdir)/unwind-dw2-fde.c \
@@ -678,6 +689,12 @@
 # The rules for compiling them should be in the t-* file for the machine.
 EXTRA_PARTS = @extra_parts@
 
+# We add crtbeginP.o to the EXTRA_PARTS list if enable_crtbeginP = yes
+enable_crtbeginP = @enable_crtbeginP@
+ifeq ($(enable_crtbeginP),yes)
+EXTRA_PARTS += crtbeginP.o
+endif
+
 # List of extra object files that should be compiled and linked with
 # compiler proper (cc1, cc1obj, cc1plus).
 EXTRA_OBJS = @extra_objs@
@@ -1002,12 +1010,12 @@
 
 # This is the variable actually used when we compile. If you change this,
 # you probably want to update BUILD_CFLAGS in configure.ac
-ALL_CFLAGS = $(T_CFLAGS) \
+ALL_CFLAGS = $(ESP_NOPIE_CFLAGS) $(T_CFLAGS) $(CFLAGS-$@) \
   $(CFLAGS) $(INTERNAL_CFLAGS) $(COVERAGE_FLAGS) $(WARN_CFLAGS) @DEFS@
 
 # The C++ version.
-ALL_CXXFLAGS = $(T_CFLAGS) $(CXXFLAGS) $(INTERNAL_CFLAGS) \
-  $(COVERAGE_FLAGS) $(WARN_CXXFLAGS) @DEFS@
+ALL_CXXFLAGS = $(ESP_NOPIE_CFLAGS) $(T_CFLAGS) $(CXXFLAGS) \
+  $(INTERNAL_CFLAGS) $(COVERAGE_FLAGS) $(WARN_CXXFLAGS) @DEFS@
 
 # Likewise.  Put INCLUDES at the beginning: this way, if some autoconf macro
 # puts -I options in CPPFLAGS, our include files in the srcdir will always
@@ -1856,9 +1873,10 @@
 	echo LIBGCC_SYNC = '$(LIBGCC_SYNC)' >> tmp-libgcc.mvars
 	echo LIBGCC_SYNC_CFLAGS = '$(LIBGCC_SYNC_CFLAGS)' >> tmp-libgcc.mvars
 	echo CRTSTUFF_CFLAGS = '$(CRTSTUFF_CFLAGS)' >> tmp-libgcc.mvars
-	echo CRTSTUFF_T_CFLAGS = '$(CRTSTUFF_T_CFLAGS)' >> tmp-libgcc.mvars
+	echo CRTSTUFF_T_CFLAGS = '$(CRTSTUFF_T_CFLAGS) $(ESP_NOPIE_CFLAGS)' >> tmp-libgcc.mvars
 	echo CRTSTUFF_T_CFLAGS_S = '$(CRTSTUFF_T_CFLAGS_S)' >> tmp-libgcc.mvars
 	echo TARGET_SYSTEM_ROOT = '$(TARGET_SYSTEM_ROOT)' >> tmp-libgcc.mvars
+	echo enable_crtbeginP = '$(enable_crtbeginP)' >> tmp-libgcc.mvars
 
 	mv tmp-libgcc.mvars libgcc.mvars
 
@@ -1892,12 +1910,14 @@
 $(T)crtbegin.o: crtstuff.c $(GCC_PASSES) $(TCONFIG_H) auto-host.h \
   gbl-ctors.h stmp-int-hdrs tsystem.h coretypes.h $(TM_H)
 	$(GCC_FOR_TARGET) $(CRTSTUFF_CFLAGS) $(CRTSTUFF_T_CFLAGS) \
+	$(ESP_NOPIE_CFLAGS) \
 	  -c $(srcdir)/crtstuff.c -DCRT_BEGIN \
 	  -o $(T)crtbegin$(objext)
 
 $(T)crtend.o: crtstuff.c $(GCC_PASSES) $(TCONFIG_H) auto-host.h \
   gbl-ctors.h stmp-int-hdrs tsystem.h coretypes.h $(TM_H)
 	$(GCC_FOR_TARGET) $(CRTSTUFF_CFLAGS) $(CRTSTUFF_T_CFLAGS) \
+	$(ESP_NOPIE_CFLAGS) \
 	  -c $(srcdir)/crtstuff.c -DCRT_END \
 	  -o $(T)crtend$(objext)
 
@@ -1918,9 +1938,19 @@
 $(T)crtbeginT.o: crtstuff.c $(GCC_PASSES) $(TCONFIG_H) auto-host.h \
   gbl-ctors.h stmp-int-hdrs tsystem.h coretypes.h $(TM_H)
 	$(GCC_FOR_TARGET) $(CRTSTUFF_CFLAGS) $(CRTSTUFF_T_CFLAGS) \
+	$(ESP_NOPIE_CFLAGS) \
 	  -c $(srcdir)/crtstuff.c -DCRT_BEGIN -DCRTSTUFFT_O \
 	  -o $(T)crtbeginT$(objext)
 
+# This is a version of crtbegin for -static -fPIE links if esp is enable.
+ifeq ($(enable_crtbeginP),yes)
+$(T)crtbeginP.o: crtstuff.c $(GCC_PASSES) $(TCONFIG_H) auto-host.h \
+  gbl-ctors.h stmp-int-hdrs tsystem.h coretypes.h $(TM_H)
+	$(GCC_FOR_TARGET) $(CRTSTUFF_CFLAGS) $(CRTSTUFF_T_CFLAGS_S) \
+	  -c $(srcdir)/crtstuff.c -DCRT_BEGIN -DCRTSTUFFT_O -DCRTSTUFFS_O \
+	  -o $(T)crtbeginP$(objext)
+endif
+
 # Compile the start modules crt0.o and mcrt0.o that are linked with
 # every program
 $(T)crt0.o: s-crt0 ; @true
--- libgcc/Makefile.in	2009-07-30 18:33:49.000000000 -0400
+++ libgcc/Makefile.in	2010-02-07 15:10:59.000000000 -0500
@@ -291,6 +291,12 @@
 gen-hide-list = echo > \$@
 endif
 
+# We add crtbeginP.o to the EXTRA_PARTS list if enable_crtbeginP = yes
+enable_libgcc_crtbeginP = $(enable_crtbeginP)
+ifeq ($(enable_libgcc_crtbeginP),yes)
+EXTRA_PARTS += crtbeginP.o
+endif
+
 ifneq ($(EXTRA_PARTS),)
   extra-parts = libgcc-extra-parts
   INSTALL_PARTS = $(EXTRA_PARTS)
@@ -842,6 +848,13 @@
 crtbeginT.o: $(gcc_srcdir)/crtstuff.c
 	$(crt_compile) $(CRTSTUFF_T_CFLAGS) \
 	  -c $(gcc_srcdir)/crtstuff.c -DCRT_BEGIN -DCRTSTUFFT_O
+
+# This is a version of crtbegin for -static -fPIE links.
+ifeq ($(enable_libgcc_crtbeginP),yes)
+crtbeginP.o: $(gcc_srcdir)/crtstuff.c
+	$(crt_compile) $(CRTSTUFF_T_CFLAGS_S) \
+	  -c $(gcc_srcdir)/crtstuff.c -DCRT_BEGIN -DCRTSTUFFT_O -DCRTSTUFFS_O
+endif
 endif
 
 # Build extra startfiles in the libgcc directory.
--- libmudflap/Makefile.in	2009-12-05 12:18:53.000000000 -0500
+++ libmudflap/Makefile.in	2010-02-07 15:10:59.000000000 -0500
@@ -253,9 +253,17 @@
 MAINT_CHARSET = latin1
 SUBDIRS = testsuite
 
+# Some stuff don't compile with SSP and FORTIFY_SOURCE
+enable_esp = @enable_esp@
+ifeq ($(enable_esp),yes)
+	NO_ESP_CFLAGS = -fno-stack-protector -U_FORTIFY_SOURCE
+else
+	NO_ESP_CFLAGS =
+endif
+
 # May be used by various substitution variables.
 gcc_version := $(shell cat $(top_srcdir)/../gcc/BASE-VER)
-AM_CFLAGS = -Wall $(SECTION_FLAGS)
+AM_CFLAGS = -Wall $(SECTION_FLAGS) $(NO_ESP_CFLAGS)
 @LIBMUDFLAPTH_FALSE@libmudflapth = 
 @LIBMUDFLAPTH_TRUE@libmudflapth = libmudflapth.la
 toolexeclib_LTLIBRARIES = libmudflap.la $(libmudflapth)