When GNU binutils is configured with --enable-targets=all on Linux, "ld -V" will report both elf_x86_64_sol2 and elf_i386_sol2 as supported emulations. But they should only be used for Solaris 2 targets. Check for Solaris 2 targets before using sol2 linker emulations.
PR target/121457 * configure: Regenerated. * configure.ac (ld_ix86_gld_32_opt): Se to -melf_i386_sol2 only for Solaris 2 targets. (ld_ix86_gld_64_opt): Set to -melf_x86_64_sol2 only for Solaris 2 targets. Signed-off-by: H.J. Lu <hjl.to...@gmail.com> --- gcc/configure | 34 ++++++++++++++++++++-------------- gcc/configure.ac | 34 ++++++++++++++++++++-------------- 2 files changed, 40 insertions(+), 28 deletions(-) diff --git a/gcc/configure b/gcc/configure index bacdd29da69..1689ee15bb6 100755 --- a/gcc/configure +++ b/gcc/configure @@ -29716,13 +29716,16 @@ fi if test x$gas = xyes; then as_ix86_gas_32_opt="--32" fi - if echo "$ld_ver" | grep GNU > /dev/null; then - if $gcc_cv_ld -V 2>/dev/null | grep elf_i386_sol2 > /dev/null; then - ld_ix86_gld_32_opt="-melf_i386_sol2" - else - ld_ix86_gld_32_opt="-melf_i386" - fi - fi + ld_ix86_gld_32_opt="-melf_i386" + case "$target" in + *-*-solaris2*) + if echo "$ld_ver" | grep GNU > /dev/null; then + if $gcc_cv_ld -V 2>/dev/null | grep elf_i386_sol2 > /dev/null; then + ld_ix86_gld_32_opt="-melf_i386_sol2" + fi + fi + ;; + esac { $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; } @@ -29910,13 +29913,16 @@ _ACEOF # Check if gas and gld support "addq %r23,foo@GOTTPOFF(%rip), %r15" # with R_X86_64_CODE_6_GOTTPOFF relocation. - if echo "$ld_ver" | grep GNU > /dev/null; then - if $gcc_cv_ld -V 2>/dev/null | grep elf_x86_64_sol2 > /dev/null; then - ld_ix86_gld_64_opt="-melf_x86_64_sol2" - else - ld_ix86_gld_64_opt="-melf_x86_64" - fi - fi + ld_ix86_gld_64_opt="-melf_x86_64" + case "$target" in + *-*-solaris2*) + if echo "$ld_ver" | grep GNU > /dev/null; then + if $gcc_cv_ld -V 2>/dev/null | grep elf_x86_64_sol2 > /dev/null; then + ld_ix86_gld_64_opt="-melf_x86_64_sol2" + fi + fi + ;; + esac # Enforce 64-bit output with gas and gld. if test x$gas = xyes; then as_ix86_gas_64_opt="--64" diff --git a/gcc/configure.ac b/gcc/configure.ac index 2c43b38178c..9817ab280eb 100644 --- a/gcc/configure.ac +++ b/gcc/configure.ac @@ -5009,13 +5009,16 @@ foo: nop if test x$gas = xyes; then as_ix86_gas_32_opt="--32" fi - if echo "$ld_ver" | grep GNU > /dev/null; then - if $gcc_cv_ld -V 2>/dev/null | grep elf_i386_sol2 > /dev/null; then - ld_ix86_gld_32_opt="-melf_i386_sol2" - else - ld_ix86_gld_32_opt="-melf_i386" - fi - fi + ld_ix86_gld_32_opt="-melf_i386" + case "$target" in + *-*-solaris2*) + if echo "$ld_ver" | grep GNU > /dev/null; then + if $gcc_cv_ld -V 2>/dev/null | grep elf_i386_sol2 > /dev/null; then + ld_ix86_gld_32_opt="-melf_i386_sol2" + fi + fi + ;; + esac gcc_GAS_CHECK_FEATURE([R_386_TLS_GD_PLT reloc], gcc_cv_as_ix86_tlsgdplt, @@ -5107,13 +5110,16 @@ _start: # Check if gas and gld support "addq %r23,foo@GOTTPOFF(%rip), %r15" # with R_X86_64_CODE_6_GOTTPOFF relocation. - if echo "$ld_ver" | grep GNU > /dev/null; then - if $gcc_cv_ld -V 2>/dev/null | grep elf_x86_64_sol2 > /dev/null; then - ld_ix86_gld_64_opt="-melf_x86_64_sol2" - else - ld_ix86_gld_64_opt="-melf_x86_64" - fi - fi + ld_ix86_gld_64_opt="-melf_x86_64" + case "$target" in + *-*-solaris2*) + if echo "$ld_ver" | grep GNU > /dev/null; then + if $gcc_cv_ld -V 2>/dev/null | grep elf_x86_64_sol2 > /dev/null; then + ld_ix86_gld_64_opt="-melf_x86_64_sol2" + fi + fi + ;; + esac # Enforce 64-bit output with gas and gld. if test x$gas = xyes; then as_ix86_gas_64_opt="--64" -- 2.50.1