[PATCH v2 2/3] x86-64/ELF: use new reloc override model to deal with x32 special case
Jan Beulich
jbeulich@suse.com
Fri Mar 4 13:35:21 GMT 2022
Fold the two custom adjustments into a single new case block in
elf_x86_64_reloc_override().
--- a/bfd/elf64-x86-64.c
+++ b/bfd/elf64-x86-64.c
@@ -185,12 +185,13 @@ static reloc_howto_type x86_64_elf_howto
HOWTO (R_X86_64_GNU_VTENTRY, 0, 4, 0, false, 0, complain_overflow_dont,
_bfd_elf_rel_vtable_reloc_fn, "R_X86_64_GNU_VTENTRY", false, 0, 0,
false),
+};
/* Use complain_overflow_bitfield on R_X86_64_32 for x32. */
+static reloc_howto_type x86_64_howto_32_x32 =
HOWTO(R_X86_64_32, 0, 2, 32, false, 0, complain_overflow_bitfield,
bfd_elf_generic_reloc, "R_X86_64_32", false, 0, 0xffffffff,
- false)
-};
+ false);
static reloc_howto_type x86_64_howto_pc32_lax =
HOWTO(R_X86_64_PC32, 0, 2, 32, true, 0, complain_overflow_bitfield,
@@ -266,6 +267,11 @@ elf_x86_64_reloc_override (const bfd *ab
default:
break;
+ case R_X86_64_32:
+ if (ABI_64_P (abfd))
+ break;
+ return &x86_64_howto_32_x32;
+
case R_X86_64_PC32:
if (params == NULL || params->pcrel_relocs != pcrel_relocs_lax)
break;
@@ -285,15 +291,8 @@ elf_x86_64_rtype_to_howto (bfd *abfd, un
{
unsigned i;
- if (r_type == (unsigned int) R_X86_64_32)
- {
- if (ABI_64_P (abfd))
- i = r_type;
- else
- i = ARRAY_SIZE (x86_64_elf_howto_table) - 1;
- }
- else if (r_type < (unsigned int) R_X86_64_GNU_VTINHERIT
- || r_type >= (unsigned int) R_X86_64_max)
+ if (r_type < (unsigned int) R_X86_64_GNU_VTINHERIT
+ || r_type >= (unsigned int) R_X86_64_max)
{
if (r_type >= (unsigned int) R_X86_64_standard)
{
@@ -334,15 +333,6 @@ elf_x86_64_reloc_name_lookup (bfd *abfd,
{
unsigned int i;
- if (!ABI_64_P (abfd) && strcasecmp (r_name, "R_X86_64_32") == 0)
- {
- /* Get x32 R_X86_64_32. */
- reloc_howto_type *reloc
- = &x86_64_elf_howto_table[ARRAY_SIZE (x86_64_elf_howto_table) - 1];
- BFD_ASSERT (reloc->type == (unsigned int) R_X86_64_32);
- return reloc;
- }
-
for (i = 0; i < ARRAY_SIZE (x86_64_elf_howto_table); i++)
if (x86_64_elf_howto_table[i].name != NULL
&& strcasecmp (x86_64_elf_howto_table[i].name, r_name) == 0)
More information about the Binutils
mailing list