aboutsummaryrefslogtreecommitdiffstats
path: root/main/gcc/0014-nopie.patch
blob: 1ca5745697bf27a2ca251a5203480fb4c188b50a (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
From 8e58f9aa5b86dc92e5a1fa71e40e499739473894 Mon Sep 17 00:00:00 2001
From: Szabolcs Nagy <nsz@port70.net>
Date: Sat, 7 Nov 2015 02:08:05 +0000
Subject: [PATCH] nopie

---
 gcc/configure    | 27 +++++++++++++++++++++++++++
 gcc/configure.ac | 13 +++++++++++++
 2 files changed, 40 insertions(+)

diff --git a/gcc/configure b/gcc/configure
index 17b878e4b4e..808570b6c99 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -30784,6 +30784,33 @@ fi
 $as_echo "$gcc_cv_no_pie" >&6; }
 if test "$gcc_cv_no_pie" = "yes"; then
   NO_PIE_FLAG="-no-pie"
+else
+  # Check if -nopie works.
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for -nopie option" >&5
+$as_echo_n "checking for -nopie option... " >&6; }
+if test "${gcc_cv_nopie+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  saved_LDFLAGS="$LDFLAGS"
+     LDFLAGS="$LDFLAGS -nopie"
+     cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int main(void) {return 0;}
+_ACEOF
+if ac_fn_cxx_try_link "$LINENO"; then :
+  gcc_cv_nopie=yes
+else
+  gcc_cv_nopie=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+     LDFLAGS="$saved_LDFLAGS"
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_nopie" >&5
+$as_echo "$gcc_cv_nopie" >&6; }
+  if test "$gcc_cv_nopie" = "yes"; then
+    NO_PIE_FLAG="-nopie"
+  fi
 fi
 
 
diff --git a/gcc/configure.ac b/gcc/configure.ac
index bf64ffbe46f..9c2571de709 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -6866,6 +6866,19 @@ AC_CACHE_CHECK([for -no-pie option],
    LDFLAGS="$saved_LDFLAGS"])
 if test "$gcc_cv_no_pie" = "yes"; then
   NO_PIE_FLAG="-no-pie"
+else
+  # Check if -nopie works.
+  AC_CACHE_CHECK([for -nopie option],
+    [gcc_cv_nopie],
+    [saved_LDFLAGS="$LDFLAGS"
+     LDFLAGS="$LDFLAGS -nopie"
+     AC_LINK_IFELSE([int main(void) {return 0;}],
+       [gcc_cv_nopie=yes],
+       [gcc_cv_nopie=no])
+     LDFLAGS="$saved_LDFLAGS"])
+  if test "$gcc_cv_nopie" = "yes"; then
+    NO_PIE_FLAG="-nopie"
+  fi
 fi
 AC_SUBST([NO_PIE_FLAG])
 
-- 
2.31.1