From ada0364f80a7694ba90fb7869ec197cba873098c Mon Sep 17 00:00:00 2001 From: jca Date: Thu, 11 Jan 2024 12:31:37 +0000 Subject: [PATCH] Add basic support for R_386_GOT32X Repairs ld.bfd operations on i386: since the switch to llvm-16 clang emits such relocations (eg one is present in /usr/lib/crtbegin.o). This unbreaks the build of ports/lang/fpc. Help and tests from tb@, ok tb@ kettenis@ --- gnu/usr.bin/binutils-2.17/bfd/bfd-in2.h | 1 + gnu/usr.bin/binutils-2.17/bfd/elf32-i386.c | 15 ++++++++++++++- gnu/usr.bin/binutils-2.17/bfd/libbfd.h | 1 + gnu/usr.bin/binutils-2.17/gas/config/tc-i386.c | 3 +++ gnu/usr.bin/binutils-2.17/gas/config/tc-i386.h | 1 + gnu/usr.bin/binutils-2.17/include/elf/i386.h | 1 + 6 files changed, 21 insertions(+), 1 deletion(-) diff --git a/gnu/usr.bin/binutils-2.17/bfd/bfd-in2.h b/gnu/usr.bin/binutils-2.17/bfd/bfd-in2.h index e17a29d4086..ed9a2b76859 100644 --- a/gnu/usr.bin/binutils-2.17/bfd/bfd-in2.h +++ b/gnu/usr.bin/binutils-2.17/bfd/bfd-in2.h @@ -2699,6 +2699,7 @@ in the instruction. */ BFD_RELOC_386_TLS_GOTDESC, BFD_RELOC_386_TLS_DESC_CALL, BFD_RELOC_386_TLS_DESC, + BFD_RELOC_386_GOT32X, /* x86-64/elf relocations */ BFD_RELOC_X86_64_GOT32, diff --git a/gnu/usr.bin/binutils-2.17/bfd/elf32-i386.c b/gnu/usr.bin/binutils-2.17/bfd/elf32-i386.c index cecc7e8b7b2..1575771e6c0 100644 --- a/gnu/usr.bin/binutils-2.17/bfd/elf32-i386.c +++ b/gnu/usr.bin/binutils-2.17/bfd/elf32-i386.c @@ -136,9 +136,14 @@ static reloc_howto_type elf_howto_table[]= HOWTO(R_386_TLS_DESC, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_386_TLS_DESC", TRUE, 0xffffffff, 0xffffffff, FALSE), + EMPTY_HOWTO (42), /* R_386_IRELATIVE */ + HOWTO(R_386_GOT32X, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, + bfd_elf_generic_reloc, "R_386_GOT32X", + TRUE, 0xffffffff, 0xffffffff, FALSE), /* Another gap. */ -#define R_386_tls (R_386_TLS_DESC + 1 - R_386_tls_offset) + /* XXX R_386_GOT32X isn't really a TLS relocation */ +#define R_386_tls (R_386_GOT32X + 1 - R_386_tls_offset) #define R_386_vt_offset (R_386_GNU_VTINHERIT - R_386_tls) /* GNU extension to record C++ vtable hierarchy. */ @@ -314,6 +319,10 @@ elf_i386_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, TRACE ("BFD_RELOC_386_TLS_DESC"); return &elf_howto_table[R_386_TLS_DESC - R_386_tls_offset]; + case BFD_RELOC_386_GOT32X: + TRACE ("BFD_RELOC_386_GOT32X"); + return &elf_howto_table[R_386_GOT32X - R_386_tls_offset]; + case BFD_RELOC_VTABLE_INHERIT: TRACE ("BFD_RELOC_VTABLE_INHERIT"); return &elf_howto_table[R_386_GNU_VTINHERIT - R_386_vt_offset]; @@ -993,6 +1002,7 @@ elf_i386_check_relocs (bfd *abfd, /* Fall through */ case R_386_GOT32: + case R_386_GOT32X: case R_386_TLS_GD: case R_386_TLS_GOTDESC: case R_386_TLS_DESC_CALL: @@ -1004,6 +1014,7 @@ elf_i386_check_relocs (bfd *abfd, { default: case R_386_GOT32: tls_type = GOT_NORMAL; break; + case R_386_GOT32X: tls_type = GOT_NORMAL; break; case R_386_TLS_GD: tls_type = GOT_TLS_GD; break; case R_386_TLS_GOTDESC: case R_386_TLS_DESC_CALL: @@ -1392,6 +1403,7 @@ elf_i386_gc_sweep_hook (bfd *abfd, case R_386_TLS_IE: case R_386_TLS_GOTIE: case R_386_GOT32: + case R_386_GOT32X: if (h != NULL) { if (h->got.refcount > 0) @@ -2452,6 +2464,7 @@ elf_i386_relocate_section (bfd *output_bfd, switch (r_type) { case R_386_GOT32: + case R_386_GOT32X: /* Relocation is to the entry for this symbol in the global offset table. */ if (htab->sgot == NULL) diff --git a/gnu/usr.bin/binutils-2.17/bfd/libbfd.h b/gnu/usr.bin/binutils-2.17/bfd/libbfd.h index e7151a8ae7a..6bf1dd14a20 100644 --- a/gnu/usr.bin/binutils-2.17/bfd/libbfd.h +++ b/gnu/usr.bin/binutils-2.17/bfd/libbfd.h @@ -1050,6 +1050,7 @@ static const char *const bfd_reloc_code_real_names[] = { "@@uninitialized@@", "BFD_RELOC_386_TLS_GOTDESC", "BFD_RELOC_386_TLS_DESC_CALL", "BFD_RELOC_386_TLS_DESC", + "BFD_RELOC_386_GOT32X", "BFD_RELOC_X86_64_GOT32", "BFD_RELOC_X86_64_PLT32", "BFD_RELOC_X86_64_COPY", diff --git a/gnu/usr.bin/binutils-2.17/gas/config/tc-i386.c b/gnu/usr.bin/binutils-2.17/gas/config/tc-i386.c index d0f3bb58dea..2dcd133f1d6 100644 --- a/gnu/usr.bin/binutils-2.17/gas/config/tc-i386.c +++ b/gnu/usr.bin/binutils-2.17/gas/config/tc-i386.c @@ -1313,6 +1313,7 @@ tc_i386_fix_adjustable (fixP) if (fixP->fx_r_type == BFD_RELOC_386_GOTOFF || fixP->fx_r_type == BFD_RELOC_386_PLT32 || fixP->fx_r_type == BFD_RELOC_386_GOT32 + || fixP->fx_r_type == BFD_RELOC_386_GOT32X || fixP->fx_r_type == BFD_RELOC_386_TLS_GD || fixP->fx_r_type == BFD_RELOC_386_TLS_LDM || fixP->fx_r_type == BFD_RELOC_386_TLS_LDO_32 @@ -5142,6 +5143,7 @@ md_apply_fix (fixP, valP, seg) return; case BFD_RELOC_386_GOT32: + case BFD_RELOC_386_GOT32X: case BFD_RELOC_X86_64_GOT32: value = 0; /* Fully resolved at runtime. No addend. */ break; @@ -5708,6 +5710,7 @@ tc_gen_reloc (section, fixp) case BFD_RELOC_X86_64_GOTPCREL: case BFD_RELOC_386_PLT32: case BFD_RELOC_386_GOT32: + case BFD_RELOC_386_GOT32X: case BFD_RELOC_386_GOTOFF: case BFD_RELOC_386_GOTPC: case BFD_RELOC_386_TLS_GD: diff --git a/gnu/usr.bin/binutils-2.17/gas/config/tc-i386.h b/gnu/usr.bin/binutils-2.17/gas/config/tc-i386.h index c77420d6b55..93e548582fe 100644 --- a/gnu/usr.bin/binutils-2.17/gas/config/tc-i386.h +++ b/gnu/usr.bin/binutils-2.17/gas/config/tc-i386.h @@ -445,6 +445,7 @@ extern int tc_i386_fix_adjustable PARAMS ((struct fix *)); || (FIX)->fx_plt \ || (FIX)->fx_r_type == BFD_RELOC_386_PLT32 \ || (FIX)->fx_r_type == BFD_RELOC_386_GOT32 \ + || (FIX)->fx_r_type == BFD_RELOC_386_GOT32X \ || (FIX)->fx_r_type == BFD_RELOC_386_GOTPC \ || (FIX)->fx_r_type == BFD_RELOC_X86_64_GOTPCREL \ || TC_FORCE_RELOCATION (FIX)) diff --git a/gnu/usr.bin/binutils-2.17/include/elf/i386.h b/gnu/usr.bin/binutils-2.17/include/elf/i386.h index e167871f34a..9033224accf 100644 --- a/gnu/usr.bin/binutils-2.17/include/elf/i386.h +++ b/gnu/usr.bin/binutils-2.17/include/elf/i386.h @@ -66,6 +66,7 @@ START_RELOC_NUMBERS (elf_i386_reloc_type) RELOC_NUMBER (R_386_TLS_GOTDESC, 39) RELOC_NUMBER (R_386_TLS_DESC_CALL,40) RELOC_NUMBER (R_386_TLS_DESC, 41) + RELOC_NUMBER (R_386_GOT32X, 43) /* 32 bit GOT entry */ /* Used by Intel. */ RELOC_NUMBER (R_386_USED_BY_INTEL_200, 200) -- 2.20.1