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.
Ok for trunk?
Since this is a very sensitive area, I'd appreciate if as many pairs of
eyes could double-check this. In particular, this patch has only seen
native testing so far. It would really help if this could be tested in
various cross scenarios, too.
There are several follow-up patches, some for GCC 16, others better left
to GCC 17:
* Once gas_flag is set reliably, acinclude.m4 (gcc_GAS_FLAGS) can use
that to determine which assembler options to use. This is a
Darwin/Solaris and x86/SPARC issue only that needs to be addressed
for GCC 16.
* I think that once gas_flag/gnu_ld_flag are determined reliably/always
set, the whole gas/gnu_ld checks can be replaced by
gas_flag/gnu_ld_flag. This will simplify config.gcc quite a bit.
* On top of that, configure.ac has many checks if gcc_cv_as and/or
gcc_cv_ld are set, but in other places just assumes they are. If we
can ensure that they are indeed always set, all those checks can just
be removed.
The latter two patches again are very sensitive, so they should be
addressed early in the GCC 17 cycle instead.
Thanks.
Rainer
--
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University
2026-01-30 Rainer Orth <[email protected]>
gcc:
PR other/123841
* acinclude.m4 (gcc_GAS_FLAGS): Restrict Darwin/as options to
native assembler.
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.
# HG changeset patch
# Parent cab27fe7da2eac3e466dd1e933deea21312fcff7
build: Only use gas_flag/gnu_ld_flag internally
diff --git a/gcc/acinclude.m4 b/gcc/acinclude.m4
--- a/gcc/acinclude.m4
+++ b/gcc/acinclude.m4
@@ -308,7 +308,7 @@ int (*fp) (void) __attribute__ ((section
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
sh_quote='"'
;;
esac
- case "$target:$gnu_ld" in
+ case "$target:$gnu_ld_flag" in
*:yes)
cat > conftest.s <<EOF
.section .dtors,$sh_flags,$sh_type
@@ -465,7 +465,7 @@ dnl #
AC_DEFUN([gcc_GAS_FLAGS],
[AC_CACHE_CHECK([assembler flags], gcc_cv_as_flags,
[ case "$target:$gas_flag" in
- *-*-darwin*:*)
+ *-*-darwin*:no)
dnl Darwin with the native assembler uses -arch i386/x86_64/ppc/ppc64.
case "$target" in
i?86-*-*)
diff --git a/gcc/configure b/gcc/configure
--- a/gcc/configure
+++ b/gcc/configure
@@ -13097,21 +13097,6 @@ 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
@@ -21954,7 +21939,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
-#line 21957 "configure"
+#line 21942 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
@@ -22060,7 +22045,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
-#line 22063 "configure"
+#line 22048 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
@@ -25485,6 +25470,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
@@ -25622,6 +25616,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; }
@@ -26112,7 +26130,7 @@ if ${gcc_cv_as_flags+:} false; then :
$as_echo_n "(cached) " >&6
else
case "$target:$gas_flag" in
- *-*-darwin*:*)
+ *-*-darwin*:no)
case "$target" in
i?86-*-*)
gcc_cv_as_flags="-arch i386"
@@ -26812,7 +26830,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'
@@ -26827,7 +26845,7 @@ fi
sh_quote='"'
;;
esac
- case "$target:$gnu_ld" in
+ case "$target:$gnu_ld_flag" in
*:yes)
cat > conftest.s <<EOF
.section .dtors,$sh_flags,$sh_type
@@ -28391,7 +28409,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"
@@ -28426,7 +28444,7 @@ fi
$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
@@ -28448,7 +28466,7 @@ fi
{ $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
@@ -28478,7 +28496,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
@@ -33090,7 +33108,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
@@ -33373,7 +33391,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
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -2023,21 +2023,6 @@ AC_DEFINE_UNQUOTED(HAVE_GNU_LD, $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
@@ -2745,6 +2730,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
@@ -2828,6 +2822,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
@@ -4289,7 +4307,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"
@@ -4315,7 +4333,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
@@ -4335,7 +4353,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
@@ -4363,7 +4381,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
@@ -6358,7 +6376,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
@@ -6591,7 +6609,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.