aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorEric Botcazou <ebotcazou@gcc.gnu.org>2021-08-12 09:30:31 +0200
committerEric Botcazou <ebotcazou@gcc.gnu.org>2021-08-12 09:33:31 +0200
commit2bdf17de1d0ad7a75d3474e672a3a2110919862f (patch)
treeb83d823081328b71715a0191454e0c5d5ed7552a /gcc
parent95e1eca43d106d821720744ac6ff1f5df41a1e78 (diff)
downloadgcc-2bdf17de1d0ad7a75d3474e672a3a2110919862f.zip
gcc-2bdf17de1d0ad7a75d3474e672a3a2110919862f.tar.gz
gcc-2bdf17de1d0ad7a75d3474e672a3a2110919862f.tar.bz2
Make -no-pie option work for native Windows
Binutils 2.36/2.37 generate PIE executables by default on native Windows (because --dynamicbase is the default) so it makes sense to have a simple way to counter that and -no-pie seems appropriate, all the more so that it is automatically passed when building the compiler itself. gcc/ * configure.ac (PE linker --disable-dynamicbase support): New check. * configure: Regenerate. * config.in: Likewise. * config/i386/mingw32.h (LINK_SPEC_DISABLE_DYNAMICBASE): New define. (LINK_SPEC): Use it. * config/i386/mingw-w64.h (LINK_SPEC_DISABLE_DYNAMICBASE): Likewise. (LINK_SPEC): Likewise.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/config.in6
-rw-r--r--gcc/config/i386/mingw-w64.h9
-rw-r--r--gcc/config/i386/mingw32.h8
-rwxr-xr-xgcc/configure20
-rw-r--r--gcc/configure.ac17
5 files changed, 60 insertions, 0 deletions
diff --git a/gcc/config.in b/gcc/config.in
index affaff2..7f5b01f 100644
--- a/gcc/config.in
+++ b/gcc/config.in
@@ -1695,6 +1695,12 @@
#endif
+/* Define if the PE linker supports --disable-dynamicbase option. */
+#ifndef USED_FOR_TARGET
+#undef HAVE_LD_PE_DISABLE_DYNAMICBASE
+#endif
+
+
/* Define if your linker supports PIE option. */
#ifndef USED_FOR_TARGET
#undef HAVE_LD_PIE
diff --git a/gcc/config/i386/mingw-w64.h b/gcc/config/i386/mingw-w64.h
index 0cec6b0..6cc7ac5 100644
--- a/gcc/config/i386/mingw-w64.h
+++ b/gcc/config/i386/mingw-w64.h
@@ -89,6 +89,14 @@ along with GCC; see the file COPYING3. If not see
# define LINK_SPEC_LARGE_ADDR_AWARE ""
#endif
+#undef LINK_SPEC_DISABLE_DYNAMICBASE
+#if HAVE_LD_PE_DISABLE_DYNAMICBASE
+# define LINK_SPEC_DISABLE_DYNAMICBASE \
+ "%{!shared:%{!mdll:%{no-pie:--disable-dynamicbase}}}"
+#else
+# define LINK_SPEC_DISABLE_DYNAMICBASE ""
+#endif
+
#undef LINK_SPEC
#define LINK_SPEC SUB_LINK_SPEC " %{mwindows:--subsystem windows} \
%{mconsole:--subsystem console} \
@@ -97,6 +105,7 @@ along with GCC; see the file COPYING3. If not see
%{static:-Bstatic} %{!static:-Bdynamic} \
%{shared|mdll: " SUB_LINK_ENTRY " --enable-auto-image-base} \
" LINK_SPEC_LARGE_ADDR_AWARE "\
+ " LINK_SPEC_DISABLE_DYNAMICBASE "\
%(shared_libgcc_undefs)"
/* Enable sincos optimization, overriding cygming.h. sincos, sincosf
diff --git a/gcc/config/i386/mingw32.h b/gcc/config/i386/mingw32.h
index 36e7bae..779c933 100644
--- a/gcc/config/i386/mingw32.h
+++ b/gcc/config/i386/mingw32.h
@@ -148,6 +148,13 @@ along with GCC; see the file COPYING3. If not see
"%{!shared:%{!mdll:%{!m64:--large-address-aware}}}"
#endif
+#if HAVE_LD_PE_DISABLE_DYNAMICBASE
+# define LINK_SPEC_DISABLE_DYNAMICBASE \
+ "%{!shared:%{!mdll:%{no-pie:--disable-dynamicbase}}}"
+#else
+# define LINK_SPEC_DISABLE_DYNAMICBASE ""
+#endif
+
#define LINK_SPEC "%{mwindows:--subsystem windows} \
%{mconsole:--subsystem console} \
%{shared: %{mdll: %eshared and mdll are not compatible}} \
@@ -155,6 +162,7 @@ along with GCC; see the file COPYING3. If not see
%{static:-Bstatic} %{!static:-Bdynamic} \
%{shared|mdll: " SUB_LINK_ENTRY " --enable-auto-image-base} \
" LINK_SPEC_LARGE_ADDR_AWARE "\
+ " LINK_SPEC_DISABLE_DYNAMICBASE "\
%(shared_libgcc_undefs)"
/* Include in the mingw32 libraries with libgcc */
diff --git a/gcc/configure b/gcc/configure
index 8b5acd7..08c2867 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -30613,6 +30613,26 @@ $as_echo "#define HAVE_LD_BROKEN_PE_DWARF5 1" >>confdefs.h
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_ld_broken_pe_dwarf5" >&5
$as_echo "$gcc_cv_ld_broken_pe_dwarf5" >&6; }
+
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking PE linker --disable-dynamicbase support" >&5
+$as_echo_n "checking PE linker --disable-dynamicbase support... " >&6; }
+ gcc_cv_ld_disable_dynamicbase=no
+ if test $in_tree_ld = yes; then
+ if test "$gcc_cv_gld_major_version" -eq 2 -a "$gcc_cv_gld_minor_version" -ge 36 -o "$gcc_cv_gld_major_version" -gt 2; then \
+ gcc_cv_ld_disable_dynamicbase=yes
+ fi
+ else
+ if $gcc_cv_ld --help 2>&1 | grep -q 'disable\-]dynamicbase' > /dev/null; then
+ gcc_cv_ld_disable_dynamicbase=yes
+ fi
+ fi
+ if test x"$gcc_cv_ld_disable_dynamicbase" = xyes; then
+
+$as_echo "#define HAVE_LD_PE_DISABLE_DYNAMICBASE 1" >>confdefs.h
+
+ fi
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_ld_disable_dynamicbase" >&5
+$as_echo "$gcc_cv_ld_disable_dynamicbase" >&6; }
;;
esac
diff --git a/gcc/configure.ac b/gcc/configure.ac
index c8e0d63..653a1cc 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -6383,6 +6383,23 @@ case $target_os in
[Define if the PE linker has broken DWARF 5 support.])
fi
AC_MSG_RESULT($gcc_cv_ld_broken_pe_dwarf5)
+
+ AC_MSG_CHECKING(PE linker --disable-dynamicbase support)
+ gcc_cv_ld_disable_dynamicbase=no
+ if test $in_tree_ld = yes; then
+ if test "$gcc_cv_gld_major_version" -eq 2 -a "$gcc_cv_gld_minor_version" -ge 36 -o "$gcc_cv_gld_major_version" -gt 2; then \
+ gcc_cv_ld_disable_dynamicbase=yes
+ fi
+ else
+ if $gcc_cv_ld --help 2>&1 | grep -q 'disable\-]dynamicbase' > /dev/null; then
+ gcc_cv_ld_disable_dynamicbase=yes
+ fi
+ fi
+ if test x"$gcc_cv_ld_disable_dynamicbase" = xyes; then
+ AC_DEFINE(HAVE_LD_PE_DISABLE_DYNAMICBASE, 1,
+ [Define if the PE linker supports --disable-dynamicbase option.])
+ fi
+ AC_MSG_RESULT($gcc_cv_ld_disable_dynamicbase)
;;
esac