binutils-gdb/ld/testsuite/ld-x86-64/apx-load1.s
H.J. Lu 3d5a60de52 x86-64: Add R_X86_64_CODE_4_GOTPCRELX
For

	mov        name@GOTPCREL(%rip), %reg
	test       %reg, name@GOTPCREL(%rip)
	binop      name@GOTPCREL(%rip), %reg

where binop is one of adc, add, add, cmp, or, sbb, sub, xor instructions,
add

 # define R_X86_64_CODE_4_GOTPCRELX  43

if the instruction starts at 4 bytes before the relocation offset.  It
similar to R_X86_64_GOTPCRELX.  Linker can treat R_X86_64_CODE_4_GOTPCRELX
as R_X86_64_GOTPCREL or convert the above instructions to

	lea	name(%rip), %reg
	mov	$name, %reg
	test	$name, %reg
	binop	$name, %reg

if the instruction is encoded with the REX2 prefix when possible.

bfd/

	* elf64-x86-64.c (x86_64_elf_howto_table): Add
	R_X86_64_CODE_4_GOTPCRELX.
	(R_X86_64_standard): Updated.
	(x86_64_reloc_map): Add BFD_RELOC_X86_64_CODE_4_GOTPCRELX.
	(elf_x86_64_convert_load_reloc): Handle R_X86_64_CODE_4_GOTPCRELX.
	(elf_x86_64_scan_relocs): Likewise.
	(elf_x86_64_relocate_section): Likewise.
	* reloc.c (bfd_reloc_code_real): Add
	BFD_RELOC_X86_64_CODE_4_GOTPCRELX.
	* bfd-in2.h: Regenerated.
	* libbfd.h: Likewise.

gas/

	* write.h (fix): Add fx_tcbit3.  Change fx_unused to 1 bit.
	* config/tc-i386.c (tc_i386_fix_adjustable): Handle
	BFD_RELOC_X86_64_CODE_4_GOTPCRELX.
	(tc_gen_reloc): Likewise.
	(output_disp): Set fixP->fx_tcbit3 for REX2 prefix.
	(i386_validate_fix): Generate BFD_RELOC_X86_64_CODE_4_GOTPCRELX
	if fixp->fx_tcbit3 is set.
	* config/tc-i386.h (TC_FORCE_RELOCATION_LOCAL): Add
	BFD_RELOC_X86_64_CODE_4_GOTPCRELX.
	(TC_FORCE_RELOCATION_ABS): Likewise.
	* testsuite/gas/i386/x86-64-gotpcrel.s: Add tests for
	R_X86_64_CODE_4_GOTPCRELX.
	* testsuite/gas/i386/x86-64-localpic.s: Likewise.
	* testsuite/gas/i386/x86-64-gotpcrel.d: Updated.
	* testsuite/gas/i386/x86-64-localpic.d: Likewise.
	* testsuite/gas/i386/ilp32/x86-64-localpic.d: Likewise.

include/

	* elf/x86-64.h (elf_x86_64_reloc_type): Add
	R_X86_64_CODE_4_GOTPCRELX.

ld/

	* testsuite/ld-x86-64/apx-load1.s: New file.
	* testsuite/ld-x86-64/apx-load1a.d: Likewise.
	* testsuite/ld-x86-64/apx-load1b.d: Likewise.
	* testsuite/ld-x86-64/apx-load1c.d: Likewise.
	* testsuite/ld-x86-64/apx-load1d.d: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Run apx-load1a, apx-load1b,
	apx-load1c and apx-load1d.
2023-12-28 08:47:17 -08:00

52 lines
1.3 KiB
ArmAsm

.data
.type bar, @object
bar:
.byte 1
.size bar, .-bar
.globl foo
.type foo, @object
foo:
.byte 1
.size foo, .-foo
.text
.globl _start
.type _start, @function
_start:
adcl bar@GOTPCREL(%rip), %r16d
addl bar@GOTPCREL(%rip), %r17d
andl bar@GOTPCREL(%rip), %r18d
cmpl bar@GOTPCREL(%rip), %r19d
orl bar@GOTPCREL(%rip), %r20d
sbbl bar@GOTPCREL(%rip), %r21d
subl bar@GOTPCREL(%rip), %r22d
xorl bar@GOTPCREL(%rip), %r23d
testl %r24d, bar@GOTPCREL(%rip)
adcq bar@GOTPCREL(%rip), %r16
addq bar@GOTPCREL(%rip), %r17
andq bar@GOTPCREL(%rip), %r18
cmpq bar@GOTPCREL(%rip), %r19
orq bar@GOTPCREL(%rip), %r20
sbbq bar@GOTPCREL(%rip), %r21
subq bar@GOTPCREL(%rip), %r22
xorq bar@GOTPCREL(%rip), %r23
testq %r24, bar@GOTPCREL(%rip)
adcl foo@GOTPCREL(%rip), %r16d
addl foo@GOTPCREL(%rip), %r17d
andl foo@GOTPCREL(%rip), %r18d
cmpl foo@GOTPCREL(%rip), %r19d
orl foo@GOTPCREL(%rip), %r20d
sbbl foo@GOTPCREL(%rip), %r21d
subl foo@GOTPCREL(%rip), %r22d
xorl foo@GOTPCREL(%rip), %r23d
testl %r24d, foo@GOTPCREL(%rip)
adcq foo@GOTPCREL(%rip), %r16
addq foo@GOTPCREL(%rip), %r17
andq foo@GOTPCREL(%rip), %r18
cmpq foo@GOTPCREL(%rip), %r19
orq foo@GOTPCREL(%rip), %r20
sbbq foo@GOTPCREL(%rip), %r21
subq foo@GOTPCREL(%rip), %r22
xorq foo@GOTPCREL(%rip), %r23
testq %r24, foo@GOTPCREL(%rip)
.size _start, .-_start