x86: Don't put R_386_TLS_DESC/R_X86_64_TLSDESC in .rel.plt/.rela.plt

Since lazy tlsdesc relocation has data races:

https://sourceware.org/bugzilla/show_bug.cgi?id=27137

put R_386_TLS_DESC and R_X86_64_TLSDESC relocation in .rela.tls/.rel.tls
section, instead of .rel.plt/.rela.plt section.

Tested with glibc/i686 and glibc/x86-64 compiled with -mtls-dialect=gnu2
as well as GCC 16 configured with --with-tls=gnu2.

bfd/

	PR ld/28387
	* elf32-i386.c (elf_i386_relocate_section): Put R_386_TLS_DESC
	in rel_tls_desc instead of elf.srelplt.
	* elf64-x86-64.c (elf_x86_64_relocate_section): Put
	R_X86_64_TLSDESC in rel_tls_desc instead of elf.srelplt.
	* elfxx-x86.c (elf_x86_allocate_dynrelocs): Use rel_tls_desc,
	instead of elf.srelplt, for GOT_TLS_GDESC_P.
	(_bfd_elf_x86_get_reloc_section): New function.
	(_bfd_x86_elf_late_size_sections): Use rel_tls_desc, instead of
	elf.srelplt, for GOT_TLS_GDESC_P.  Remove next_tls_desc_index.
	(_bfd_x86_elf_link_setup_gnu_properties): Allocate
	.rela.tls/.rel.tls section for rel_tls_desc.
	* elfxx-x86.h (elf_x86_link_hash_table): Add rel_tls_desc.
	Remove next_tls_desc_index.
	(_bfd_elf_x86_get_reloc_section): New.
	(elf_backend_get_reloc_section): Likewise.

ld/

	PR ld/28387
	* emulparams/elf32_x86_64.sh (OTHER_GOT_RELOC_SECTIONS): New.
	* emulparams/elf_i386.sh (OTHER_GOT_RELOC_SECTIONS): Likewise.
	* emulparams/elf_x86_64.sh (OTHER_GOT_RELOC_SECTIONS): Likewise.
	* testsuite/ld-i386/i386.exp: Run pr28387.
	* testsuite/ld-i386/pr17057.d: Adjusted
	* testsuite/ld-i386/tlsdesc.rd: Likewise.
	* testsuite/ld-i386/tlsdesc2.d: Likewise.
	* testsuite/ld-i386/tlsgdesc.rd: Likewise.
	* testsuite/ld-x86-64/tlsdesc.pd: Likewise.
	* testsuite/ld-x86-64/tlsdesc.rd: Likewise.
	* testsuite/ld-x86-64/tlsdesc2.d: Likewise.
	* testsuite/ld-x86-64/tlsgdesc.rd: Likewise.
	* testsuite/ld-i386/pr28387.d: New file.
	* testsuite/ld-i386/pr28387.s: Likewise.
	* testsuite/ld-x86-64/pr28387-x32.d: Likewise.
	* testsuite/ld-x86-64/pr28387.d: Likewise.
	* testsuite/ld-x86-64/pr28387.s: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Run pr28387 and pr28387-x32.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
22 files changed