aboutsummaryrefslogtreecommitdiff
blob: f0ddc7eb428d368e8d5353543acc7833721e85e4 (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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
2012-10-04	Magnus Granberg		<zorry@gentoo.org>

		* configure.ac		Add --enable-esp.  Add -fno-stack-protector
		to stage1_cflags.
		* configure		Likewise
		* gcc/configure.ac		Add --enable-esp and check if SSP works.
		Define ENABLE_ESP ENABLE_ESP_SSP.
		Check if we support crtbeginP and define ENABLE_CRTBEGINP.
		* gcc/configure	Likewise

--- a/configure.ac	2011-11-29 22:36:43.000000000 +0100
+++ b/configure.ac	2011-12-07 23:29:26.125712475 +0100
@@ -419,6 +419,25 @@ if test "${ENABLE_LIBADA}" != "yes" ; th
   noconfigdirs="$noconfigdirs gnattools"
 fi
 
+# Check whether --enable-esp was given and target have the support.
+AC_ARG_ENABLE([esp],
+[AS_HELP_STRING([--enable-esp],
+		[Enable Stack protector and Position independent executable as
+		 default if we have suppot for it when compiling
+		 and link with -z relro and -z now as default.
+		 Linux targets supported i*86, x86_64, x32, powerpc, powerpc64, ia64 and arm.])],
+[
+  case $target in
+    i?86*-*-linux* | x86_64-*-linux* | powerpc-*-linux* | powerpc64-*-linux* | arm*-*-linux* | ia64-*-linux*)
+      enable_espf=yes
+      ;;
+    *)
+      AC_MSG_WARN([*** --enable-esp is not supported on this $target target.])
+      ;;
+  esac
+])
+AC_SUBST([enable_esp])
+
 AC_ARG_ENABLE(libssp,
 [AS_HELP_STRING([--enable-libssp], [build libssp directory])],
 ENABLE_LIBSSP=$enableval,
@@ -3211,6 +3230,11 @@ if test "$GCC" = yes -a "$ENABLE_BUILD_W
   CFLAGS="$saved_CFLAGS"
 fi
 
+# Disable -fstack-protector on stage1
+if test x$enable_esp = xyes; then
+  stage1_cflags="$stage1_cflags -fno-stack-protector"
+fi
+
 AC_SUBST(stage1_cflags)
 
 # Enable --enable-checking in stage1 of the compiler.
--- a/configure	2011-12-22 21:51:34.700589641 +0100
+++ b/configure	2011-12-22 22:17:32.855636066 +0100
@@ -671,6 +671,7 @@ LDFLAGS
 CFLAGS
 CC
 EXTRA_CONFIGARGS_LIBJAVA
+enable_esp
 target_subdir
 host_subdir
 build_subdir
@@ -749,6 +750,7 @@ enable_ld
 enable_libquadmath
 enable_libquadmath_support
 enable_libada
+enable_esp
 enable_libssp
 enable_static_libjava
 enable_bootstrap
@@ -1467,6 +1469,11 @@ Optional Features:
   --disable-libquadmath-support
                           disable libquadmath support for Fortran
   --enable-libada         build libada directory
+  --enable-esp           Enable Stack protector and Position independent
+                          executable as default if we have suppot for it when
+                          compiling and link with -z relro and -z now as
+                          default. Linux targets supported i*86, x86_64, x32,
+                          powerpc, powerpc64, ia64 and arm.
   --enable-libssp         build libssp directory
   --enable-static-libjava[=ARG]
                           build static libjava [default=no]
@@ -2985,6 +2992,24 @@ if test "${ENABLE_LIBADA}" != "yes" ; th
   noconfigdirs="$noconfigdirs gnattools"
 fi
 
+# Check whether --enable-esp was given and target have the support.
+# Check whether --enable-esp was given.
+if test "${enable_esp+set}" = set; then :
+  enableval=$enable_esp;
+  case $target in
+    i?86*-*-linux* | x86_64-*-linux* | powerpc-*-linux* | powerpc64-*-linux* | arm*-*-linux* | ia64-*-linux*)
+      enable_esp=yes
+      ;;
+    *)
+      { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: *** --enable-esp is not supported on this $target target." >&5
+$as_echo "$as_me: WARNING: *** --enable-esp is not supported on this $target target." >&2;}
+      ;;
+  esac
+
+fi
+
+
+
 # Check whether --enable-libssp was given.
 if test "${enable_libssp+set}" = set; then :
   enableval=$enable_libssp; ENABLE_LIBSSP=$enableval
@@ -14418,6 +14445,11 @@ rm -f core conftest.err conftest.$ac_obj
   CFLAGS="$saved_CFLAGS"
 fi
 
+# Disable -fstack-protector on stage1
+if test x$enable_esp = xyes; then
+  stage1_cflags="$stage1_cflags -fno-stack-protector"
+fi
+
 
 
 # Enable --enable-checking in stage1 of the compiler.
--- a/gcc/configure.ac	2011-11-18 11:52:32.000000000 +0100
+++ b/gcc/configure.ac	2012-10-02 17:39:15.649526241 +0200
@@ -5130,6 +5237,84 @@ if test x"${LINKER_HASH_STYLE}" != x; th
                                          [The linker hash style])
 fi
 
+# --------------
+# Esp checks
+# --------------
+
+# Check whether --enable-esp was given and target have the support.
+AC_ARG_ENABLE([esp],
+[AS_HELP_STRING([--enable-esp],
+		[Enable Stack protector and Position independent executable as
+		 default if we have suppot for it when compiling
+		 and link with -z relro and -z now as default.
+		 Linux targets supported i*86, x86_64, x32, powerpc, powerpc64, ia64 and arm.])],
+  enable_esp=$enableval,
+  enable_esp=no)
+if test $enable_esp = yes ; then
+  AC_MSG_CHECKING(if $target support esp)
+  case "$target" in
+    i?86*-*-linux* | x86_64-*-linux* | powerpc-*-linux* | powerpc64-*-linux* | arm*-*-linux* | ia64-*-linux*)
+      enable_esp=yes
+      AC_DEFINE(ENABLE_ESP, 1,
+        [Define if your target support esp and you have enable it.])
+      ;;
+    *)
+      enable_esp=no
+      ;;
+  esac
+AC_MSG_RESULT($enable_esp)
+fi
+AC_SUBST([enable_esp])
+if test $enable_esp = yes ; then
+ AC_MSG_CHECKING(if we can default to use -fstack-protector-all)
+  ssp_link_test=no
+  if test x$gcc_cv_libc_provides_ssp = xyes && test x$set_have_as_tls = xyes; then
+    if $EGREP '^ 	*#[ 	]*define[ 	]+__UCLIBC__[ 	]+1' \
+       $target_header_dir/features.h > /dev/null; then
+      if test -f $target_header_dir/bits/uClibc_config.h && \
+         $EGREP '^ 	*#[ 	]*define[ 	]+__UCLIBC_SUBLEVEL__[ 	]+([3-9][2-9]|[4-9][0-9])' \
+	 $target_header_dir/bits/uClibc_config.h > /dev/null && \
+	 $EGREP '^ 	*#[ 	]*define[ 	]+__UCLIBC_HAS_TLS__[ 	]+1' \
+	 $target_header_dir/bits/uClibc_config.h > /dev/null; then
+	ssp_link_test=yes
+      fi
+    else
+      ssp_link_test=yes
+    fi
+  fi
+  if test x$ssp_link_test=xyes ; then
+    saved_CFLAGS="$CFLAGS"
+    CFLAGS="$CFLAGS -O2 -fstack-protector-all -Werror"
+    AC_TRY_LINK(,,
+      [AC_MSG_RESULT([yes]); enable_esp_ssp=yes],
+      [AC_MSG_RESULT([no]); enable_esp_ssp=no])
+    CFLAGS="$saved_CFLAGS"
+  else
+    [AC_MSG_RESULT([no]); enable_esp_ssp=no]
+  fi
+  if test $enable_esp_ssp = yes ; then
+    AC_DEFINE(ENABLE_ESP_SSP, 1,
+      [Define if your compiler will default to use -fstack-protector-all.])
+  fi
+  AC_MSG_CHECKING(checking for crtbeginP.o support)
+    if test x$enable_esp = xyes ; then
+      case "$target" in
+	ia64*-*-linux*)
+          enable_crtbeginP=no ;;
+        *-*-linux*)
+          if test x$gcc_cv_ld_pie = xyes && test x$lt_cv_prog_compiler_static_works = xyes; then
+            enable_crtbeginP=yes
+            AC_DEFINE(ENABLE_CRTBEGINP, 1,
+              [Define if your compiler will support crtbeginP.])
+     	  fi
+          ;;
+  	*) enable_crtbeginP=no ;;
+      esac
+    fi
+  AC_MSG_RESULT($enable_crtbeginP)
+fi
+AC_SUBST([enable_crtbeginP])
+
 # Configure the subdirectories
 # AC_CONFIG_SUBDIRS($subdirs)
 
--- a/gcc/configure	2011-12-31 12:45:24.449810238 +0100
+++ b/gcc/configure	2011-12-31 00:43:40.000000000 +0100
@@ -600,6 +600,8 @@ ac_includes_default="\
 
 ac_subst_vars='LTLIBOBJS
 LIBOBJS
+enable_crtbeginP
+enable_esp
 enable_plugin
 pluginlibs
 CLOOGINC
@@ -916,6 +917,7 @@ enable_version_specific_runtime_libs
 enable_plugin
 enable_libquadmath_support
 with_linker_hash_style
+enable_esp
 '
       ac_precious_vars='build_alias
 host_alias
@@ -1629,6 +1631,11 @@ Optional Features:
   --enable-plugin         enable plugin support
   --disable-libquadmath-support
                           disable libquadmath support for Fortran
+  --enable-esp            Enable Stack protector and Position independent
+                          executable and Fortify_sources as default if we have
+                          suppot for it when compiling and link -z now as
+                          default. Linux targets supported i*86, x86_64, x32,
+                          powerpc, powerpc64, ia64, mips and arm.
 
 Optional Packages:
   --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
@@ -27290,6 +27145,110 @@ _ACEOF
 
 fi
 
+# --------------
+# Esp checks
+# --------------
+
+# Check whether --enable-esp was given and target have the support.
+# Check whether --enable-esp was given.
+if test "${enable_esp+set}" = set; then :
+  enableval=$enable_esp; enable_esp=$enableval
+else
+  enable_esp=no
+fi
+
+if test $enable_esp = yes ; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $target support esp" >&5
+$as_echo_n "checking if $target support esp... " >&6; }
+  case "$target" in
+    i?86*-*-linux* | x86_64-*-linux* | powerpc-*-linux* | powerpc64-*-linux* | arm*-*-linux* | ia64-*-linux*)
+      enable_esp=yes
+
+$as_echo "#define ENABLE_ESP 1" >>confdefs.h
+
+      ;;
+    *)
+      enable_esp=no
+      ;;
+  esac
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $enable_esp" >&5
+$as_echo "$enable_esp" >&6; }
+fi
+
+if test $enable_esp = yes ; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking if we can default to use -fstack-protector-all" >&5
+$as_echo_n "checking if we can default to use -fstack-protector-all... " >&6; }
+  ssp_link_test=no
+  if test x$gcc_cv_libc_provides_ssp = xyes && test x$set_have_as_tls = xyes; then
+    if $EGREP '^ 	*#[ 	]*define[ 	]+__UCLIBC__[ 	]+1' \
+       $target_header_dir/features.h > /dev/null; then
+      if test -f $target_header_dir/bits/uClibc_config.h && \
+         $EGREP '^ 	*#[ 	]*define[ 	]+__UCLIBC_SUBLEVEL__[ 	]+([3-9][2-9]|[4-9][0-9])' \
+	 $target_header_dir/bits/uClibc_config.h > /dev/null && \
+	 $EGREP '^ 	*#[ 	]*define[ 	]+__UCLIBC_HAS_TLS__[ 	]+1' \
+	 $target_header_dir/bits/uClibc_config.h > /dev/null; then
+	ssp_link_test=yes
+      fi
+    else
+      ssp_link_test=yes
+    fi
+  fi
+  if test x$ssp_link_test=xyes ; then
+    saved_CFLAGS="$CFLAGS"
+    CFLAGS="$CFLAGS -O2 -fstack-protector-all -Werror"
+    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }; enable_esp_ssp=yes
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }; enable_esp_ssp=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+    CFLAGS="$saved_CFLAGS"
+  else
+    enable_esp_ssp=no
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: $enable_esp_ssp" >&5
+$as_echo "$enable_esp_ssp" >&6; }
+  fi
+  if test $enable_esp_ssp = yes ; then
+
+$as_echo "#define ENABLE_ESP_SSP 1" >>confdefs.h
+
+  fi
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking checking for crtbeginP.o support" >&5
+$as_echo_n "checking checking for crtbeginP.o support... " >&6; }
+    if test x$enable_esp = xyes ; then
+      case "$target" in
+	ia64*-*-linux*)
+          enable_crtbeginP=no ;;
+        *-*-linux*)
+          if test x$gcc_cv_ld_pie = xyes && test x$lt_cv_prog_compiler_static_works = xyes; then
+            enable_crtbeginP=yes
+
+$as_echo "#define ENABLE_CRTBEGINP 1" >>confdefs.h
+
+     	  fi
+          ;;
+  	*) enable_crtbeginP=no ;;
+      esac
+    fi
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $enable_crtbeginP" >&5
+$as_echo "$enable_crtbeginP" >&6; }
+fi
+
+
 # Configure the subdirectories
 # AC_CONFIG_SUBDIRS($subdirs)