x86-64: Add R_X86_64_CODE_4_GOTTPOFF/R_X86_64_CODE_4_GOTPC32_TLSDESC
authorH.J. Lu <hjl.tools@gmail.com>
Fri, 9 Jun 2023 20:50:22 +0000 (13:50 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Thu, 28 Dec 2023 16:47:17 +0000 (08:47 -0800)
commita533c8df598b5ef99c54a13e2b137c98b34b043c
treecb019f462896604b2b48bb1f40dfe01bc0437051
parent4a54cb06585f568031dfd291d0fe45979ad75e98
x86-64: Add R_X86_64_CODE_4_GOTTPOFF/R_X86_64_CODE_4_GOTPC32_TLSDESC

For

add name@gottpoff(%rip), %reg
mov name@gottpoff(%rip), %reg

add

 # define R_X86_64_CODE_4_GOTTPOFF 44

and for

lea name@tlsdesc(%rip), %reg

add

 # define R_X86_64_CODE_4_GOTPC32_TLSDESC 45

if the instruction starts at 4 bytes before the relocation offset.
They are similar to R_X86_64_GOTTPOFF and R_X86_64_GOTPC32_TLSDESC,
respectively.  Linker can covert GOTTPOFF to

add $name@tpoff, %reg
mov $name@tpoff, %reg

and GOTPC32_TLSDESC to

mov $name@tpoff, %reg
mov name@gottpoff(%rip), %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_GOTTPOFF and R_X86_64_CODE_4_GOTPC32_TLSDESC.
(R_X86_64_standard): Updated.
(x86_64_reloc_map): Add BFD_RELOC_X86_64_CODE_4_GOTTPOFF
and BFD_RELOC_X86_64_CODE_4_GOTPC32_TLSDESC.
(elf_x86_64_check_tls_transition): Handle R_X86_64_CODE_4_GOTTPOFF
and R_X86_64_CODE_4_GOTPC32_TLSDESC.
(elf_x86_64_tls_transition): Likewise.
(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_GOTTPOFF and
BFD_RELOC_X86_64_CODE_4_GOTPC32_TLSDESC.
* bfd-in2.h: Regenerated.
* libbfd.h: Likewise.

gas/

* config/tc-i386.c (tc_i386_fix_adjustable): Handle
BFD_RELOC_X86_64_CODE_4_GOTTPOFF and
BFD_RELOC_X86_64_CODE_4_GOTPC32_TLSDESC.
(md_assemble): Handle BFD_RELOC_X86_64_CODE_4_GOTTPOFF.
(output_insn): Don't add empty REX prefix with REX2 prefix.
(output_disp): Handle BFD_RELOC_X86_64_CODE_4_GOTTPOFF and
BFD_RELOC_X86_64_CODE_4_GOTPC32_TLSDESC.
(md_apply_fix): Likewise.
(i386_validate_fix): Generate BFD_RELOC_X86_64_CODE_4_GOTTPOFF or
BFD_RELOC_X86_64_CODE_4_GOTPC32_TLSDESC if ixp->fx_tcbit3 is set.
(tc_gen_reloc): Handle BFD_RELOC_X86_64_CODE_4_GOTTPOFF and
BFD_RELOC_X86_64_CODE_4_GOTPC32_TLSDESC.
* testsuite/gas/i386/x86-64-gottpoff.d: New file.
* testsuite/gas/i386/x86-64-gottpoff.s: Likewise.
* testsuite/gas/i386/x86-64-tlsdesc.d: Likewise.
* testsuite/gas/i386/x86-64-tlsdesc.s: Likewise.

include/

* elf/x86-64.h (elf_x86_64_reloc_type): Add
R_X86_64_CODE_4_GOTTPOFF and R_X86_64_CODE_4_GOTPC32_TLSDESC

ld/

* testsuite/ld-x86-64/tlsbindesc.d: Updated.
* testsuite/ld-x86-64/tlsbindesc.rd: Likewise.
* testsuite/ld-x86-64/tlsbindesc.s: Add R_X86_64_CODE_4_GOTTPOFF
and R_X86_64_CODE_4_GOTPC32_TLSDESC tests.
14 files changed:
bfd/bfd-in2.h
bfd/elf64-x86-64.c
bfd/libbfd.h
bfd/reloc.c
gas/config/tc-i386.c
gas/testsuite/gas/i386/x86-64-gottpoff.d [new file with mode: 0644]
gas/testsuite/gas/i386/x86-64-gottpoff.s [new file with mode: 0644]
gas/testsuite/gas/i386/x86-64-tlsdesc.d [new file with mode: 0644]
gas/testsuite/gas/i386/x86-64-tlsdesc.s [new file with mode: 0644]
gas/testsuite/gas/i386/x86-64.exp
include/elf/x86-64.h
ld/testsuite/ld-x86-64/tlsbindesc.dd
ld/testsuite/ld-x86-64/tlsbindesc.rd
ld/testsuite/ld-x86-64/tlsbindesc.s