binutils-gdb/gold/testsuite
H.J. Lu 3c1f1c3578 x86-64: Add R_X86_64_CODE_6_GOTTPOFF
For

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

and

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

add

 #define R_X86_64_CODE_6_GOTTPOFF		50

if the instruction starts at 6 bytes before the relocation offset.
They are similar to R_X86_64_GOTTPOFF.  Linker can covert GOTTPOFF to

	add	$name@tpoff, %reg1, %reg2

Rewrite fx_tcbit, fx_tcbit2 and fx_tcbit3 usage to generate
R_X86_64_GOTPCRELX, R_X86_64_REX_GOTPCRELX, R_X86_64_CODE_4_GOTPCRELX,
R_X86_64_CODE_4_GOTTPOFF, R_X86_64_CODE_4_GOTPC32_TLSDESC and
R_X86_64_CODE_6_GOTTPOFF.

NB: There is no need to check BFD_RELOC_X86_64_CODE_4_GOTTPOFF in
md_assemble since there is only BFD_RELOC_X86_64_GOTTPOFF at this
stage, which will be converted to BFD_RELOC_X86_64_CODE_4_GOTTPOFF
or BFD_RELOC_X86_64_CODE_6_GOTTPOFF in i386_validate_fix.

5 relocations:

 #define R_X86_64_CODE_5_GOTPCRELX		46
 #define R_X86_64_CODE_5_GOTTPOFF		47
 #define R_X86_64_CODE_5_GOTPC32_TLSDESC	48
 #define R_X86_64_CODE_6_GOTPCRELX		49
 #define R_X86_64_CODE_6_GOTPC32_TLSDESC	51

are added for completeness and they are unused.

bfd/

	* elf64-x86-64.c (x86_64_elf_howto_table): Add
	R_X86_64_CODE_5_GOTPCRELX, R_X86_64_CODE_5_GOTTPOFF,
	R_X86_64_CODE_5_GOTPC32_TLSDESC, R_X86_64_CODE_6_GOTPCRELX,
	R_X86_64_CODE_6_GOTTPOFF and R_X86_64_CODE_6_GOTPC32_TLSDESC.
	(R_X86_64_standard): Updated.
	(x86_64_reloc_map): Add R_X86_64_CODE_5_GOTPCRELX,
	R_X86_64_CODE_5_GOTTPOFF, R_X86_64_CODE_5_GOTPC32_TLSDESC,
	R_X86_64_CODE_6_GOTPCRELX, R_X86_64_CODE_6_GOTTPOFF and
	R_X86_64_CODE_6_GOTPC32_TLSDESC.
	(elf_x86_64_check_tls_transition): Handle
	R_X86_64_CODE_6_GOTTPOFF.
	(elf_x86_64_tls_transition): Likewise.
	(elf_x86_64_scan_relocs): Handle R_X86_64_CODE_6_GOTTPOFF.
	Issue an error for R_X86_64_CODE_5_GOTPCRELX,
	R_X86_64_CODE_5_GOTTPOFF, R_X86_64_CODE_5_GOTPC32_TLSDESC,
	R_X86_64_CODE_6_GOTPCRELX and R_X86_64_CODE_6_GOTPC32_TLSDESC.
	(elf_x86_64_relocate_section): Handle R_X86_64_CODE_6_GOTTPOFF.
	* reloc.c (bfd_reloc_code_real): Add
	BFD_RELOC_X86_64_CODE_5_GOTPCRELX,
	BFD_RELOC_X86_64_CODE_5_GOTTPOFF,
	BFD_RELOC_X86_64_CODE_5_GOTPC32_TLSDESC,
	BFD_RELOC_X86_64_CODE_6_GOTPCRELX,
	BFD_RELOC_X86_64_CODE_6_GOTTPOFF and
	BFD_RELOC_X86_64_CODE_6_GOTPC32_TLSDESC.
	* bfd-in2.h: Regenerated.
	* libbfd.h: Likewise.

elfcpp/

	* x86_64.h (R_X86_64_CODE_5_GOTPCRELX): New.
	(R_X86_64_CODE_5_GOTTPOFF): Likewise.
	(R_X86_64_CODE_5_GOTPC32_TLSDESC): Likewise.
	(R_X86_64_CODE_6_GOTPCRELX): Likewise.
	(R_X86_64_CODE_6_GOTTPOFF): Likewise.
	(R_X86_64_CODE_6_GOTPC32_TLSDESC): Likewise.

gas/

	* config/tc-i386.c (tc_i386_fix_adjustable): Handle
	BFD_RELOC_X86_64_CODE_6_GOTTPOFF.
	(md_assemble): Don't check BFD_RELOC_X86_64_CODE_4_GOTTPOFF.
	Allow "add %reg1, foo@gottpoff(%rip), %reg2".
	(output_disp): Handle BFD_RELOC_X86_64_CODE_6_GOTTPOFF.  Rewrite
	setting fx_tcbitX bits for BFD_RELOC_X86_64_GOTTPOFF,
	BFD_RELOC_X86_64_GOTPC32_TLSDESC and BFD_RELOC_32_PCREL.
	(md_apply_fix): Handle BFD_RELOC_X86_64_CODE_6_GOTTPOFF.
	(i386_validate_fix): Rewrite fx_tcbitX bit checking for
	BFD_RELOC_X86_64_GOTTPOFF, BFD_RELOC_X86_64_GOTPC32_TLSDESC and
	BFD_RELOC_32_PCREL.
	(tc_gen_reloc): Handle BFD_RELOC_X86_64_CODE_6_GOTTPOFF.
	* testsuite/gas/i386/x86-64-gottpoff.d: Updated.
	* testsuite/gas/i386/x86-64-gottpoff.s: Add tests for
	"add %reg1, foo@gottpoff(%rip), %reg2" and
	"add foo@gottpoff(%rip), %reg, %reg2".

gold/

	* x86_64.cc (Target_x86_64::optimize_tls_reloc): Handle
	R_X86_64_CODE_6_GOTTPOFF.
	(Target_x86_64::Scan::get_reference_flags): Likewise.
	(Target_x86_64::Scan::local): Likewise.
	(Target_x86_64::Scan::global): Likewise.
	(Target_x86_64::Relocate::relocate): Likewise.
	(Target_x86_64::Relocate::relocate_tls): Likewise.
	(Target_x86_64::Relocate::tls_ie_to_le): Handle.
	R_X86_64_CODE_6_GOTTPOFF.
	* testsuite/x86_64_ie_to_le.s: Add tests for
	"add %reg1, foo@gottpoff(%rip), %reg2" and
	"add foo@gottpoff(%rip), %reg, %reg2".
	* testsuite/x86_64_ie_to_le.sh: Updated.

include/

	* elf/x86-64.h (elf_x86_64_reloc_type): Add
	R_X86_64_CODE_5_GOTPCRELX, R_X86_64_CODE_5_GOTTPOFF,
	R_X86_64_CODE_5_GOTPC32_TLSDESC, R_X86_64_CODE_6_GOTPCRELX,
	R_X86_64_CODE_6_GOTTPOFF and R_X86_64_CODE_6_GOTPC32_TLSDESC.

ld/

	* testsuite/ld-x86-64/tlsbindesc.s: Add R_X86_64_CODE_6_GOTTPOFF
	tests.
	* testsuite/ld-x86-64/tlsbindesc.d: Updated.
	* testsuite/ld-x86-64/tlsbindesc.rd: Likewise.

(cherry picked from commit 5bc71c2a6b)
2024-02-10 08:23:26 -08:00
..
aarch64_globals.s
aarch64_pr23870_bar.c
aarch64_pr23870_foo.c
aarch64_pr23870_main.S
aarch64_reloc_none.s
aarch64_reloc_none.sh
aarch64_relocs.s
aarch64_relocs.sh
aarch64_tlsdesc.s
aarch64_tlsdesc.sh
aarch64_tlsdesc.t
arm_abs_global.s
arm_abs_global.sh
arm_abs_lib.s
arm_attr_merge_6a.s
arm_attr_merge_6b.s
arm_attr_merge_7a.s
arm_attr_merge_7b.s
arm_attr_merge.sh
arm_bl_in_range.s
arm_bl_out_of_range.s
arm_branch_in_range.sh
arm_branch_out_of_range.sh
arm_branch_range.t
arm_cortex_a8_b_cond.s
arm_cortex_a8_b_local.s
arm_cortex_a8_b.s
arm_cortex_a8_bl.s
arm_cortex_a8_blx.s
arm_cortex_a8_local_reloc.s
arm_cortex_a8_local.s
arm_cortex_a8.sh
arm_exidx_test.s
arm_exidx_test.sh
arm_farcall_arm_arm_be8.sh
arm_farcall_arm_arm.s
arm_farcall_arm_arm.sh
arm_farcall_arm_thumb.s
arm_farcall_arm_thumb.sh
arm_farcall_thumb_arm.s
arm_farcall_thumb_arm.sh
arm_farcall_thumb_thumb_be8.sh
arm_farcall_thumb_thumb.s
arm_farcall_thumb_thumb.sh
arm_fix_1176.s
arm_fix_1176.sh
arm_fix_v4bx.s
arm_fix_v4bx.sh
arm_target1_abs.sh
arm_target1_rel.sh
arm_target1.s
arm_target2_abs.sh
arm_target2_got_rel.sh
arm_target2_rel.sh
arm_target2.s
arm_target_lazy_init.s
arm_target_lazy_init.t
arm_thm_jump8.s
arm_thm_jump8.t
arm_thm_jump11.s
arm_thm_jump11.t
arm_unaligned_reloc.s
arm_unaligned_reloc.sh
basic_test.cc
binary_test.cc
binary_unittest.cc
binary.in
common_test_1_v1.c
common_test_1_v2.c
common_test_1.c
common_test_2.c
common_test_3.c
constructor_test.cc
copy_test_1.cc
copy_test_2.cc
copy_test_protected.cc
copy_test_protected.sh
copy_test_relro_1.cc
copy_test_relro.cc
copy_test_v1.cc
copy_test.cc
debug_msg.cc
debug_msg.sh
defsym_test.c
defsym_test.sh
discard_locals_relocatable_test.c
discard_locals_test.c
discard_locals_test.sh
dwp_test_1.cc
dwp_test_1.s
dwp_test_1.sh
dwp_test_1b.cc
dwp_test_1b.s
dwp_test_2.cc
dwp_test_2.s
dwp_test_2.sh
dwp_test_main.cc
dwp_test_main.s
dwp_test.h
dyn_weak_ref_1.c
dyn_weak_ref_2.c
dyn_weak_ref.sh
dynamic_list_2.cc
dynamic_list_2.t
dynamic_list_lib1.cc
dynamic_list_lib2.cc
dynamic_list.sh
dynamic_list.t
eh_test_2.sh
eh_test_a.cc
eh_test_b.cc
ehdr_start_def.cc
ehdr_start_test_4.sh
ehdr_start_test.cc
ehdr_start_test.t
empty_command_line_test.sh
exception_test_1.cc
exception_test_2.cc
exception_test_main.cc
exception_test.h
exclude_libs_test_1.c
exclude_libs_test_2.c
exclude_libs_test_3.c
exclude_libs_test.c
exclude_libs_test.sh
export_dynamic_plugin.cc
file_in_many_sections_test.sh
file_in_many_sections.c
final_layout.cc
final_layout.sh
gc_comdat_test_1.cc
gc_comdat_test_2.cc
gc_comdat_test.sh
gc_dynamic_list_test.c
gc_dynamic_list_test.sh
gc_dynamic_list_test.t
gc_orphan_section_test.cc
gc_orphan_section_test.sh
gc_tls_test.cc
gc_tls_test.sh
gdb_index_test_1.sh
gdb_index_test_2_gabi.sh
gdb_index_test_2_zstd.sh
gdb_index_test_2.sh
gdb_index_test_3.c
gdb_index_test_3.sh
gdb_index_test_4.sh
gdb_index_test_comm.sh
gdb_index_test.cc
gnu_property_a.S
gnu_property_b.S
gnu_property_c.S
gnu_property_main.c
gnu_property_test.sh
hidden_test_1.c
hidden_test_main.c
hidden_test.sh
i386_mov_to_lea1.s
i386_mov_to_lea2.s
i386_mov_to_lea3.s
i386_mov_to_lea4.s
i386_mov_to_lea5.s
i386_mov_to_lea.sh
icf_keep_unique_test.cc
icf_keep_unique_test.sh
icf_preemptible_functions_test.cc
icf_preemptible_functions_test.sh
icf_safe_pie_test.sh
icf_safe_so_test.cc
icf_safe_so_test.sh
icf_safe_test.cc
icf_safe_test.sh
icf_sht_rel_addend_test_1.cc
icf_sht_rel_addend_test_2.cc
icf_sht_rel_addend_test.sh
icf_string_merge_test.cc
icf_string_merge_test.sh
icf_test_pr21066.cc
icf_test_pr21066.sh
icf_test.cc
icf_test.sh
icf_virtual_function_folding_test.cc
ifunc-sel.h
ifuncdep2.c
ifuncmain1.c
ifuncmain1vis.c
ifuncmain2.c
ifuncmain3.c
ifuncmain4.c
ifuncmain5.c
ifuncmain6pie.c
ifuncmain7.c
ifuncmod1.c
ifuncmod1.sh
ifuncmod3.c
ifuncmod5.c
ifuncmod6.c
ifuncvar1.c
ifuncvar2.c
ifuncvar3.c
incr_comdat_test_1.cc
incr_comdat_test_2_v1.cc
incr_comdat_test_2_v2.cc
incr_comdat_test_2_v3.cc
incremental_test_1.c
incremental_test_2.c
incremental_test.sh
initpri1.c
initpri2.c
initpri3.c
justsyms_1.cc
justsyms_2.cc
justsyms_exec.c
justsyms_lib.c
justsyms_lib.t
justsyms.t
keep_text_section_prefix.cc
keep_text_section_prefix.sh
large_symbol_alignment.cc
large.c
leb128_unittest.cc
Makefile.am
Makefile.in
many_sections_test.cc
memory_test_inc_1.t.src
memory_test_inc_2.t.src
memory_test_inc_3.t.src
memory_test_inc.t
memory_test.s
memory_test.sh
memory_test.t
merge_string_literals_1.cc
merge_string_literals_2.cc
merge_string_literals.sh
missing_key_func.cc
missing_key_func.sh
no_version_test.c
no_version_test.sh
object_unittest.cc
odr_header1.h
odr_header2.h
odr_violation1.cc
odr_violation2.cc
overflow_unittest.cc
package_metadata_main.c
pie_copyrelocs_shared_test.cc
pie_copyrelocs_test.cc
plugin_common_test_1.c
plugin_common_test_2.c
plugin_final_layout.cc
plugin_final_layout.sh
plugin_layout_with_alignment.c
plugin_layout_with_alignment.sh
plugin_new_section_layout.c
plugin_pr22868_a.c
plugin_pr22868_b.c
plugin_pr22868.sh
plugin_section_alignment.cc
plugin_section_order.c
plugin_start_lib_test_2.c
plugin_start_lib_test.c
plugin_test_1.sh
plugin_test_2.sh
plugin_test_3.sh
plugin_test_4.sh
plugin_test_6.sh
plugin_test_7_1.c
plugin_test_7_2.c
plugin_test_7.sh
plugin_test_9b_elf.cc
plugin_test_9b_ir.cc
plugin_test_10.sh
plugin_test_11.sh
plugin_test_12.sh
plugin_test_defsym.c
plugin_test_defsym.sh
plugin_test_start_lib.sh
plugin_test_tls.sh
plugin_test_wrap_symbols_1.cc
plugin_test_wrap_symbols_2.cc
plugin_test_wrap_symbols.sh
plugin_test.c
pr12826_1.s
pr12826_2.s
pr12826.sh
pr14265.c
pr14265.sh
pr14265.t
pr17704a_test.s
pr18689.c
pr18689.sh
pr20216_def.c
pr20216_gd.S
pr20216_ld.S
pr20216_main.c
pr20308_def.c
pr20308_gd.S
pr20308_ld.S
pr20308_main.c
pr20717.c
pr20717.sh
pr20717.t
pr20976.c
pr21430.s
pr21430.sh
pr22266_a.c
pr22266_main.c
pr22266_script.t
pr23016_1.sh
pr23016_1a.s
pr23016_1b.s
pr23016_2.sh
pr23016_2a.s
pr23016_2b.s
pr26936.sh
pr26936a.s
pr26936b.s
pr26936c.s
pr26936d.s
protected_1.cc
protected_2.cc
protected_3.cc
protected_4.cc
protected_main_1.cc
protected_main_2.cc
protected_main_3.cc
relro_script_test.t
relro_test_main.cc
relro_test.cc
relro_test.sh
retain_1.s
retain_2.s
retain_symbols_file_test.sh
retain.sh
script_test_1.h
script_test_1.t
script_test_1a.cc
script_test_1b.cc
script_test_2.cc
script_test_2.t
script_test_2a.cc
script_test_2b.cc
script_test_3.sh
script_test_3.t
script_test_4.sh
script_test_4.t
script_test_5.cc
script_test_5.sh
script_test_5.t
script_test_6.sh
script_test_6.t
script_test_7.sh
script_test_7.t
script_test_8.sh
script_test_9.cc
script_test_9.sh
script_test_9.t
script_test_10.s
script_test_10.sh
script_test_10.t
script_test_11.h
script_test_11.t
script_test_11a.c
script_test_11b.c
script_test_12.t
script_test_12a.c
script_test_12b.c
script_test_12i.t
script_test_13.c
script_test_13.sh
script_test_13.t
script_test_14.s
script_test_14.sh
script_test_14.t
script_test_15.c
script_test_15a.sh
script_test_15a.t
script_test_15b.sh
script_test_15b.t
script_test_15c.sh
script_test_15c.t
searched_file_test_lib.cc
searched_file_test.cc
section_sorting_name.cc
section_sorting_name.sh
split_i386_1.s
split_i386_2.s
split_i386_3.s
split_i386_4.s
split_i386_n.s
split_i386.sh
split_s390_1_a1.s
split_s390_1_a2.s
split_s390_1_n1.s
split_s390_1_n2.s
split_s390_1_z1.s
split_s390_1_z2.s
split_s390_1_z3.s
split_s390_1_z4.s
split_s390_2_ns.s
split_s390_2_s.s
split_s390.sh
split_s390x_1_a1.s
split_s390x_1_a2.s
split_s390x_1_n1.s
split_s390x_1_n2.s
split_s390x_1_z1.s
split_s390x_1_z2.s
split_s390x_1_z3.s
split_s390x_1_z4.s
split_s390x_2_ns.s
split_s390x_2_s.s
split_x32_1.s
split_x32_2.s
split_x32_3.s
split_x32_4.s
split_x32_n.s
split_x32.sh
split_x86_64_1.s
split_x86_64_2.s
split_x86_64_3.s
split_x86_64_4.s
split_x86_64_n.s
split_x86_64.sh
start_lib_test_1.c
start_lib_test_2.c
start_lib_test_3.c
start_lib_test_main.c
strong_ref_weak_def_1.c
strong_ref_weak_def_2.c
strong_ref_weak_def.sh
test.cc
test.h
testfile.cc
testfile.h
testmain.cc
text_section_grouping.cc
text_section_grouping.sh
text_unlikely_segment.cc
text_unlikely_segment.sh
thin_archive_main.cc
thin_archive_test_1.cc
thin_archive_test_2.cc
thin_archive_test_3.cc
thin_archive_test_4.cc
thumb2_branch_range.t
thumb_bl_in_range.s
thumb_bl_out_of_range_local.s
thumb_bl_out_of_range.s
thumb_blx_in_range.s
thumb_blx_out_of_range.s
thumb_branch_range.t
tls_pie_test.sh
tls_test_c.c
tls_test_file2.cc
tls_test_main.cc
tls_test.cc
tls_test.h
two_file_shared.sh
two_file_test_1_v1.cc
two_file_test_1.cc
two_file_test_1b_v1.cc
two_file_test_1b.cc
two_file_test_2_tls.cc
two_file_test_2_v1.cc
two_file_test_2.cc
two_file_test_main.cc
two_file_test_tls.cc
two_file_test.h
undef_symbol_main.cc
undef_symbol.cc
undef_symbol.sh
ver_matching_def.cc
ver_matching_test.sh
ver_test_1.cc
ver_test_1.sh
ver_test_2.cc
ver_test_2.script
ver_test_2.sh
ver_test_3.cc
ver_test_4.cc
ver_test_4.script
ver_test_4.sh
ver_test_5.cc
ver_test_5.script
ver_test_5.sh
ver_test_6.c
ver_test_7.cc
ver_test_7.sh
ver_test_8.script
ver_test_8.sh
ver_test_9.cc
ver_test_10.script
ver_test_10.sh
ver_test_13.c
ver_test_13.script
ver_test_13.sh
ver_test_14.script
ver_test_14.sh
ver_test_main_2.cc
ver_test_main.cc
ver_test_pr16504_a.c
ver_test_pr16504_a.script
ver_test_pr16504_b.c
ver_test_pr16504_b.script
ver_test_pr16504.sh
ver_test_pr23409_1.script
ver_test_pr23409_2.script
ver_test_pr23409.sh
ver_test.h
version_script.map
weak_alias_test_1.cc
weak_alias_test_2.cc
weak_alias_test_3.cc
weak_alias_test_4.cc
weak_alias_test_5.cc
weak_alias_test_main.cc
weak_alias_test.script
weak_as_needed_a.c
weak_as_needed_b.c
weak_as_needed_b.script
weak_as_needed_c.c
weak_as_needed_c.script
weak_as_needed.sh
weak_plt_main.cc
weak_plt_shared.cc
weak_plt.sh
weak_test.cc
weak_undef_file1.cc
weak_undef_file2.cc
weak_undef_file3.cc
weak_undef_file4.cc
weak_undef_test_2.cc
weak_undef_test.cc
weak_undef.h
weak_unresolved_symbols_test.cc
x32_overflow_pc32.sh
x86_64_gd_to_le.s
x86_64_gd_to_le.sh
x86_64_ie_to_le.s
x86_64_ie_to_le.sh
x86_64_indirect_call_to_direct1.s
x86_64_indirect_call_to_direct.sh
x86_64_indirect_jump_to_direct1.s
x86_64_mov_to_lea1.s
x86_64_mov_to_lea2.s
x86_64_mov_to_lea3.s
x86_64_mov_to_lea4.s
x86_64_mov_to_lea5.s
x86_64_mov_to_lea.sh
x86_64_overflow_pc32.s
x86_64_overflow_pc32.sh