https://gcc.gnu.org/g:0e240e22ce40cc173e48796474311a88df695c10

commit r16-7074-g0e240e22ce40cc173e48796474311a88df695c10
Author: Rainer Orth <[email protected]>
Date:   Tue Jan 27 19:16:53 2026 +0100

    build: Unifiy 32 and 64-bit linker options
    
    Similarly to assembler option handling in gcc/configure.ac, selecting
    linker options to control 32 or 64-bit output is handled in various
    different ways all over the place.
    
    This patch uses the same approach as its assembler equivalent, setting
    ld_32_opt and ld_64_opt once and using the result everywhere.
    
    Bootstrapped without regressions on i386-pc-solaris2.11,
    amd64-pc-solaris2.11, sparc-sun-solaris2.11, sparcv9-sun-solaris2.11
    (as/ld and gas/gld), x86_64-pc-linux-gnu, i686-pc-linux-gnu,
    x86_64-unknown-freebsd14.3, sparc64-unknown-linux-gnu, and
    x86_64-apple-darwin21.6.0.
    
    2026-01-10  Rainer Orth  <[email protected]>
    
            gcc:
            * configure.ac (ld_32_opt, ld_64_opt): Set.
            (ld_ix86_gld_32_opt): Replace by ld_32_opt.
            (ld_ix86_gld_64_opt): Replace by ld_64_opt.
            Replace -melf_x86_64 by ld_64_opt.
            * configure: Regenerate.

Diff:
---
 gcc/configure    | 49 +++++++++++++++++++++++++------------------------
 gcc/configure.ac | 45 +++++++++++++++++++++++----------------------
 2 files changed, 48 insertions(+), 46 deletions(-)

diff --git a/gcc/configure b/gcc/configure
index 4650195e1139..a6b11aa6c940 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -13097,6 +13097,21 @@ cat >>confdefs.h <<_ACEOF
 _ACEOF
 
 
+case "$target:$gnu_ld" in
+  *-*-solaris2*:no)
+    # While Solaris ld has -m32/-m64 it usually determines the ELF class
+    # from the input objects.
+    ;;
+  i?86-*-solaris2*:yes | x86_64-*-solaris2*:yes)
+    ld_32_opt=-melf_i386_sol2
+    ld_64_opt=-melf_x86_64_sol2
+    ;;
+  i?86-*-*:yes | x86_64-*-*:yes)
+    ld_32_opt=-melf_i386
+    ld_64_opt=-melf_x86_64
+    ;;
+esac
+
 count=a
 for f in $host_xm_file; do
        count=${count}x
@@ -21939,7 +21954,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 21942 "configure"
+#line 21957 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -22045,7 +22060,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 22048 "configure"
+#line 22063 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -30016,14 +30031,6 @@ $as_echo "#define HAVE_AS_IX86_UD2 1" >>confdefs.h
 fi
 
 
-    # Enforce 32-bit output with gas and gld.
-    if test x$gnu_ld = xyes; then
-      case $target in
-       *-*-solaris2*) ld_ix86_gld_32_opt="-melf_i386_sol2" ;;
-       *)             ld_ix86_gld_32_opt="-melf_i386" ;;
-      esac
-    fi
-
     { $as_echo "$as_me:${as_lineno-$LINENO}: checking assembler for 
R_386_TLS_GD_PLT reloc" >&5
 $as_echo_n "checking assembler for R_386_TLS_GD_PLT reloc... " >&6; }
 if ${gcc_cv_as_ix86_tlsgdplt+:} false; then :
@@ -30040,7 +30047,7 @@ else
   test $ac_status = 0; }; }
     then
        if test x$gcc_cv_ld != x \
-        && $gcc_cv_ld $ld_ix86_gld_32_opt -o conftest conftest.o -G > 
/dev/null 2>&1; then
+        && $gcc_cv_ld $ld_32_opt -o conftest conftest.o -G > /dev/null 2>&1; 
then
           gcc_cv_as_ix86_tlsgdplt=yes
         fi
         rm -f conftest
@@ -30082,7 +30089,7 @@ else
   test $ac_status = 0; }; }
     then
        if test x$gcc_cv_ld != x \
-        && $gcc_cv_ld $ld_ix86_gld_32_opt -o conftest conftest.o -G > 
/dev/null 2>&1; then
+        && $gcc_cv_ld $ld_32_opt -o conftest conftest.o -G > /dev/null 2>&1; 
then
           gcc_cv_as_ix86_tlsldmplt=yes
         fi
         rm -f conftest
@@ -30130,7 +30137,7 @@ else
   test $ac_status = 0; }; }
     then
        if test x$gcc_cv_ld != x && test x$gcc_cv_objdump != x \
-           && $gcc_cv_ld $ld_ix86_gld_32_opt -o conftest conftest.o 
$ld_tls_libs -lc > /dev/null 2>&1; then
+           && $gcc_cv_ld $ld_32_opt -o conftest conftest.o $ld_tls_libs -lc > 
/dev/null 2>&1; then
           if $gcc_cv_objdump -d conftest 2>/dev/null | grep nop > /dev/null \
              || dis conftest 2>/dev/null | grep nop > /dev/null; then
             gcc_cv_as_ix86_tlsldm=yes
@@ -30182,7 +30189,7 @@ else
            && test x$gcc_cv_readelf != x \
            && $gcc_cv_readelf --relocs --wide conftest.o 2>&1 \
               | grep R_386_GOT32X > /dev/null 2>&1 \
-           && $gcc_cv_ld $ld_ix86_gld_32_opt -o conftest conftest.o > 
/dev/null 2>&1; then
+           && $gcc_cv_ld $ld_32_opt -o conftest conftest.o > /dev/null 2>&1; 
then
           if $gcc_cv_objdump -dw conftest 2>&1 \
              | grep 0xffffff > /dev/null 2>&1; then
             gcc_cv_as_ix86_got32x=no
@@ -30210,12 +30217,6 @@ _ACEOF
 
     # Check if gas and gld support "addq %r23,foo@GOTTPOFF(%rip), %r15"
     # with R_X86_64_CODE_6_GOTTPOFF relocation.
-    if test x$gnu_ld = xyes; then
-      case $target in
-       *-*-solaris2*) ld_ix86_gld_64_opt="-melf_x86_64_sol2" ;;
-       *)             ld_ix86_gld_64_opt="-melf_x86_64" ;;
-      esac
-    fi
     conftest_s='
        .text
        .globl  _start
@@ -30245,7 +30246,7 @@ else
            && test x$gcc_cv_readelf != x \
            && $gcc_cv_readelf --relocs --wide conftest.o 2>&1 \
               | grep R_X86_64_CODE_6_GOTTPOFF > /dev/null 2>&1 \
-           && $gcc_cv_ld $ld_ix86_gld_64_opt -o conftest conftest.o > 
/dev/null 2>&1; then
+           && $gcc_cv_ld $ld_64_opt -o conftest conftest.o > /dev/null 2>&1; 
then
           if $gcc_cv_objdump -dw conftest 2>&1 \
              | grep "add \+\$0xf\+8,%r23,%r15" > /dev/null 2>&1; then
             gcc_cv_as_x86_64_code_6_gottpoff=yes
@@ -30342,7 +30343,7 @@ else
   test $ac_status = 0; }; }
     then
        if test x$gcc_cv_ld != x \
-           && $gcc_cv_ld $ld_ix86_gld_32_opt -o conftest conftest.o > 
/dev/null 2>&1; then
+           && $gcc_cv_ld $ld_32_opt -o conftest conftest.o > /dev/null 2>&1; 
then
           gcc_cv_as_ix86_tls_get_addr_via_got=yes
         fi
         rm -f conftest
@@ -32874,9 +32875,9 @@ ptr:
        .quad   a_glob
 EOF
       if $gcc_cv_as $as_64_opt -o conftest1.o conftest1.s > /dev/null 2>&1 \
-         && $gcc_cv_ld -shared -melf_x86_64 -o conftest1.so conftest1.o > 
/dev/null 2>&1 \
+         && $gcc_cv_ld -shared $ld_64_opt -o conftest1.so conftest1.o > 
/dev/null 2>&1 \
          && $gcc_cv_as $as_64_opt -o conftest2.o conftest2.s > /dev/null 2>&1 \
-         && $gcc_cv_ld -pie -melf_x86_64 -o conftest conftest2.o conftest1.so 
> /dev/null 2>&1; then
+         && $gcc_cv_ld -pie $ld_64_opt -o conftest conftest2.o conftest1.so > 
/dev/null 2>&1; then
         gcc_cv_ld_pie_copyreloc=yes
       fi
       rm -f conftest conftest1.so conftest1.o conftest2.o conftest1.s 
conftest2.s
diff --git a/gcc/configure.ac b/gcc/configure.ac
index 67471e335dd4..3f6a6a171ca1 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -2023,6 +2023,21 @@ AC_DEFINE_UNQUOTED(HAVE_GNU_LD, $gnu_ld_bool, [Define to 
1 if using GNU ld.])
 gnu_as_bool=`if test x"$gas" = x"yes"; then echo 1; else echo 0; fi`
 AC_DEFINE_UNQUOTED(HAVE_GNU_AS, $gnu_as_bool, [Define to 1 if using GNU as.])
 
+case "$target:$gnu_ld" in
+  *-*-solaris2*:no)
+    # While Solaris ld has -m32/-m64 it usually determines the ELF class
+    # from the input objects.
+    ;;
+  i?86-*-solaris2*:yes | x86_64-*-solaris2*:yes)
+    ld_32_opt=-melf_i386_sol2
+    ld_64_opt=-melf_x86_64_sol2
+    ;;
+  i?86-*-*:yes | x86_64-*-*:yes)
+    ld_32_opt=-melf_i386
+    ld_64_opt=-melf_x86_64
+    ;;
+esac
+
 count=a
 for f in $host_xm_file; do
        count=${count}x
@@ -4962,20 +4977,12 @@ foo:    nop
       [AC_DEFINE(HAVE_AS_IX86_UD2, 1,
        [Define if your assembler supports the 'ud2' mnemonic.])])
 
-    # Enforce 32-bit output with gas and gld.
-    if test x$gnu_ld = xyes; then
-      case $target in
-       *-*-solaris2*) ld_ix86_gld_32_opt="-melf_i386_sol2" ;;
-       *)             ld_ix86_gld_32_opt="-melf_i386" ;;
-      esac
-    fi
-
     gcc_GAS_CHECK_FEATURE([R_386_TLS_GD_PLT reloc],
         gcc_cv_as_ix86_tlsgdplt,
        [$as_32_opt],
        [call    tls_gd@tlsgdplt],
        [if test x$gcc_cv_ld != x \
-        && $gcc_cv_ld $ld_ix86_gld_32_opt -o conftest conftest.o -G > 
/dev/null 2>&1; then
+        && $gcc_cv_ld $ld_32_opt -o conftest conftest.o -G > /dev/null 2>&1; 
then
           gcc_cv_as_ix86_tlsgdplt=yes
         fi
         rm -f conftest],
@@ -4993,7 +5000,7 @@ tls_ld:
        [$as_32_opt],
        [$conftest_s],
        [if test x$gcc_cv_ld != x \
-        && $gcc_cv_ld $ld_ix86_gld_32_opt -o conftest conftest.o -G > 
/dev/null 2>&1; then
+        && $gcc_cv_ld $ld_32_opt -o conftest conftest.o -G > /dev/null 2>&1; 
then
           gcc_cv_as_ix86_tlsldmplt=yes
         fi
         rm -f conftest])
@@ -5017,7 +5024,7 @@ value:'
        [$as_32_opt],
        [$conftest_s],
        [if test x$gcc_cv_ld != x && test x$gcc_cv_objdump != x \
-           && $gcc_cv_ld $ld_ix86_gld_32_opt -o conftest conftest.o 
$ld_tls_libs -lc > /dev/null 2>&1; then
+           && $gcc_cv_ld $ld_32_opt -o conftest conftest.o $ld_tls_libs -lc > 
/dev/null 2>&1; then
           if $gcc_cv_objdump -d conftest 2>/dev/null | grep nop > /dev/null \
              || dis conftest 2>/dev/null | grep nop > /dev/null; then
             gcc_cv_as_ix86_tlsldm=yes
@@ -5045,7 +5052,7 @@ _start:
            && test x$gcc_cv_readelf != x \
            && $gcc_cv_readelf --relocs --wide conftest.o 2>&1 \
               | grep R_386_GOT32X > /dev/null 2>&1 \
-           && $gcc_cv_ld $ld_ix86_gld_32_opt -o conftest conftest.o > 
/dev/null 2>&1; then
+           && $gcc_cv_ld $ld_32_opt -o conftest conftest.o > /dev/null 2>&1; 
then
           if $gcc_cv_objdump -dw conftest 2>&1 \
              | grep 0xffffff > /dev/null 2>&1; then
             gcc_cv_as_ix86_got32x=no
@@ -5060,12 +5067,6 @@ _start:
 
     # Check if gas and gld support "addq %r23,foo@GOTTPOFF(%rip), %r15"
     # with R_X86_64_CODE_6_GOTTPOFF relocation.
-    if test x$gnu_ld = xyes; then
-      case $target in
-       *-*-solaris2*) ld_ix86_gld_64_opt="-melf_x86_64_sol2" ;;
-       *)             ld_ix86_gld_64_opt="-melf_x86_64" ;;
-      esac
-    fi
     conftest_s='
        .text
        .globl  _start
@@ -5084,7 +5085,7 @@ foo:
            && test x$gcc_cv_readelf != x \
            && $gcc_cv_readelf --relocs --wide conftest.o 2>&1 \
               | grep R_X86_64_CODE_6_GOTTPOFF > /dev/null 2>&1 \
-           && $gcc_cv_ld $ld_ix86_gld_64_opt -o conftest conftest.o > 
/dev/null 2>&1; then
+           && $gcc_cv_ld $ld_64_opt -o conftest conftest.o > /dev/null 2>&1; 
then
           if $gcc_cv_objdump -dw conftest 2>&1 \
              | grep "add \+\$0xf\+8,%r23,%r15" > /dev/null 2>&1; then
             gcc_cv_as_x86_64_code_6_gottpoff=yes
@@ -5132,7 +5133,7 @@ gd:
        [$as_32_opt],
        [$conftest_s],
        [if test x$gcc_cv_ld != x \
-           && $gcc_cv_ld $ld_ix86_gld_32_opt -o conftest conftest.o > 
/dev/null 2>&1; then
+           && $gcc_cv_ld $ld_32_opt -o conftest conftest.o > /dev/null 2>&1; 
then
           gcc_cv_as_ix86_tls_get_addr_via_got=yes
         fi
         rm -f conftest])
@@ -6175,9 +6176,9 @@ ptr:
        .quad   a_glob
 EOF
       if $gcc_cv_as $as_64_opt -o conftest1.o conftest1.s > /dev/null 2>&1 \
-         && $gcc_cv_ld -shared -melf_x86_64 -o conftest1.so conftest1.o > 
/dev/null 2>&1 \
+         && $gcc_cv_ld -shared $ld_64_opt -o conftest1.so conftest1.o > 
/dev/null 2>&1 \
          && $gcc_cv_as $as_64_opt -o conftest2.o conftest2.s > /dev/null 2>&1 \
-         && $gcc_cv_ld -pie -melf_x86_64 -o conftest conftest2.o conftest1.so 
> /dev/null 2>&1; then
+         && $gcc_cv_ld -pie $ld_64_opt -o conftest conftest2.o conftest1.so > 
/dev/null 2>&1; then
         gcc_cv_ld_pie_copyreloc=yes
       fi
       rm -f conftest conftest1.so conftest1.o conftest2.o conftest1.s 
conftest2.s

Reply via email to