build: Unify 32 and 64-bit assembler handling

gcc/configure.ac uses various ways to handle differences between GNU as
and Solaris as assembler options and syntax.

This patch unifies all those, setting gcc_cv_as_flags, as_32_opt, and
as_64_opt once in acinclude.m4 (gcc_GAS_FLAGS) and using the result
everywhere.  Besides, handling Solaris as syntax differences from GNU as
is done in a more readable way.

Bootstrapped without regressions on i386-pc-solaris2.11,
x86_64-pc-solaris2.11, x86_64-pc-linux-gnu, x86_64-unknown-freebsd14.3,
and x86_64-apple-darwin21.6.0.

	gcc:
	* acinclude.m4 (gcc_cv_as_flags) Provide Solaris settings.
	Apply Linux/x86 gas settings on all x86 gas targets, too.
	(as_32_opt, as_64_opt): Set on all x86 gas targets.
	* configure.ac: Consistenly use as_32_opt, as_64_opt instead of
	as_ix86_gas_{32,64}_opt or hardcoded --64.
	<sparc*-*-*>: Simplify setting TLS test code.
	* configure: Regenerate.
This commit is contained in:
Rainer Orth
2026-01-27 19:15:36 +01:00
parent f75fe68437
commit 5fc4e333b4
3 changed files with 123 additions and 158 deletions

View File

@@ -464,29 +464,46 @@ dnl # Used by gcc_GAS_CHECK_FEATURE
dnl #
AC_DEFUN([gcc_GAS_FLAGS],
[AC_CACHE_CHECK([assembler flags], gcc_cv_as_flags,
[ case "$target" in
i[[34567]]86-*-linux*)
[ case "$target:$gas_flag" in
*-*-solaris2*:no)
dnl Override the default, which may be incompatible.
gcc_cv_as_flags=--32
case "$target" in
i?86-*-* | sparc-*-*)
gcc_cv_as_flags=-m32
;;
x86_64-*-* | sparcv9-*-* | sparc64-*-*)
gcc_cv_as_flags=-m64
;;
esac
as_32_opt=-m32
as_64_opt=-m64
;;
x86_64-*-linux-gnux32)
i?86-*-*:yes | x86_64-*-*:yes )
dnl Override the default, which may be incompatible.
gcc_cv_as_flags=--x32
case "$target" in
i?86-*-*)
gcc_cv_as_flags=--32
;;
x86_64-*-linux-gnux32*)
gcc_cv_as_flags=--x32
;;
x86_64-*-linux*)
gcc_cv_as_flags=--64
;;
esac
as_32_opt=--32
as_64_opt=--64
;;
x86_64-*-linux*)
dnl Override the default, which may be incompatible.
gcc_cv_as_flags=--64
;;
powerpc*-*-darwin*)
powerpc*-*-darwin*:*)
dnl Always pass -arch ppc to assembler.
gcc_cv_as_flags="-arch ppc"
;;
amdgcn*)
amdgcn*:*)
dnl Currently, only the llvm-mc assembler is supported.
dnl Add flags to ensure an amdgcn ELF file is written.
gcc_cv_as_flags="--filetype=obj -triple=amdgcn--amdhsa"
;;
*)
*:*)
gcc_cv_as_flags=" "
;;
esac])

139
gcc/configure vendored
View File

@@ -26096,23 +26096,41 @@ $as_echo_n "checking assembler flags... " >&6; }
if ${gcc_cv_as_flags+:} false; then :
$as_echo_n "(cached) " >&6
else
case "$target" in
i[34567]86-*-linux*)
gcc_cv_as_flags=--32
case "$target:$gas_flag" in
*-*-solaris2*:no)
case "$target" in
i?86-*-* | sparc-*-*)
gcc_cv_as_flags=-m32
;;
x86_64-*-* | sparcv9-*-* | sparc64-*-*)
gcc_cv_as_flags=-m64
;;
esac
as_32_opt=-m32
as_64_opt=-m64
;;
x86_64-*-linux-gnux32)
gcc_cv_as_flags=--x32
i?86-*-*:yes | x86_64-*-*:yes )
case "$target" in
i?86-*-*)
gcc_cv_as_flags=--32
;;
x86_64-*-linux-gnux32*)
gcc_cv_as_flags=--x32
;;
x86_64-*-linux*)
gcc_cv_as_flags=--64
;;
esac
as_32_opt=--32
as_64_opt=--64
;;
x86_64-*-linux*)
gcc_cv_as_flags=--64
;;
powerpc*-*-darwin*)
powerpc*-*-darwin*:*)
gcc_cv_as_flags="-arch ppc"
;;
amdgcn*)
amdgcn*:*)
gcc_cv_as_flags="--filetype=obj -triple=amdgcn--amdhsa"
;;
*)
*:*)
gcc_cv_as_flags=" "
;;
esac
@@ -27095,13 +27113,6 @@ else
# No objdump, err on the side of caution.
gcc_cv_as_cfi_directive=no
else
if test x$gas = xyes; then
as_32_opt="--32"
as_64_opt="--64"
else
as_32_opt="-m32"
as_64_opt="-m64"
fi
case "$target" in
sparc*-*-solaris2.*)
# On Solaris/SPARC, .eh_frame sections should always be read-write.
@@ -27952,34 +27963,23 @@ foo: .long 25
.word foo(tlsldm)
.word foo(tlsldo)'
;;
i[34567]86-*-* | x86_64-*-*)
case "$target" in
i[34567]86-*-solaris2.* | x86_64-*-solaris2.*)
on_solaris=yes
;;
*)
on_solaris=no
;;
esac
if test x$on_solaris = xyes && test x$gas_flag = xno; then
conftest_s='
.section .tdata,"awt",@progbits'
tls_section_flag=t
i?86-*-* | x86_64-*-*)
case "$target:$gas_flag" in
i?86-*-solaris2*:no | x86_64-*-solaris2*:no)
tls_section_flag=t
$as_echo "#define TLS_SECTION_ASM_FLAG 't'" >>confdefs.h
else
conftest_s='
.section ".tdata","awT",@progbits'
tls_section_flag=T
fi
;;
*:*)
tls_section_flag=T
;;
esac
conftest_s='
.section .tdata,"aw'$tls_section_flag'",@progbits'
case "$target" in
i[34567]86-*-*)
if test x$on_solaris = xyes; then
case $gas_flag in
yes) tls_as_opt="$tls_as_opt --32" ;;
esac
fi
i?86-*-*)
tls_as_opt="$tls_as_opt $as_32_opt"
conftest_s="$conftest_s
foo: .long 25
.text
@@ -27996,12 +27996,7 @@ foo: .long 25
leal foo@ntpoff(%ecx), %eax"
;;
x86_64-*-*)
if test x$on_solaris = xyes; then
case $gas_flag in
yes) tls_as_opt="$tls_as_opt --64" ;;
no) tls_as_opt="$tls_as_opt -xarch=amd64" ;;
esac
fi
tls_as_opt="$as_64_opt"
conftest_s="$conftest_s
foo: .long 25
.text
@@ -28011,7 +28006,7 @@ foo: .long 25
leaq foo@dtpoff(%rax), %rdx
movq foo@gottpoff(%rip), %rax
movq \$foo@tpoff, %rax"
;;
;;
esac
;;
ia64-*-*)
@@ -28220,22 +28215,17 @@ foo: .long 25
.long foo@TPOFF'
;;
sparc*-*-*)
case "$target" in
sparc*-sun-solaris2.*)
on_solaris=yes
case "$target:$gas_flag" in
sparc*-sun-solaris2.*:no)
conftest_s='
.section ".tdata",#alloc,#write,#tls'
;;
*)
on_solaris=no
*:*)
conftest_s='
.section ".tdata","awT",@progbits'
;;
esac
if test x$on_solaris = xyes && test x$gas_flag = xno; then
conftest_s='
.section ".tdata",#alloc,#write,#tls'
else
conftest_s='
.section ".tdata","awT",@progbits'
tls_as_opt="-32"
fi
tls_as_opt=$as_32_opt
conftest_s="$conftest_s
foo: .long 25
.text
@@ -30027,9 +30017,6 @@ fi
# Enforce 32-bit output with gas and gld.
if test x$gas = xyes; then
as_ix86_gas_32_opt="--32"
fi
if test x$gnu_ld = xyes; then
case $target in
*-*-solaris2*) ld_ix86_gld_32_opt="-melf_i386_sol2" ;;
@@ -30045,7 +30032,7 @@ else
gcc_cv_as_ix86_tlsgdplt=no
if test x"$gcc_cv_as" != x; then
$as_echo 'call tls_gd@tlsgdplt' > conftest.s
if { ac_try='$gcc_cv_as $gcc_cv_as_flags $as_ix86_gas_32_opt -o conftest.o conftest.s >&5'
if { ac_try='$gcc_cv_as $gcc_cv_as_flags $as_32_opt -o conftest.o conftest.s >&5'
{ { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
(eval $ac_try) 2>&5
ac_status=$?
@@ -30087,7 +30074,7 @@ else
gcc_cv_as_ix86_tlsldmplt=no
if test x"$gcc_cv_as" != x; then
$as_echo "$conftest_s" > conftest.s
if { ac_try='$gcc_cv_as $gcc_cv_as_flags $as_ix86_gas_32_opt -o conftest.o conftest.s >&5'
if { ac_try='$gcc_cv_as $gcc_cv_as_flags $as_32_opt -o conftest.o conftest.s >&5'
{ { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
(eval $ac_try) 2>&5
ac_status=$?
@@ -30135,7 +30122,7 @@ else
gcc_cv_as_ix86_tlsldm=no
if test x"$gcc_cv_as" != x; then
$as_echo "$conftest_s" > conftest.s
if { ac_try='$gcc_cv_as $gcc_cv_as_flags $as_ix86_gas_32_opt -o conftest.o conftest.s >&5'
if { ac_try='$gcc_cv_as $gcc_cv_as_flags $as_32_opt -o conftest.o conftest.s >&5'
{ { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
(eval $ac_try) 2>&5
ac_status=$?
@@ -30184,7 +30171,7 @@ else
gcc_cv_as_ix86_got32x=no
if test x"$gcc_cv_as" != x; then
$as_echo "$conftest_s" > conftest.s
if { ac_try='$gcc_cv_as $gcc_cv_as_flags $as_ix86_gas_32_opt -o conftest.o conftest.s >&5'
if { ac_try='$gcc_cv_as $gcc_cv_as_flags $as_32_opt -o conftest.o conftest.s >&5'
{ { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
(eval $ac_try) 2>&5
ac_status=$?
@@ -30229,10 +30216,6 @@ _ACEOF
*) ld_ix86_gld_64_opt="-melf_x86_64" ;;
esac
fi
# Enforce 64-bit output with gas and gld.
if test x$gas = xyes; then
as_ix86_gas_64_opt="--64"
fi
conftest_s='
.text
.globl _start
@@ -30251,7 +30234,7 @@ else
gcc_cv_as_x86_64_code_6_gottpoff=no
if test x"$gcc_cv_as" != x; then
$as_echo "$conftest_s" > conftest.s
if { ac_try='$gcc_cv_as $gcc_cv_as_flags $as_ix86_gas_64_opt -o conftest.o conftest.s >&5'
if { ac_try='$gcc_cv_as $gcc_cv_as_flags $as_64_opt -o conftest.o conftest.s >&5'
{ { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
(eval $ac_try) 2>&5
ac_status=$?
@@ -30300,7 +30283,7 @@ else
nop
.data
.long .L0@GOTOFF' > conftest.s
if { ac_try='$gcc_cv_as $gcc_cv_as_flags $as_ix86_gas_32_opt -o conftest.o conftest.s >&5'
if { ac_try='$gcc_cv_as $gcc_cv_as_flags $as_32_opt -o conftest.o conftest.s >&5'
{ { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
(eval $ac_try) 2>&5
ac_status=$?
@@ -30351,7 +30334,7 @@ else
gcc_cv_as_ix86_tls_get_addr_via_got=no
if test x"$gcc_cv_as" != x; then
$as_echo "$conftest_s" > conftest.s
if { ac_try='$gcc_cv_as $gcc_cv_as_flags $as_ix86_gas_32_opt -o conftest.o conftest.s >&5'
if { ac_try='$gcc_cv_as $gcc_cv_as_flags $as_32_opt -o conftest.o conftest.s >&5'
{ { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
(eval $ac_try) 2>&5
ac_status=$?
@@ -32890,9 +32873,9 @@ main:
ptr:
.quad a_glob
EOF
if $gcc_cv_as --64 -o conftest1.o conftest1.s > /dev/null 2>&1 \
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_as --64 -o conftest2.o conftest2.s > /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_copyreloc=yes
fi

View File

@@ -3449,13 +3449,6 @@ gcc_GAS_CHECK_FEATURE([cfi directives], gcc_cv_as_cfi_directive,,
# No objdump, err on the side of caution.
gcc_cv_as_cfi_directive=no
else
if test x$gas = xyes; then
as_32_opt="--32"
as_64_opt="--64"
else
as_32_opt="-m32"
as_64_opt="-m64"
fi
case "$target" in
sparc*-*-solaris2.*)
# On Solaris/SPARC, .eh_frame sections should always be read-write.
@@ -3913,35 +3906,24 @@ foo: .long 25
.word foo(tlsldm)
.word foo(tlsldo)'
;;
i[34567]86-*-* | x86_64-*-*)
case "$target" in
i[34567]86-*-solaris2.* | x86_64-*-solaris2.*)
on_solaris=yes
;;
*)
on_solaris=no
;;
esac
if test x$on_solaris = xyes && test x$gas_flag = xno; then
conftest_s='
.section .tdata,"awt",@progbits'
tls_section_flag=t
i?86-*-* | x86_64-*-*)
case "$target:$gas_flag" in
i?86-*-solaris2*:no | x86_64-*-solaris2*:no)
tls_section_flag=t
changequote([,])dnl
AC_DEFINE(TLS_SECTION_ASM_FLAG, 't',
AC_DEFINE(TLS_SECTION_ASM_FLAG, 't',
[Define to the flag used to mark TLS sections if the default (`T') doesn't work.])
changequote(,)dnl
else
conftest_s='
.section ".tdata","awT",@progbits'
tls_section_flag=T
fi
;;
*:*)
tls_section_flag=T
;;
esac
conftest_s='
.section .tdata,"aw'$tls_section_flag'",@progbits'
case "$target" in
i[34567]86-*-*)
if test x$on_solaris = xyes; then
case $gas_flag in
yes) tls_as_opt="$tls_as_opt --32" ;;
esac
fi
i?86-*-*)
tls_as_opt="$tls_as_opt $as_32_opt"
conftest_s="$conftest_s
foo: .long 25
.text
@@ -3958,12 +3940,7 @@ foo: .long 25
leal foo@ntpoff(%ecx), %eax"
;;
x86_64-*-*)
if test x$on_solaris = xyes; then
case $gas_flag in
yes) tls_as_opt="$tls_as_opt --64" ;;
no) tls_as_opt="$tls_as_opt -xarch=amd64" ;;
esac
fi
tls_as_opt="$as_64_opt"
conftest_s="$conftest_s
foo: .long 25
.text
@@ -3973,7 +3950,7 @@ foo: .long 25
leaq foo@dtpoff(%rax), %rdx
movq foo@gottpoff(%rip), %rax
movq \$foo@tpoff, %rax"
;;
;;
esac
;;
ia64-*-*)
@@ -4182,22 +4159,17 @@ foo: .long 25
.long foo@TPOFF'
;;
sparc*-*-*)
case "$target" in
sparc*-sun-solaris2.*)
on_solaris=yes
case "$target:$gas_flag" in
sparc*-sun-solaris2.*:no)
conftest_s='
.section ".tdata",#alloc,#write,#tls'
;;
*)
on_solaris=no
*:*)
conftest_s='
.section ".tdata","awT",@progbits'
;;
esac
if test x$on_solaris = xyes && test x$gas_flag = xno; then
conftest_s='
.section ".tdata",#alloc,#write,#tls'
else
conftest_s='
.section ".tdata","awT",@progbits'
tls_as_opt="-32"
fi
tls_as_opt=$as_32_opt
conftest_s="$conftest_s
foo: .long 25
.text
@@ -4991,9 +4963,6 @@ foo: nop
[Define if your assembler supports the 'ud2' mnemonic.])])
# Enforce 32-bit output with gas and gld.
if test x$gas = xyes; then
as_ix86_gas_32_opt="--32"
fi
if test x$gnu_ld = xyes; then
case $target in
*-*-solaris2*) ld_ix86_gld_32_opt="-melf_i386_sol2" ;;
@@ -5003,7 +4972,7 @@ foo: nop
gcc_GAS_CHECK_FEATURE([R_386_TLS_GD_PLT reloc],
gcc_cv_as_ix86_tlsgdplt,
[$as_ix86_gas_32_opt],
[$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
@@ -5021,7 +4990,7 @@ tls_ld:
gcc_GAS_CHECK_FEATURE([R_386_TLS_LDM_PLT reloc],
gcc_cv_as_ix86_tlsldmplt,
[$as_ix86_gas_32_opt],
[$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
@@ -5045,7 +5014,7 @@ _start:
value:'
gcc_GAS_CHECK_FEATURE([R_386_TLS_LDM reloc],
gcc_cv_as_ix86_tlsldm,
[$as_ix86_gas_32_opt],
[$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
@@ -5070,7 +5039,7 @@ _start:
jmp *_start@GOT'
gcc_GAS_CHECK_FEATURE([R_386_GOT32X reloc],
gcc_cv_as_ix86_got32x,
[$as_ix86_gas_32_opt],
[$as_32_opt],
[$conftest_s],
[if test x$gcc_cv_ld != x && test x$gcc_cv_objdump != x \
&& test x$gcc_cv_readelf != x \
@@ -5097,10 +5066,6 @@ _start:
*) ld_ix86_gld_64_opt="-melf_x86_64" ;;
esac
fi
# Enforce 64-bit output with gas and gld.
if test x$gas = xyes; then
as_ix86_gas_64_opt="--64"
fi
conftest_s='
.text
.globl _start
@@ -5113,7 +5078,7 @@ foo:
.quad 0'
gcc_GAS_CHECK_FEATURE([R_X86_64_CODE_6_GOTTPOFF reloc],
gcc_cv_as_x86_64_code_6_gottpoff,
[$as_ix86_gas_64_opt],
[$as_64_opt],
[$conftest_s],
[if test x$gcc_cv_ld != x && test x$gcc_cv_objdump != x \
&& test x$gcc_cv_readelf != x \
@@ -5134,7 +5099,7 @@ foo:
gcc_GAS_CHECK_FEATURE([GOTOFF in data],
gcc_cv_as_ix86_gotoff_in_data,
[$as_ix86_gas_32_opt],
[$as_32_opt],
[ .text
.L0:
nop
@@ -5164,7 +5129,7 @@ gd:
.byte 0'
gcc_GAS_CHECK_FEATURE([calling ___tls_get_addr via GOT],
gcc_cv_as_ix86_tls_get_addr_via_got,
[$as_ix86_gas_32_opt],
[$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
@@ -6209,9 +6174,9 @@ main:
ptr:
.quad a_glob
EOF
if $gcc_cv_as --64 -o conftest1.o conftest1.s > /dev/null 2>&1 \
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_as --64 -o conftest2.o conftest2.s > /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_copyreloc=yes
fi