From: Rainer Orth Date: Tue, 3 Feb 2026 19:41:40 +0000 (+0100) Subject: build: Only use gas_flag/gnu_ld_flag internally [PR123841] X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cc12934b555625b130e242eb6199c60b353ab509;p=thirdparty%2Fgcc.git build: Only use gas_flag/gnu_ld_flag internally [PR123841] gcc/acinclude.m4, gcc/config.gcc, and gcc/configure.ac have two different variables that are checked to determine if GNU as and/or GNU ld are used. config.gcc describes them like this: gas_flag Either yes or no depending on whether GNU as was requested. gnu_ld_flag Either yes or no depending on whether GNU ld was requested. gas Set to yes or no depending on whether the target system normally uses GNU as. gnu_ld Set to yes or no depending on whether the target system normally uses GNU ld. I find this duplication highly confusing: what's the point of what a target normally uses when it can just be determined at configure time if the assembler/linker used is gas/gnu_ld? There are two uses for those variables: * gas/gnu_ld determine the setting of HAVE_GNU_AS/HAVE_GNU_LD. In this case only, the normally part may be good enough, so this patch doesn't touch it. * However, there are several other places where this isn't good enough: when the assembler/linker is invoked at configure time, it's crucial that the right options and input syntax are use for the tool in question. Therefore this patch determines gas_flag/gnu_ld_flag at configure time if they are not yet set otherwise. All tests that need to know which tool is used now check gas_flag/gnu_ld_flag only. Tested on {i386,amd64}-pc-solaris2.11, {i686,x86_64}-pc-linux-gnu, {i386,x86_64}-apple-darwin, and sparc64-unknown-linux-gnu. 2026-01-30 Rainer Orth gcc: PR other/123841 * acinclude.m4 (gcc_GAS_FLAGS): Check $gas_flag, $gnu_ld_flag instead of $gas, $gnu_ld. * configure.ac: Likewise. (gas_flag): Determine if not already set. (gnu_ld_flag): Likewise. (ld_32_opt): Only set after gnu_ld_flag is set. (ld_64_opt): Likewise. * configure: Regenerate. --- diff --git a/gcc/acinclude.m4 b/gcc/acinclude.m4 index 89e00a16f1d..ea735457d73 100644 --- a/gcc/acinclude.m4 +++ b/gcc/acinclude.m4 @@ -308,7 +308,7 @@ int (*fp) (void) __attribute__ ((section (".init_array"))) = foo; gcc_cv_initfini_array=yes fi elif test x"$gcc_cv_as" != x -a x"$gcc_cv_ld" != x -a x"$gcc_cv_objdump" != x ; then - case $target:$gas in + case $target:$gas_flag in *:yes) sh_flags='"a"' sh_type='%progbits' @@ -323,7 +323,7 @@ int (*fp) (void) __attribute__ ((section (".init_array"))) = foo; sh_quote='"' ;; esac - case "$target:$gnu_ld" in + case "$target:$gnu_ld_flag" in *:yes) cat > conftest.s <>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 @@ -21988,7 +21973,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 21991 "configure" +#line 21976 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -22094,7 +22079,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 22097 "configure" +#line 22082 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -25519,6 +25504,15 @@ case "$ORIGINAL_AS_FOR_TARGET" in ;; esac +# Check if we are using GNU as if not already set. +if test -z "$gas_flag"; then + if $gcc_cv_as --version 2>/dev/null | grep GNU > /dev/null; then + gas_flag=yes + else + gas_flag=no + fi +fi + if $gcc_cv_as --help 2>&1 | grep -- --fatal-warnings > /dev/null; then fw_as_opt=--fatal-warnings fi @@ -25656,6 +25650,30 @@ cat >>confdefs.h <<_ACEOF _ACEOF +# Check if we are using GNU ld if not already set. +if test -z "$gnu_ld_flag"; then + if $gcc_cv_ld --version 2>/dev/null | grep GNU > /dev/null; then + gnu_ld_flag=yes + else + gnu_ld_flag=no + fi +fi + +case "$target:$gnu_ld_flag" 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 + # Check to see if we are using gold instead of ld { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using gold" >&5 $as_echo_n "checking whether we are using gold... " >&6; } @@ -26846,7 +26864,7 @@ fi gcc_cv_initfini_array=yes fi elif test x"$gcc_cv_as" != x -a x"$gcc_cv_ld" != x -a x"$gcc_cv_objdump" != x ; then - case $target:$gas in + case $target:$gas_flag in *:yes) sh_flags='"a"' sh_type='%progbits' @@ -26861,7 +26879,7 @@ fi sh_quote='"' ;; esac - case "$target:$gnu_ld" in + case "$target:$gnu_ld_flag" in *:yes) cat > conftest.s <&6; } $as_echo_n "checking linker --version-script option... " >&6; } gcc_cv_ld_version_script=no ld_version_script_option='' -if test $in_tree_ld = yes || test x"$gnu_ld" = xyes; then +if test $in_tree_ld = yes || test x"$gnu_ld_flag" = xyes; then gcc_cv_ld_version_script=yes ld_version_script_option='--version-script' elif test x$gcc_cv_ld != x; then @@ -28482,7 +28500,7 @@ $as_echo "$gcc_cv_ld_version_script" >&6; } { $as_echo "$as_me:${as_lineno-$LINENO}: checking linker soname option" >&5 $as_echo_n "checking linker soname option... " >&6; } gcc_cv_ld_soname=no -if test $in_tree_ld = yes || test x"$gnu_ld" = xyes; then +if test $in_tree_ld = yes || test x"$gnu_ld_flag" = xyes; then gcc_cv_ld_soname=yes ld_soname_option='-soname' elif test x$gcc_cv_ld != x; then @@ -28512,7 +28530,7 @@ $as_echo_n "checking linker --demangle support... " >&6; } if test "$gcc_cv_gld_major_version" -eq 2 -a "$gcc_cv_gld_minor_version" -ge 14 -o "$gcc_cv_gld_major_version" -gt 2; then \ gcc_cv_ld_demangle=yes fi - elif test x$gcc_cv_ld != x -a x"$gnu_ld" = xyes; then + elif test x$gcc_cv_ld != x -a x"$gnu_ld_flag" = xyes; then # Check if the GNU linker supports --demangle option if $gcc_cv_ld --help 2>&1 | grep no-demangle > /dev/null; then gcc_cv_ld_demangle=yes @@ -33124,7 +33142,7 @@ gcc_cv_ld_ctf=no # Check for Solaris ld 1.3315 introduced in Solaris 11.4 SRU 84. ld -z ctf # already went in in SRU 81, but lacked GNU CTF to Solaris CTF conversion. if $gcc_cv_ld --help 2>&1 | grep -- '-z ctf' > /dev/null \ - && test x$gnu_ld = xno && test "$ld_vers_minor" -ge 3315; then + && test x$gnu_ld_flag = xno && test "$ld_vers_minor" -ge 3315; then gcc_cv_ld_ctf=yes $as_echo "#define HAVE_LD_CTF 1" >>confdefs.h @@ -33407,7 +33425,7 @@ elif test x$gcc_cv_ld != x; then gcc_cv_ld_no_as_needed_option='--pop-state' fi fi - case "$target:$gnu_ld" in + case "$target:$gnu_ld_flag" in *-*-solaris2*:no) # Solaris 2 ld always supports -z ignore/-z record. Prefer the native # forms. diff --git a/gcc/configure.ac b/gcc/configure.ac index a638d7cb0b6..b05e7512914 100644 --- a/gcc/configure.ac +++ b/gcc/configure.ac @@ -2038,21 +2038,6 @@ 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 @@ -2760,6 +2745,15 @@ case "$ORIGINAL_AS_FOR_TARGET" in *) AC_CONFIG_FILES(as:exec-tool.in, [chmod +x as]) ;; esac +# Check if we are using GNU as if not already set. +if test -z "$gas_flag"; then + if $gcc_cv_as --version 2>/dev/null | grep GNU > /dev/null; then + gas_flag=yes + else + gas_flag=no + fi +fi + if $gcc_cv_as --help 2>&1 | grep -- --fatal-warnings > /dev/null; then fw_as_opt=--fatal-warnings fi @@ -2843,6 +2837,30 @@ AC_ARG_WITH(plugin-ld, AC_SUBST(ORIGINAL_PLUGIN_LD_FOR_TARGET) AC_DEFINE_UNQUOTED(PLUGIN_LD_SUFFIX, "$PLUGIN_LD_SUFFIX", [Specify plugin linker]) +# Check if we are using GNU ld if not already set. +if test -z "$gnu_ld_flag"; then + if $gcc_cv_ld --version 2>/dev/null | grep GNU > /dev/null; then + gnu_ld_flag=yes + else + gnu_ld_flag=no + fi +fi + +case "$target:$gnu_ld_flag" 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 + # Check to see if we are using gold instead of ld AC_MSG_CHECKING(whether we are using gold) ld_is_gold=no @@ -4304,7 +4322,7 @@ elif test x$gcc_cv_ld != x; then ;; # HP-UX ld uses -a flags to select between shared and archive. *-*-hpux*) - if test x"$gnu_ld" = xno; then + if test x"$gnu_ld_flag" = xno; then gcc_cv_ld_static_dynamic=yes gcc_cv_ld_static_option="-aarchive_shared" gcc_cv_ld_dynamic_option="-adefault" @@ -4330,7 +4348,7 @@ AC_MSG_RESULT($gcc_cv_ld_static_dynamic) AC_MSG_CHECKING(linker --version-script option) gcc_cv_ld_version_script=no ld_version_script_option='' -if test $in_tree_ld = yes || test x"$gnu_ld" = xyes; then +if test $in_tree_ld = yes || test x"$gnu_ld_flag" = xyes; then gcc_cv_ld_version_script=yes ld_version_script_option='--version-script' elif test x$gcc_cv_ld != x; then @@ -4350,7 +4368,7 @@ AC_SUBST(ld_version_script_option) AC_MSG_CHECKING(linker soname option) gcc_cv_ld_soname=no -if test $in_tree_ld = yes || test x"$gnu_ld" = xyes; then +if test $in_tree_ld = yes || test x"$gnu_ld_flag" = xyes; then gcc_cv_ld_soname=yes ld_soname_option='-soname' elif test x$gcc_cv_ld != x; then @@ -4378,7 +4396,7 @@ if test x"$demangler_in_ld" = xyes; then if test "$gcc_cv_gld_major_version" -eq 2 -a "$gcc_cv_gld_minor_version" -ge 14 -o "$gcc_cv_gld_major_version" -gt 2; then \ gcc_cv_ld_demangle=yes fi - elif test x$gcc_cv_ld != x -a x"$gnu_ld" = xyes; then + elif test x$gcc_cv_ld != x -a x"$gnu_ld_flag" = xyes; then # Check if the GNU linker supports --demangle option if $gcc_cv_ld --help 2>&1 | grep no-demangle > /dev/null; then gcc_cv_ld_demangle=yes @@ -6373,7 +6391,7 @@ gcc_cv_ld_ctf=no # Check for Solaris ld 1.3315 introduced in Solaris 11.4 SRU 84. ld -z ctf # already went in in SRU 81, but lacked GNU CTF to Solaris CTF conversion. if $gcc_cv_ld --help 2>&1 | grep -- '-z ctf' > /dev/null \ - && test x$gnu_ld = xno && test "$ld_vers_minor" -ge 3315; then + && test x$gnu_ld_flag = xno && test "$ld_vers_minor" -ge 3315; then gcc_cv_ld_ctf=yes AC_DEFINE(HAVE_LD_CTF, 1, [Define if your linker supports -z ctf.]) fi @@ -6606,7 +6624,7 @@ elif test x$gcc_cv_ld != x; then gcc_cv_ld_no_as_needed_option='--pop-state' fi fi - case "$target:$gnu_ld" in + case "$target:$gnu_ld_flag" in *-*-solaris2*:no) # Solaris 2 ld always supports -z ignore/-z record. Prefer the native # forms.