summarylogtreecommitdiffstats
path: root/no-reorder-functions.patch
blob: 4ec4b35585522cb54e9e8c7e98ac3dad363bf873 (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
Index: b/configure.ac
===================================================================
--- a/configure.ac
+++ b/configure.ac
@@ -112,6 +112,22 @@
     if test "x$grub_cv_cc_no_stack_protector" = xyes; then
       STAGE2_CFLAGS="$STAGE2_CFLAGS -fno-stack-protector"
     fi
+    # GCC >= 3.3 supports -fno-reorder-functions; this defends us against
+    # unlikely-to-be-executed functions being linked before _start with GCC
+    # >= 4.6.
+    AC_CACHE_CHECK([whether gcc has -fno-reorder-functions],
+		   no_reorder_functions_flag, [
+      saved_CFLAGS=$CFLAGS
+      CFLAGS="-fno-reorder-functions"
+      AC_TRY_COMPILE(,
+		     ,
+		     no_reorder_functions_flag=yes,
+		     no_reorder_functions_flag=no)
+      CFLAGS=$saved_CFLAGS
+    ])
+    if test "x$no_reorder_functions_flag" = xyes; then
+      STAGE2_CFLAGS="$STAGE2_CFLAGS -fno-reorder-functions"
+    fi
   fi
 fi