[PATCH 04/14] x86-64: use BFD_RELOC_32_PLT_PCREL in favor of custom type
Jan Beulich
jbeulich@suse.com
Fri Nov 28 11:30:35 GMT 2025
No reason to have a separate type when the generic one has no (other)
meaning for this target.
---
Why is it that BFD_RELOC_386_PLT32 (but not BFD_RELOC_X86_64_PLT32) is
among the types checked in TC_FORCE_RELOCATION_LOCAL()? Without that, the
type could also be replaced by BFD_RELOC_32_PLT_PCREL, then even
simplifying a couple of expressions.
Code and comment in tc_i386_fix_adjustable() as well as the conditional
in i386_validate_fix() suggest that PLT32 relocs can also be absolute.
The relocation types (32- and 64-bit) are clearly specified as PC-
relative, though. What's the deal? (Questionable commit is 1b714c14e40f
["x86: Turn PLT32 to PC32 only for PC-relative relocations"].) PR
gas/32196 really pointed at a bigger problem: If the programmer says @plt,
a PLT32 relocation ought to be generated, no matter what. Just like for
any of the other @... relocation modifiers. Dropping the relocation is an
optimization, which ought to not be active by default.
--- a/bfd/bfd-in2.h
+++ b/bfd/bfd-in2.h
@@ -3881,7 +3881,6 @@ enum bfd_reloc_code_real
/* x86-64/elf relocations. */
BFD_RELOC_X86_64_GOT32,
- BFD_RELOC_X86_64_PLT32,
BFD_RELOC_X86_64_COPY,
BFD_RELOC_X86_64_GLOB_DAT,
BFD_RELOC_X86_64_JUMP_SLOT,
--- a/bfd/elf64-x86-64.c
+++ b/bfd/elf64-x86-64.c
@@ -233,7 +233,7 @@ static const struct elf_reloc_map x86_64
{ BFD_RELOC_64, R_X86_64_64, },
{ BFD_RELOC_32_PCREL, R_X86_64_PC32, },
{ BFD_RELOC_X86_64_GOT32, R_X86_64_GOT32,},
- { BFD_RELOC_X86_64_PLT32, R_X86_64_PLT32,},
+ { BFD_RELOC_32_PLT_PCREL, R_X86_64_PLT32,},
{ BFD_RELOC_X86_64_COPY, R_X86_64_COPY, },
{ BFD_RELOC_X86_64_GLOB_DAT, R_X86_64_GLOB_DAT, },
{ BFD_RELOC_X86_64_JUMP_SLOT, R_X86_64_JUMP_SLOT, },
--- a/bfd/libbfd.h
+++ b/bfd/libbfd.h
@@ -1445,7 +1445,6 @@ static const char *const bfd_reloc_code_
"BFD_RELOC_386_IRELATIVE",
"BFD_RELOC_386_GOT32X",
"BFD_RELOC_X86_64_GOT32",
- "BFD_RELOC_X86_64_PLT32",
"BFD_RELOC_X86_64_COPY",
"BFD_RELOC_X86_64_GLOB_DAT",
"BFD_RELOC_X86_64_JUMP_SLOT",
--- a/bfd/reloc.c
+++ b/bfd/reloc.c
@@ -2416,8 +2416,6 @@ ENUMDOC
ENUM
BFD_RELOC_X86_64_GOT32
ENUMX
- BFD_RELOC_X86_64_PLT32
-ENUMX
BFD_RELOC_X86_64_COPY
ENUMX
BFD_RELOC_X86_64_GLOB_DAT
--- a/gas/config/tc-i386.c
+++ b/gas/config/tc-i386.c
@@ -1396,7 +1396,7 @@ gotrel[] =
BFD_RELOC_64_PLTOFF },
{ .bitfield = { .imm64 = 1 } }, true },
{ STRING_COMMA_LEN ("PLT"), { BFD_RELOC_386_PLT32,
- BFD_RELOC_X86_64_PLT32 },
+ BFD_RELOC_32_PLT_PCREL },
OPERAND_TYPE_IMM32_32S_DISP32, false },
{ STRING_COMMA_LEN ("GOTPLT"), { _dummy_first_bfd_reloc_code_real,
BFD_RELOC_X86_64_GOTPLT64 },
@@ -4138,7 +4138,7 @@ tc_i386_fix_adjustable (fixS *fixP)
/* Resolve PLT32 relocation against local symbol to section only for
PC-relative relocations. */
if (fixP->fx_r_type == BFD_RELOC_386_PLT32
- || fixP->fx_r_type == BFD_RELOC_X86_64_PLT32)
+ || fixP->fx_r_type == BFD_RELOC_32_PLT_PCREL)
return fixP->fx_pcrel;
return 1;
}
@@ -11778,7 +11778,7 @@ output_jump (void)
if (flag_code == CODE_64BIT && size == 4
&& jump_reloc == NO_RELOC && i.op[0].disps->X_add_number == 0
&& need_plt32_p (i.op[0].disps->X_add_symbol))
- jump_reloc = BFD_RELOC_X86_64_PLT32;
+ jump_reloc = BFD_RELOC_32_PLT_PCREL;
#endif
jump_reloc = reloc (size, 1, 1, jump_reloc);
@@ -13424,7 +13424,7 @@ x86_cons (expressionS *exp, int size)
*input_line_pointer = c;
}
else if ((got_reloc == BFD_RELOC_386_PLT32
- || got_reloc == BFD_RELOC_X86_64_PLT32)
+ || got_reloc == BFD_RELOC_32_PLT_PCREL)
&& exp->X_op != O_symbol)
{
char c = *input_line_pointer;
@@ -15768,7 +15768,7 @@ elf_symbol_resolved_in_segment_p (symbol
switch ((enum bfd_reloc_code_real) fr_var)
{
case BFD_RELOC_386_PLT32:
- case BFD_RELOC_X86_64_PLT32:
+ case BFD_RELOC_32_PLT_PCREL:
/* Symbol with PLT relocation may be preempted. */
return 0;
default:
@@ -16229,7 +16229,7 @@ md_estimate_size_before_relax (fragS *fr
&& fragP->tc_frag_data.code == CODE_64BIT
&& fragP->fr_offset == 0
&& need_plt32_p (fragP->fr_symbol))
- reloc_type = BFD_RELOC_X86_64_PLT32;
+ reloc_type = BFD_RELOC_32_PLT_PCREL;
#endif
old_fr_fix = fragP->fr_fix;
@@ -16633,7 +16633,7 @@ md_apply_fix (fixS *fixP, valueT *valP,
switch (fixP->fx_r_type)
{
case BFD_RELOC_386_PLT32:
- case BFD_RELOC_X86_64_PLT32:
+ case BFD_RELOC_32_PLT_PCREL:
/* Make the jump instruction point to the address of the operand.
At runtime we merely add the offset to the actual PLT entry.
NB: Subtract the offset size only for jump instructions. */
@@ -18350,7 +18350,7 @@ i386_validate_fix (fixS *fixp)
if (fixp->fx_addsy
&& fixp->fx_pcrel
&& (fixp->fx_r_type == BFD_RELOC_386_PLT32
- || fixp->fx_r_type == BFD_RELOC_X86_64_PLT32)
+ || fixp->fx_r_type == BFD_RELOC_32_PLT_PCREL)
&& symbol_section_p (fixp->fx_addsy))
fixp->fx_r_type = BFD_RELOC_32_PCREL;
if (!object_64bit)
@@ -18426,7 +18426,7 @@ tc_gen_reloc (asection *section ATTRIBUT
#endif
/* Fall through. */
- case BFD_RELOC_X86_64_PLT32:
+ case BFD_RELOC_32_PLT_PCREL:
case BFD_RELOC_X86_64_GOT32:
case BFD_RELOC_X86_64_GOTPCREL:
case BFD_RELOC_X86_64_GOTPCRELX:
@@ -18593,7 +18593,7 @@ tc_gen_reloc (asection *section ATTRIBUT
else
switch (code)
{
- case BFD_RELOC_X86_64_PLT32:
+ case BFD_RELOC_32_PLT_PCREL:
case BFD_RELOC_X86_64_GOT32:
case BFD_RELOC_X86_64_GOTPCREL:
case BFD_RELOC_X86_64_GOTPCRELX:
More information about the Binutils
mailing list