gold: Handle R_X86_64_CODE_4_GOTPCRELX

Handle R_X86_64_CODE_4_GOTPCRELX and convert

	mov	name@GOTPCREL(%rip), %r31

to

	lea	name@GOTPCREL(%rip), %r31

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

elfcpp/

	* x86_64.h (R_X86_64_CODE_4_GOTPCRELX): New.

gold/

	* x86_64.cc (Target_x86_64::can_convert_mov_to_lea): Handle
	R_X86_64_CODE_4_GOTPCRELX.
	(Target_x86_64::Scan::get_reference_flags): Likewise.
	(Target_x86_64::Scan::local): Likewise.
	(Target_x86_64::Scan::possible_function_pointer_reloc): Likewise.
	(Target_x86_64::Scan::global): Likewise.
	(Target_x86_64::Relocate::relocate): Likewise.
	* testsuite/x86_64_mov_to_lea1.s: Add a test for
	R_X86_64_CODE_4_GOTPCRELX.
	* testsuite/x86_64_mov_to_lea2.s: Likewise.
	* testsuite/x86_64_mov_to_lea3.s: Likewise.
	* testsuite/x86_64_mov_to_lea4.s: Likewise.
	* testsuite/x86_64_mov_to_lea5.s: Likewise.
	* testsuite/x86_64_mov_to_lea.sh: Updated.
This commit is contained in:
H.J. Lu
2023-06-08 12:12:48 -07:00
parent 3d5a60de52
commit 4a54cb0658
8 changed files with 54 additions and 10 deletions

View File

@@ -95,9 +95,13 @@ enum
R_X86_64_PC32_BND = 39, // PC relative 32 bit signed with BND prefix
R_X86_64_PLT32_BND = 40, // 32 bit PLT address with BND prefix
R_X86_64_GOTPCRELX = 41, // 32 bit signed PC relative offset to GOT
// without REX prefix, relaxable.
// without REX nor REX2 prefixes, relaxable.
R_X86_64_REX_GOTPCRELX = 42, // 32 bit signed PC relative offset to GOT
// with REX prefix, relaxable.
R_X86_64_CODE_4_GOTPCRELX = 43, // 32 bit signed PC relative offset to
// GOT if the instruction starts at 4
// bytes before the relocation offset,
// relaxable.
// GNU vtable garbage collection extensions.
R_X86_64_GNU_VTINHERIT = 250,
R_X86_64_GNU_VTENTRY = 251