x86-64: Check R_X86_64_CODE_6_GOTTPOFF support

If assembler and linker supports

add %reg1, name@gottpoff(%rip), %reg2

with R_X86_64_CODE_6_GOTTPOFF, we can generate it instead of

mov name@gottpoff(%rip), %reg2
add %reg1, %reg2

gcc/

	* configure.ac (HAVE_AS_R_X86_64_CODE_6_GOTTPOFF): Defined as 1
	if R_X86_64_CODE_6_GOTTPOFF is supported.
	* config.in: Regenerated.
	* configure: Likewise.
	* config/i386/predicates.md (apx_ndd_add_memory_operand): Allow
	UNSPEC_GOTNTPOFF if R_X86_64_CODE_6_GOTTPOFF is supported.

gcc/testsuite/

	* gcc.target/i386/apx-ndd-tls-1b.c: New test.
	* lib/target-supports.exp
	(check_effective_target_code_6_gottpoff_reloc): New.
This commit is contained in:
H.J. Lu 2024-02-04 07:46:35 -08:00 committed by H.J. Lu
parent 9266d9fce2
commit 7f2cf0c45f
6 changed files with 181 additions and 1 deletions

View file

@ -737,6 +737,13 @@
#endif
/* Define 0/1 if your assembler and linker support R_X86_64_CODE_6_GOTTPOFF.
*/
#ifndef USED_FOR_TARGET
#undef HAVE_AS_R_X86_64_CODE_6_GOTTPOFF
#endif
/* Define if your assembler supports relocs needed by -fpic. */
#ifndef USED_FOR_TARGET
#undef HAVE_AS_SMALL_PIC_RELOCS

View file

@ -2299,10 +2299,14 @@
;; Return true if OP is a memory operand which can be used in APX NDD
;; ADD with register source operand. UNSPEC_GOTNTPOFF memory operand
;; isn't allowed with APX NDD ADD.
;; is allowed with APX NDD ADD only if R_X86_64_CODE_6_GOTTPOFF works.
(define_predicate "apx_ndd_add_memory_operand"
(match_operand 0 "memory_operand")
{
/* OK if "add %reg1, name@gottpoff(%rip), %reg2" is supported. */
if (HAVE_AS_R_X86_64_CODE_6_GOTTPOFF)
return true;
op = XEXP (op, 0);
/* Disallow APX NDD ADD with UNSPEC_GOTNTPOFF. */

68
gcc/configure vendored
View file

@ -29834,6 +29834,74 @@ cat >>confdefs.h <<_ACEOF
_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
# 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
.type _start, @function
_start:
addq %r23,foo@GOTTPOFF(%rip), %r15
.section .tdata,"awT",@progbits
.type foo, @object
foo:
.quad 0'
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking assembler for R_X86_64_CODE_6_GOTTPOFF reloc" >&5
$as_echo_n "checking assembler for R_X86_64_CODE_6_GOTTPOFF reloc... " >&6; }
if ${gcc_cv_as_x86_64_code_6_gottpoff+:} false; then :
$as_echo_n "(cached) " >&6
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'
{ { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
(eval $ac_try) 2>&5
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; }
then
if test x$gcc_cv_ld != x && test x$gcc_cv_objdump != x \
&& 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
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
else
gcc_cv_as_x86_64_code_6_gottpoff=no
fi
fi
rm -f conftest
else
echo "configure: failed program was" >&5
cat conftest.s >&5
fi
rm -f conftest.o conftest.s
fi
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_as_x86_64_code_6_gottpoff" >&5
$as_echo "$gcc_cv_as_x86_64_code_6_gottpoff" >&6; }
cat >>confdefs.h <<_ACEOF
#define HAVE_AS_R_X86_64_CODE_6_GOTTPOFF `if test x"$gcc_cv_as_x86_64_code_6_gottpoff" = xyes; then echo 1; else echo 0; fi`
_ACEOF
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking assembler for GOTOFF in data" >&5
$as_echo_n "checking assembler for GOTOFF in data... " >&6; }
if ${gcc_cv_as_ix86_gotoff_in_data+:} false; then :

View file

@ -5057,6 +5057,50 @@ _start:
[`if test x"$gcc_cv_as_ix86_got32x" = xyes; then echo 1; else echo 0; fi`],
[Define 0/1 if your assembler and linker support @GOT.])
# 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
# 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
.type _start, @function
_start:
addq %r23,foo@GOTTPOFF(%rip), %r15
.section .tdata,"awT",@progbits
.type foo, @object
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],
[$conftest_s],
[if test x$gcc_cv_ld != x && test x$gcc_cv_objdump != x \
&& 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
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
else
gcc_cv_as_x86_64_code_6_gottpoff=no
fi
fi
rm -f conftest])
AC_DEFINE_UNQUOTED(HAVE_AS_R_X86_64_CODE_6_GOTTPOFF,
[`if test x"$gcc_cv_as_x86_64_code_6_gottpoff" = xyes; then echo 1; else echo 0; fi`],
[Define 0/1 if your assembler and linker support R_X86_64_CODE_6_GOTTPOFF.])
gcc_GAS_CHECK_FEATURE([GOTOFF in data],
gcc_cv_as_ix86_gotoff_in_data,
[$as_ix86_gas_32_opt],

View file

@ -0,0 +1,9 @@
/* PR target/113733 */
/* { dg-do assemble { target { apxf && { ! ia32 } } } } */
/* { dg-require-effective-target tls } */
/* { dg-require-effective-target code_6_gottpoff_reloc } */
/* { dg-options "-save-temps -mapxf -O3 -w" } */
#include "apx-ndd-tls-1a.c"
/* { dg-final { scan-assembler-times "addq\[ \t]+%r\[a-z0-9\]+, a@gottpoff\\(%rip\\), %r\[a-z0-9\]+" 1 { target lp64 } } } */

View file

@ -12191,6 +12191,54 @@ proc check_effective_target_pie_copyreloc { } {
}]
}
# Return 1 if the x86-64 target supports R_X86_64_CODE_6_GOTTPOFF
# relocation, 0 otherwise. Cache the result.
proc check_effective_target_code_6_gottpoff_reloc { } {
global tool
global GCC_UNDER_TEST
if { !([istarget i?86-*-*] || [istarget x86_64-*-*]) } {
return 0
}
# Need auto-host.h to check linker support.
if { ![file exists ../../auto-host.h ] } {
return 0
}
return [check_cached_effective_target code_6_gottpoff_reloc {
# Include the current process ID in the file names to prevent
# conflicts with invocations for multiple testsuites.
set src code_6_gottpoff[pid].c
set obj code_6_gottpoff[pid].o
set f [open $src "w"]
puts $f "#include \"../../auto-host.h\""
puts $f "#if HAVE_AS_R_X86_64_CODE_6_GOTTPOFF == 0"
puts $f "# error Assembler does not support R_X86_64_CODE_6_GOTTPOFF."
puts $f "#endif"
close $f
verbose "check_effective_target_code_6_gottpoff_reloc compiling testfile $src" 2
set lines [${tool}_target_compile $src $obj object ""]
file delete $src
file delete $obj
if [string match "" $lines] then {
verbose "check_effective_target_code_6_gottpoff_reloc testfile compilation passed" 2
return 1
} else {
verbose "check_effective_target_code_6_gottpoff_reloc testfile compilation failed" 2
return 0
}
}]
return $code_6_gottpoff_reloc_available_saved
}
# Return 1 if the x86 target supports R_386_GOT32X relocation, 0
# otherwise. Cache the result.