Hello,

This was initially proposed in the course of a discussion regarding options
to allow configuring an x86_64-linux/mingw compiler to operate with -m32 by
default, here:

  https://gcc.gnu.org/pipermail/gcc-patches/2025-November/699411.html

The proposal can be seen independently from that topic so I'm resending
separately.

This is a suggestion to replace the processing of harcoded
values for TARGET_BI_ARCH in the i386 port by tests on the ABI bit
within TARGET_64BIT_DEFAULT that each of the TARGET_BI_ARCH value
was meant to convey.

This removes the distributed assumptions of what each value conveys,
making it easier to introduce other variations if needed.

The patch also removes a config.gcc #define TARGET_BI_ARCH 0 for
a couple of darwin variants that need to go 64-bit only per the
accompanying comment.  There was a mismatch between the previous
definition and the implicit assumption in ix86_option_override_internal,
that TARGET_BI_ARCH defined and != 1 implies == 2, per:

  #ifdef TARGET_BI_ARCH
   else
     {
  #if TARGET_BI_ARCH == 1
  ...
  #else
      /* When TARGET_BI_ARCH == 2, by default, OPTION_MASK_ABI_X32 is
         on and OPTION_MASK_ABI_64 is off.
  ...

Moreover, ISTM the absence of definition better matches the intent of
the TARGET_64BIT definition logic in i386.h, with the #ifndef guard in:

  #ifdef IN_LIBGCC2
  ...
  #else
  #ifndef TARGET_BI_ARCH  <== here
  #undef TARGET_64BIT
  #undef TARGET_64BIT_P
  #if TARGET_64BIT_DEFAULT
  #define TARGET_64BIT 1
  #define TARGET_64BIT_P(x) 1
  #else
  #define TARGET_64BIT 0
  #define TARGET_64BIT_P(x) 0
  #endif
  #endif
  #endif

...

This also preserves the outcome of:

  #if defined (TARGET_BI_ARCH) || TARGET_64BIT_DEFAULT
  #define MAX_BITS_PER_WORD 64
  #else
  #define MAX_BITS_PER_WORD 32
  #endif

As TARGET_64BIT_DEFAULT is defined to non zero.

I believe the change also preserves the effect of definitions of
TARGET_BI_ARCH
to 1 for i.86-linux (for enable-targets=all) or solaris, in particular the
influence on
MAX_BITS_PER_WORD quoted above.

This bootstraps and regtests fine on x86_64-linux. I also verified that a
an x86_64-linux compiler configured with --with-abi=x32 has the same
specs as before
the change.

Would this be ok to install?

Thanks in advance for your thoughts,

Cheers,

Olivier

--

2025-11-01  Olivier Hainque  <[email protected]>

        * config/i386/i386-options.cc (ix86_option_override_internal):
        Replace tests on TARGET_BI_ARCH by tests on ABI bits within
        TARGET_64BIT_DEFAULT.
        * config/i386/gnu-user64.h: Likewise.
        * config/i386/biarchx32.h (TARGET_BI_ARCH): Now a regular
        #define to standard Boolean value 1.
        * config.gcc (x86_64-*-darwin1* and 2*): Remove definition
        of TARGET_BI_ARCH to 0.
From 93eb7885fcaf91a4c1e0a8a1875f879a9c1ad9ef Mon Sep 17 00:00:00 2001
From: Olivier Hainque <[email protected]>
Date: Sat, 1 Nov 2025 11:04:17 +0000
Subject: [PATCH] Turn tests on TARGET_BI_ARCH into tests on
 TARGET_64BIT_DEFAULT

This patch is a proposal to replace the processing of harcoded
values for TARGET_BI_ARCH in the i386 port by tests on the ABI bit
within TARGET_64BIT_DEFAULT that each of the TARGET_BI_ARCH value
was meant to convey.

This results in more direct code logic, with tests like
(TARGET_64BIT_DEFAULT & OPTION_MASK_ABI_X32) rather than
(TARGET_BI_ARCH == 2) and removes the need to maintain
synchronization between the hardcoded values and their
intended meaning everywhere.

The patch also removes a config.gcc #define TARGET_BI_ARCH 0 for
a couple of darwin variants that need to go 64-bit only per the
accompanying comment.  There was a mismatch between the previous
definition and the implicit assumption in ix86_option_override_internal,
that TARGET_BI_ARCH defined and != 1 implies == 2, per:

  #ifdef TARGET_BI_ARCH
   else
     {
  #if TARGET_BI_ARCH == 1
  ...
  #else
      /* When TARGET_BI_ARCH == 2, by default, OPTION_MASK_ABI_X32 is
         on and OPTION_MASK_ABI_64 is off.
  ...

Moreover, ISTM the absence of definition better matches the intent of
the TARGET_64BIT definition logic in i386.h, with the #ifndef guard in:

  #ifdef IN_LIBGCC2
  ...
  #else
  #ifndef TARGET_BI_ARCH  <== here
  #undef TARGET_64BIT
  #undef TARGET_64BIT_P
  #if TARGET_64BIT_DEFAULT
  #define TARGET_64BIT 1
  #define TARGET_64BIT_P(x) 1
  #else
  #define TARGET_64BIT 0
  #define TARGET_64BIT_P(x) 0
  #endif
  #endif
  #endif

...

This also preserves the outcome of:

  #if defined (TARGET_BI_ARCH) || TARGET_64BIT_DEFAULT
  #define MAX_BITS_PER_WORD 64
  #else
  #define MAX_BITS_PER_WORD 32
  #endif

As TARGET_64BIT_DEFAULT is defined to non zero.

The change also preserves the effect of definitions of TARGET_BI_ARCH
to 1 for i.86-linux (for enable-targets=all) or solaris, in particular
the influence on MAX_BITS_PER_WORD quoted above.

2025-11-01  Olivier Hainque  <[email protected]>

        * config/i386/i386-options.cc (ix86_option_override_internal):
        Replace tests on TARGET_BI_ARCH by tests on ABI bits within
        TARGET_64BIT_DEFAULT.
        * config/i386/gnu-user64.h: Likewise.
        * config/i386/biarchx32.h (TARGET_BI_ARCH): Now a regular
        #define to standard Boolean value 1.
        * config.gcc (x86_64-*-darwin1* and 2*): Remove definition
        of TARGET_BI_ARCH to 0.
---
 gcc/config.gcc                  |  1 -
 gcc/config/i386/biarchx32.h     |  2 +-
 gcc/config/i386/gnu-user64.h    |  4 ++--
 gcc/config/i386/i386-options.cc | 29 +++++++++++++----------------
 4 files changed, 16 insertions(+), 20 deletions(-)

diff --git a/gcc/config.gcc b/gcc/config.gcc
index c678b801f70..784ab663c73 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -1959,7 +1959,6 @@ i[34567]86-*-darwin*)
 x86_64-*-darwin1[89]* | x86_64-*-darwin2*)
        # Only 64b from now
        tm_defines="${tm_defines} 
TARGET_64BIT_DEFAULT=(OPTION_MASK_ISA_64BIT|OPTION_MASK_ABI_64)"
-       tm_defines="${tm_defines} TARGET_BI_ARCH=0"
        with_cpu=${with_cpu:-core2}
        tmake_file="${tmake_file} t-slibgcc"
        ;;
diff --git a/gcc/config/i386/biarchx32.h b/gcc/config/i386/biarchx32.h
index b18d424de74..13455d9c881 100644
--- a/gcc/config/i386/biarchx32.h
+++ b/gcc/config/i386/biarchx32.h
@@ -25,4 +25,4 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If 
not, see
 <http://www.gnu.org/licenses/>.  */
 
 #define TARGET_64BIT_DEFAULT (OPTION_MASK_ISA_64BIT | OPTION_MASK_ABI_X32)
-#define TARGET_BI_ARCH 2
+#define TARGET_BI_ARCH 1
diff --git a/gcc/config/i386/gnu-user64.h b/gcc/config/i386/gnu-user64.h
index abe714711bf..b76c2ad2a17 100644
--- a/gcc/config/i386/gnu-user64.h
+++ b/gcc/config/i386/gnu-user64.h
@@ -33,7 +33,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If 
not, see
 
 #if TARGET_64BIT_DEFAULT
 #define SPEC_32 "m16|m32"
-#if TARGET_BI_ARCH == 2
+#if (TARGET_64BIT_DEFAULT & OPTION_MASK_ABI_X32)
 #define SPEC_64 "m64"
 #define SPEC_X32 "m16|m32|m64:;"
 #else
@@ -70,7 +70,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If 
not, see
 #define LINK_SPEC GNU_USER_TARGET_LINK_SPEC
 
 #if TARGET_64BIT_DEFAULT
-#if TARGET_BI_ARCH == 2
+#if (TARGET_64BIT_DEFAULT & OPTION_MASK_ABI_X32)
 #define MULTILIB_DEFAULTS { "mx32" }
 #else
 #define MULTILIB_DEFAULTS { "m64" }
diff --git a/gcc/config/i386/i386-options.cc b/gcc/config/i386/i386-options.cc
index dadcf7664c6..eaac6ccad4b 100644
--- a/gcc/config/i386/i386-options.cc
+++ b/gcc/config/i386/i386-options.cc
@@ -2018,22 +2018,19 @@ ix86_option_override_internal (bool main_args_p,
 #ifdef TARGET_BI_ARCH
   else
     {
-#if TARGET_BI_ARCH == 1
-      /* When TARGET_BI_ARCH == 1, by default, OPTION_MASK_ABI_64
-        is on and OPTION_MASK_ABI_X32 is off.  We turn off
-        OPTION_MASK_ABI_64 if OPTION_MASK_ABI_X32 is turned on by
-        -mx32.  */
-      if (TARGET_X32_P (opts->x_ix86_isa_flags))
-       opts->x_ix86_isa_flags &= ~OPTION_MASK_ABI_64;
-#else
-      /* When TARGET_BI_ARCH == 2, by default, OPTION_MASK_ABI_X32 is
-        on and OPTION_MASK_ABI_64 is off.  We turn off
-        OPTION_MASK_ABI_X32 if OPTION_MASK_ABI_64 is turned on by
-        -m64 or OPTION_MASK_CODE16 is turned on by -m16.  */
-      if (TARGET_LP64_P (opts->x_ix86_isa_flags)
-         || TARGET_16BIT_P (opts->x_ix86_isa_flags))
-       opts->x_ix86_isa_flags &= ~OPTION_MASK_ABI_X32;
-#endif
+      /* Turn off OPTION_MASK_ABI_64 set by default if OPTION_MASK_ABI_X32 is
+        turned on by -mx32.  */
+      if (TARGET_64BIT_DEFAULT & OPTION_MASK_ABI_64)
+       if (TARGET_X32_P (opts->x_ix86_isa_flags))
+         opts->x_ix86_isa_flags &= ~OPTION_MASK_ABI_64;
+
+      /* Turn off OPTION_MASK_ABI_X32 set by default if OPTION_MASK_ABI_64 is
+        turned on by -m64 or OPTION_MASK_CODE16 is turned on by -m16.  */
+      if (TARGET_64BIT_DEFAULT & OPTION_MASK_ABI_X32)
+       if (TARGET_LP64_P (opts->x_ix86_isa_flags)
+           || TARGET_16BIT_P (opts->x_ix86_isa_flags))
+         opts->x_ix86_isa_flags &= ~OPTION_MASK_ABI_X32;
+
       if (TARGET_64BIT_P (opts->x_ix86_isa_flags)
          && TARGET_IAMCU_P (opts->x_target_flags))
        sorry ("Intel MCU psABI isn%'t supported in %s mode",
-- 
2.34.1

Reply via email to