introduce --enable-mingw-full32 to default to --large-address-aware

Alexandre Oliva oliva@adacore.com
Fri Oct 5 06:48:00 GMT 2018


Add a configure knob for mingw32 and 64 toolchains to default passing
--large-address-aware to the linker, when creating 32-bit binaries.
-Wl,--disable-large-address-aware can still reverse its effects.

I've tested this with cross i686-pc-mingw32-gcc and
x86_64-w64-mingw64-gcc (is this the usual triplet name?), observing the
flags passed by gcc to the linker when asked to create an executable
program or a dynamic library, in 32- or, with the latter compiler, in
64-bit mode.


I wonder if it makes any sense to extend/rename the configure flag to
apply to cygwin as well, though it should default to enabled for that
platform.

I also wonder if it makes sense, at this point, for mingw to default to
--large-address-aware (I guess not, but it doesn't hurt to ask, does it?
:-)

Yet another idea that comes to mind is to introduce gcc flags, say
-m32full and -m31, to imply -m32 and also pass either
--large-address-aware or --disable-large-address-aware, respectively, to
the linker.

I suppose it might also make sense to approach this issue from the
linker, rather than from GCC, enabling its default to be configured.
Would that be preferred?  I thought tweaking GCC would be better, for
the flag would be visible with -v, both the one passed to the linker and
the one passed to GCC configure.  It wouldn't be quite as visible as a
linker configuration knob.


Given all this, is this patch below ok to install, or should I make
changes.  I've included the configure and config.in changes because
they're small enough.

Below this first patch, I enclose another patch for cygming.h.


for  gcc/ChangeLog

	* configure.ac: Introduce --enable-mingw-full32 to define
	MINGW_DEFAULT_LARGE_ADDR_AWARE.
	* configure, config.in: Rebuilt.
	* config/i386/mingw32.h (LINK_SPEC_LARGE_ADDR_AWARE): Define,
	based on MINGW_DEFAULT_LARGE_ADDR_AWARE.
	(LINK_SPEC): Insert it.
	* config/i386/mingw-264.h: Likewise.
---
 gcc/config.in               |    6 ++++++
 gcc/config/i386/mingw-w64.h |    9 +++++++++
 gcc/config/i386/mingw32.h   |    8 ++++++++
 gcc/configure               |   26 ++++++++++++++++++++------
 gcc/configure.ac            |    7 +++++++
 5 files changed, 50 insertions(+), 6 deletions(-)

diff --git a/gcc/config.in b/gcc/config.in
index 2856e72d627df..05aa7e94c296d 100644
--- a/gcc/config.in
+++ b/gcc/config.in
@@ -2040,6 +2040,12 @@
 #endif
 
 
+/* Define if we should link with --large-address-aware by default */
+#ifndef USED_FOR_TARGET
+#undef MINGW_DEFAULT_LARGE_ADDR_AWARE
+#endif
+
+
 /* Value to set mingw's _dowildcard to. */
 #ifndef USED_FOR_TARGET
 #undef MINGW_DOWILDCARD
diff --git a/gcc/config/i386/mingw-w64.h b/gcc/config/i386/mingw-w64.h
index 484dc7a9e9f27..00b3f042a36ca 100644
--- a/gcc/config/i386/mingw-w64.h
+++ b/gcc/config/i386/mingw-w64.h
@@ -81,6 +81,14 @@ along with GCC; see the file COPYING3.  If not see
 #define MULTILIB_DEFAULTS { "m32" }
 #endif
 
+#undef LINK_SPEC_LARGE_ADDR_AWARE
+#if MINGW_DEFAULT_LARGE_ADDR_AWARE
+# define LINK_SPEC_LARGE_ADDR_AWARE \
+  "%{!shared:%{!mdll:%{" SPEC_32 ":--large-address-aware}}}"
+#else
+# define LINK_SPEC_LARGE_ADDR_AWARE ""
+#endif
+
 #undef LINK_SPEC
 #define LINK_SPEC SUB_LINK_SPEC " %{mwindows:--subsystem windows} \
   %{mconsole:--subsystem console} \
@@ -88,4 +96,5 @@ along with GCC; see the file COPYING3.  If not see
   %{shared: --shared} %{mdll:--dll} \
   %{static:-Bstatic} %{!static:-Bdynamic} \
   %{shared|mdll: " SUB_LINK_ENTRY " --enable-auto-image-base} \
+  " LINK_SPEC_LARGE_ADDR_AWARE "\
   %(shared_libgcc_undefs)"
diff --git a/gcc/config/i386/mingw32.h b/gcc/config/i386/mingw32.h
index a66010894208b..c9d8a7a31f30e 100644
--- a/gcc/config/i386/mingw32.h
+++ b/gcc/config/i386/mingw32.h
@@ -114,12 +114,20 @@ along with GCC; see the file COPYING3.  If not see
 #define SUBTARGET_EXTRA_SPECS						\
   { "shared_libgcc_undefs", SHARED_LIBGCC_UNDEFS_SPEC }
 
+#if MINGW_DEFAULT_LARGE_ADDR_AWARE
+# define LINK_SPEC_LARGE_ADDR_AWARE \
+  "%{!shared:%{!mdll:--large-address-aware}}"
+#else
+# define LINK_SPEC_LARGE_ADDR_AWARE ""
+#endif
+
 #define LINK_SPEC "%{mwindows:--subsystem windows} \
   %{mconsole:--subsystem console} \
   %{shared: %{mdll: %eshared and mdll are not compatible}} \
   %{shared: --shared} %{mdll:--dll} \
   %{static:-Bstatic} %{!static:-Bdynamic} \
   %{shared|mdll: " SUB_LINK_ENTRY " --enable-auto-image-base} \
+  " LINK_SPEC_LARGE_ADDR_AWARE "\
   %(shared_libgcc_undefs)"
 
 /* Include in the mingw32 libraries with libgcc */
diff --git a/gcc/configure b/gcc/configure
index b7a8e3643778b..21fbda80a3ba7 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -927,6 +927,7 @@ enable_sjlj_exceptions
 with_gcc_major_version_only
 enable_secureplt
 enable_mingw_wildcard
+enable_mingw_full32
 enable_leading_mingw64_underscores
 enable_cld
 enable_frame_pointer
@@ -1644,6 +1645,8 @@ Optional Features:
   --enable-secureplt      enable -msecure-plt by default for PowerPC
   --enable-mingw-wildcard Set whether to expand wildcard on command-line.
                           Default to platform configuration
+  --enable-mingw-full32   Link with --large-address-aware, past 2GiB, by
+                          default
   --enable-leading-mingw64-underscores
                           enable leading underscores on 64 bit mingw targets
   --enable-cld            enable -mcld by default for 32bit x86
@@ -12002,6 +12005,17 @@ _ACEOF
 
 fi
 
+# Check whether --enable-mingw-full32 was given.
+if test "${enable_mingw_full32+set}" = set; then :
+  enableval=$enable_mingw_full32;
+fi
+
+if test x"$enable_mingw_full32" = xyes; then :
+
+$as_echo "#define MINGW_DEFAULT_LARGE_ADDR_AWARE 1" >>confdefs.h
+
+fi
+
 # Check whether --enable-leading-mingw64-underscores was given.
 if test "${enable_leading_mingw64_underscores+set}" = set; then :
   enableval=$enable_leading_mingw64_underscores;
@@ -18460,7 +18474,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 18463 "configure"
+#line 18477 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -18566,7 +18580,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 18569 "configure"
+#line 18583 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -19731,20 +19745,20 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi
 	      prelink_cmds_CXX='tpldir=Template.dir~
 		rm -rf $tpldir~
 		$CC --prelink_objects --instantiation_dir $tpldir $objs $libobjs $compile_deplibs~
-		compile_command="$compile_command `find $tpldir -name \*.o | $NL2SP`"'
+		compile_command="$compile_command `find $tpldir -name \*.o | sort | $NL2SP`"'
 	      old_archive_cmds_CXX='tpldir=Template.dir~
 		rm -rf $tpldir~
 		$CC --prelink_objects --instantiation_dir $tpldir $oldobjs$old_deplibs~
-		$AR $AR_FLAGS $oldlib$oldobjs$old_deplibs `find $tpldir -name \*.o | $NL2SP`~
+		$AR $AR_FLAGS $oldlib$oldobjs$old_deplibs `find $tpldir -name \*.o | sort | $NL2SP`~
 		$RANLIB $oldlib'
 	      archive_cmds_CXX='tpldir=Template.dir~
 		rm -rf $tpldir~
 		$CC --prelink_objects --instantiation_dir $tpldir $predep_objects $libobjs $deplibs $convenience $postdep_objects~
-		$CC -shared $pic_flag $predep_objects $libobjs $deplibs `find $tpldir -name \*.o | $NL2SP` $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname -o $lib'
+		$CC -shared $pic_flag $predep_objects $libobjs $deplibs `find $tpldir -name \*.o | sort | $NL2SP` $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname -o $lib'
 	      archive_expsym_cmds_CXX='tpldir=Template.dir~
 		rm -rf $tpldir~
 		$CC --prelink_objects --instantiation_dir $tpldir $predep_objects $libobjs $deplibs $convenience $postdep_objects~
-		$CC -shared $pic_flag $predep_objects $libobjs $deplibs `find $tpldir -name \*.o | $NL2SP` $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname ${wl}-retain-symbols-file ${wl}$export_symbols -o $lib'
+		$CC -shared $pic_flag $predep_objects $libobjs $deplibs `find $tpldir -name \*.o | sort | $NL2SP` $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname ${wl}-retain-symbols-file ${wl}$export_symbols -o $lib'
 	      ;;
 	    *) # Version 6 and above use weak symbols
 	      archive_cmds_CXX='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname -o $lib'
diff --git a/gcc/configure.ac b/gcc/configure.ac
index 65f9c92ec8522..6272bcaef1c2f 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -1826,6 +1826,13 @@ AS_IF([test x"$enable_mingw_wildcard" != xplatform ],
 		 $(test x"$enable_mingw_wildcard" = xno; echo $?),
 		 [Value to set mingw's _dowildcard to.])])
 
+AC_ARG_ENABLE(mingw-full32,
+[AS_HELP_STRING([--enable-mingw-full32],
+		[Link with --large-address-aware, past 2GiB, by default])])
+AS_IF([test x"$enable_mingw_full32" = xyes],
+  [AC_DEFINE([MINGW_DEFAULT_LARGE_ADDR_AWARE], 1,
+    [Define if we should link with --large-address-aware by default])])
+
 AC_ARG_ENABLE(leading-mingw64-underscores,
   AS_HELP_STRING([--enable-leading-mingw64-underscores],
                  [enable leading underscores on 64 bit mingw targets]),


----

define HAVE_GAS_ALIGNED_COMM

HAVE_GAS_ALIGNED_COMM is referenced in an initializer in cygming.opt,
but it's not guaranteed to be defined by configure, so define it to
zero in a cygming-specific header if it's not defined.

Ok to install?


for  gcc/ChangeLog

	* cygming.h (HAVE_GAS_ALIGNED_COMM): Fallback-define.
---
 gcc/config/i386/cygming.h |    4 ++++
 1 file changed, 4 insertions(+)

diff --git a/gcc/config/i386/cygming.h b/gcc/config/i386/cygming.h
index cfe563f47af0b..d7c7dd7057bf6 100644
--- a/gcc/config/i386/cygming.h
+++ b/gcc/config/i386/cygming.h
@@ -488,3 +488,7 @@ do {						\
 
 /* Static stack checking is supported by means of probes.  */
 #define STACK_CHECK_STATIC_BUILTIN 1
+
+#ifndef HAVE_GAS_ALIGNED_COMM
+# define HAVE_GAS_ALIGNED_COMM 0
+#endif



-- 
Alexandre Oliva, freedom fighter   https://FSFLA.org/blogs/lxo
Be the change, be Free!         FSF Latin America board member
GNU Toolchain Engineer                Free Software Evangelist



More information about the Gcc-patches mailing list