From c191dc86f4f7340542066f4156aa57be9cfbf876 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    | 25 +++++++++++++++++++++++++
 gcc/configure.ac | 11 +++++++++++
 2 files changed, 36 insertions(+)

diff --git a/gcc/configure b/gcc/configure
index 0f4a5d52c30..343563c8948 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -34586,6 +34586,29 @@ rm -f core conftest.err conftest.$ac_objext \
 fi
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_no_pie" >&5
 $as_echo "$gcc_cv_no_pie" >&6; }
+# 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 ${gcc_cv_nopie+:} false; 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 x$enable_host_shared = xyes; then
   PICFLAG=-fPIC
@@ -34603,6 +34626,8 @@ if test x$enable_host_pie = xyes; then
   LD_PICFLAG=-pie
 elif test x$gcc_cv_no_pie = xyes; then
   LD_PICFLAG=-no-pie
+elif test x$gcc_cv_nopie = xyes; then
+  LD_PICFLAG=-nopie
 else
   LD_PICFLAG=
 fi
diff --git a/gcc/configure.ac b/gcc/configure.ac
index b0e3615e5aa..b3948469d17 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -7802,6 +7802,15 @@ AC_CACHE_CHECK([for -no-pie option],
      [gcc_cv_no_pie=yes],
      [gcc_cv_no_pie=no])
    LDFLAGS="$saved_LDFLAGS"])
+# Check if -nopie works.
+AC_CACHE_CHECK([for -nopie option],
+  [gcc_cv_nopie],
+  [saved_LDFLAGS="$LDFLAGS"
+   LDFLAGS="$LDFLAGS -nopie"
+   AC_LINK_IFELSE([AC_LANG_SOURCE([int main(void) {return 0;}])],
+     [gcc_cv_nopie=yes],
+     [gcc_cv_nopie=no])
+   LDFLAGS="$saved_LDFLAGS"])
 
 if test x$enable_host_shared = xyes; then
   PICFLAG=-fPIC
@@ -7819,6 +7828,8 @@ if test x$enable_host_pie = xyes; then
   LD_PICFLAG=-pie
 elif test x$gcc_cv_no_pie = xyes; then
   LD_PICFLAG=-no-pie
+elif test x$gcc_cv_nopie = xyes; then
+  LD_PICFLAG=-nopie
 else
   LD_PICFLAG=
 fi
-- 
2.50.1

