[PATCHv3] Introduce x86_64-linux-gnuabi32

Message ID or344gaunf.fsf_-_@lxoliva.fsfla.org
State New
Headers
Series [PATCHv3] Introduce x86_64-linux-gnuabi32 |

Commit Message

Alexandre Oliva Jan. 8, 2026, 5:20 p.m. UTC
  On Dec 29, 2025, Uros Bizjak <ubizjak@gmail.com> wrote:

> I think that *abi32 is better than *m32 (*abi32 really sounds like a
> new target with different ABI, while *m32 is just mixing an option
> into the target triplet), but otherwise I have no better proposal in
> the bikeshedding contest.

:-)

> Since the patch introduces a new target that doesn't affect existing
> targets, I think it is good to go in (with *abi32 suffix).

Thanks, here's what I'm checking in momentarily.  Tested with a
x86_64-linux-gnuabi32 bootstrap.


Enable a 32-bit "native" toolchain on x86_64-*-linux-gnu and
x86_64-*-mingw32, i.e., one that targets -m32 by default, despite
supporting and potentially running in 64-bit mode, by appending abi32
to the triplet, and/or by setting the default ABI to 32 or m32.
Adjust libada and gnattools build machinery to support this
configuration in both bootstrap and non-bootstrap modes.

From: Olivier Hainque <hainque@adacore.com>
Co-Authored-By: Alexandre Oliva <oliva@adacore.com>

for  gcc/ChangeLog

	* config.gcc [x86_64-*-*]: Match *abi32 target, default to m32
	abi.  Accept 32 or m32 for --with-abi.

for  gcc/ada/ChangeLog

	* gcc-interface/Make-lang.in (m32_target): Set.
	(not_m32_target, native_target, native_gnattools1): Set.
	(ADA_TOOLS_FLAGS_TO_PASS, gnattools): Handle x86_64 natives
	defaulting to -m32 as cross for gnattools.
	* gcc-interface/Makefile.in (target_cpu): Set to i686 for
	x86_64 configurations defaulting to -m32.

for  gnattools/ChangeLog

	* configure.ac (default_gnattools_target): Use gnattools-cross
	when not bootstrapping x86_64 configurations defaulting to
	-m32.
	* configure: Rebuild.
---
 gcc/ada/gcc-interface/Make-lang.in |   25 +++++++++++++++++++------
 gcc/ada/gcc-interface/Makefile.in  |    7 +++++++
 gcc/config.gcc                     |   25 +++++++++++++++++++++++++
 gnattools/configure                |   10 ++++++++++
 gnattools/configure.ac             |   10 ++++++++++
 5 files changed, 71 insertions(+), 6 deletions(-)
  

Comments

Rainer Orth Jan. 9, 2026, 6:27 a.m. UTC | #1
Hi Alexandre,

> On Dec 29, 2025, Uros Bizjak <ubizjak@gmail.com> wrote:
>
>> I think that *abi32 is better than *m32 (*abi32 really sounds like a
>> new target with different ABI, while *m32 is just mixing an option
>> into the target triplet), but otherwise I have no better proposal in
>> the bikeshedding contest.
>
> :-)
>
>> Since the patch introduces a new target that doesn't affect existing
>> targets, I think it is good to go in (with *abi32 suffix).
>
> Thanks, here's what I'm checking in momentarily.  Tested with a
> x86_64-linux-gnuabi32 bootstrap.

AFAICS this has broken Ada bootstrap practically everywhere: on all of
*-*-solaris2.11, x86_64-pc-linux-gnu, and i686-pc-linux-gnu I see

rm -rf ../gcc/ada/tools
Cannot build gnattools while gnatlib is out of date or unbuilt
make[2]: *** [Makefile:162: ../gcc/stamp-gnatlib-rts] Error 1

	Rainer
  
Jakub Jelinek Jan. 9, 2026, 6:47 a.m. UTC | #2
On Fri, Jan 09, 2026 at 07:27:37AM +0100, Rainer Orth wrote:
> Hi Alexandre,
> 
> > On Dec 29, 2025, Uros Bizjak <ubizjak@gmail.com> wrote:
> >
> >> I think that *abi32 is better than *m32 (*abi32 really sounds like a
> >> new target with different ABI, while *m32 is just mixing an option
> >> into the target triplet), but otherwise I have no better proposal in
> >> the bikeshedding contest.
> >
> > :-)
> >
> >> Since the patch introduces a new target that doesn't affect existing
> >> targets, I think it is good to go in (with *abi32 suffix).
> >
> > Thanks, here's what I'm checking in momentarily.  Tested with a
> > x86_64-linux-gnuabi32 bootstrap.
> 
> AFAICS this has broken Ada bootstrap practically everywhere: on all of
> *-*-solaris2.11, x86_64-pc-linux-gnu, and i686-pc-linux-gnu I see
> 
> rm -rf ../gcc/ada/tools
> Cannot build gnattools while gnatlib is out of date or unbuilt
> make[2]: *** [Makefile:162: ../gcc/stamp-gnatlib-rts] Error 1

I've filed PR123497.  I suspect r16-6582-g6ae5a2a6ba4bc8c instead, trying
to bootstrap with that one reverted right now.

	Jakub
  

Patch

diff --git a/gcc/ada/gcc-interface/Make-lang.in b/gcc/ada/gcc-interface/Make-lang.in
index b1628bfb97bfb..00a788b9277de 100644
--- a/gcc/ada/gcc-interface/Make-lang.in
+++ b/gcc/ada/gcc-interface/Make-lang.in
@@ -190,10 +190,20 @@  GNATLS_FOR_HOST   = $(subst gnatmake,gnatls,$(GNATMAKE))
 
 # There are too many Ada sources to check against here.  Let's
 # always force the recursive make.
+
+# A native x86_64 compiler defaulting to -m32 is not suitable to build
+# 64bit host tools.  Arrange to build the tools with the base compiler
+# in this case, as we do for cross configurations.
+
+m32_target=$(filter x86_64%abi32, $(target))
+not_m32_target=$(if $(m32_target),,$(target))
+
 ifeq ($(build), $(host))
-  ifeq ($(host), $(target))
-    # This is a regular native. So use the compiler from our current build
-    # tree.
+  native_target=$(filter $(host), $(target))
+
+  ifneq ($(and $(native_target), $(not_m32_target)),)
+    # This is a regular native. Use the compiler from our
+    # current build tree.
     ADA_TOOLS_FLAGS_TO_PASS=\
         CC="../../xgcc -B../../" \
         CXX="$(CXX)" \
@@ -203,8 +213,8 @@  ifeq ($(build), $(host))
         GNATLINK="../../gnatlink" \
         GNATBIND="../../gnatbind"
   else
-    # This is a regular cross compiler. Use the native compiler to compile
-    # the tools.
+    # This is a regular cross compiler or a 64bit native defaulting to -m32.
+    # Use the base native compiler to compile the tools.
 
     # put the host RTS dir first in the PATH to hide the default runtime
     # files that are among the sources
@@ -790,8 +800,11 @@  gnatbind$(exeext): ada/b_gnatb.o $(CONFIG_H) $(GNATBIND_OBJS) $(EXTRA_HOST_OBJS)
 	+$(GCC_LINK) -o $@ $(CFLAGS) ada/b_gnatb.o $(GNATBIND_OBJS) $(EXTRA_HOST_OBJS) ggc-none.o libcommon-target.a $(LIBS) $(SYSLIBS) $(GNATLIB)
 
 # use target-gcc target-gnatmake target-gnatbind target-gnatlink
+
+native_gnattools1=$(if $(not_m32_target),gnattools1,gnattools1-re)
+
 gnattools: $(CONFIG_H) prefix.o force
-	$(MAKE) -C ada $(ADA_TOOLS_FLAGS_TO_PASS) gnattools1
+	$(MAKE) -C ada $(ADA_TOOLS_FLAGS_TO_PASS) $(native_gnattools1)
 	$(MAKE) -C ada $(ADA_TOOLS_FLAGS_TO_PASS) gnattools2
 
 regnattools:
diff --git a/gcc/ada/gcc-interface/Makefile.in b/gcc/ada/gcc-interface/Makefile.in
index f37893e93feed..881548358fc09 100644
--- a/gcc/ada/gcc-interface/Makefile.in
+++ b/gcc/ada/gcc-interface/Makefile.in
@@ -358,6 +358,13 @@  ifeq ($(strip $(filter-out x86_64 linux-gnux32%, $(target_cpu) $(target_os))),)
   endif
 endif
 
+# The x86_64-*abi32 compilers are x86_64 compilers defaulting to -m32
+ifeq ($(strip $(filter-out x86_64 %abi32, $(target_cpu) $(target_os))),)
+  ifneq ($(strip $(MULTISUBDIR)),/64)
+    target_cpu:=i686
+  endif
+endif
+
 # Configuration of host tools
 
 # Under linux, host tools need to be linked with -ldl
diff --git a/gcc/config.gcc b/gcc/config.gcc
index 3cce8876dbc53..30fcacba39273 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -678,6 +678,28 @@  i[34567]86-*-*)
 x86_64-*-darwin*)
 	;;
 x86_64-*-*)
+        # Pick a default with_abi and with_multilib_list for m32
+        # restricted toolchains
+        case ${target} in
+        *abi32)
+		case ${with_abi} in
+		"" | 32 | m32)
+			with_abi=m32
+			;;
+		*)
+			echo "Invalid --with-abi=$with_abi for m32 target"
+			exit 1
+	       esac
+	       case ${with_multilib_list} in
+	       default | *m32*)
+			;;
+	       *)
+			echo "Invalid multilib list for abi32 target"
+			exit 1
+	       esac
+	       ;;
+	esac
+
 	case ${with_abi} in
 	"")
 		if test "x$with_multilib_list" = xmx32; then
@@ -692,6 +714,9 @@  x86_64-*-*)
 	x32 | mx32)
 		tm_file="i386/biarchx32.h ${tm_file}"
 		;;
+	32 | m32)
+		tm_defines="${tm_defines} TARGET_BI_ARCH=1"
+		;;
 	*)
 		echo "Unknown ABI used in --with-abi=$with_abi"
 		exit 1
diff --git a/gnattools/configure b/gnattools/configure
index b3b6aab1b72ed..c7744c2e6033a 100755
--- a/gnattools/configure
+++ b/gnattools/configure
@@ -3683,6 +3683,16 @@  fi
 # ../gcc/ada/gcc-interface/config-lang.in as well.
 if test "x$cross_compiling/$build/$host" = "xno/$host/$target" ; then
   default_gnattools_target="gnattools-native"
+  # When natively-building x86_64-*abi32 tools without bootstrap,
+  # use the native toolchain to build gnattools, expecting its
+  # libraries to be compatible with whichever multilib was used to
+  # build other tools.  This requires the compiler being built to be
+  # gnatbind-compatible with the one used for the build.
+  case $enable_bootstrap/$target in
+    no/x86_64-*abi32)
+      default_gnattools_target="gnattools-cross"
+      ;;
+  esac
 else
   default_gnattools_target="gnattools-cross"
 fi
diff --git a/gnattools/configure.ac b/gnattools/configure.ac
index ff07179b3ba80..c9cdb694a15e4 100644
--- a/gnattools/configure.ac
+++ b/gnattools/configure.ac
@@ -125,6 +125,16 @@  AC_SUBST(LD_PICFLAG)
 # ../gcc/ada/gcc-interface/config-lang.in as well.
 if test "x$cross_compiling/$build/$host" = "xno/$host/$target" ; then
   default_gnattools_target="gnattools-native"
+  # When natively-building x86_64-*abi32 tools without bootstrap,
+  # use the native toolchain to build gnattools, expecting its
+  # libraries to be compatible with whichever multilib was used to
+  # build other tools.  This requires the compiler being built to be
+  # gnatbind-compatible with the one used for the build.
+  case $enable_bootstrap/$target in
+    no/x86_64-*abi32)
+      default_gnattools_target="gnattools-cross"
+      ;;
+  esac
 else
   default_gnattools_target="gnattools-cross"
 fi