x86-64: Generate R_X86_64_PLT32 for ".long foo@PLT - .L4"
Adds a new relocation type R_X86_64_PLT32 to binutils for specific PIC scenarios involving PLT entries.
This patch introduces the BFD_RELOC_X86_64_PLT32 relocation type and uses it in the gas assembler for x86-64 targets. This addresses PR gas/34423 by generating the R_X86_64_PLT32 relocation for directives like .long foo@PLT - .L4. The intention is to ensure that relocations against function symbols in such directives are correctly resolved using PLT entries, specifically for PC32 relative relocations.
- proposer
Submits a patch to introduce and utilize the R_X86_64_PLT32 relocation type for specific directives involving PLT entries.
“Add BFD_RELOC_X86_64_PLT32 and use it to generate R_X86_64_PLT32 for directives like ".long foo@PLT - .L4" so that PLT entries are used to resolve the PC32 relocation against function symbols for such directives.”
In Details
This patch enhances binutils' handling of x86-64 relocations, particularly for Position Independent Code (PIC). It introduces a new relocation type, R_X86_64_PLT32, which is a PC-relative 32-bit relocation specifically designed for accessing Procedure Linkage Table (PLT) entries. This is necessary for constructs like .long symbol@PLT - offset, ensuring that the linker correctly resolves the address using the PLT mechanism rather than a direct symbol lookup, which is crucial for shared library calls in PIC.
- x86-64
- A 64-bit microarchitecture and instruction set extension of the x86 instruction set, commonly used in modern desktop and server CPUs.
- PLT
- Procedure Linkage Table. A table used in dynamically linked executables on systems like Linux to resolve external function calls at runtime. It helps achieve Position Independent Code (PIC).
- R_X86_64_PLT32
- A specific relocation type for the x86-64 architecture, indicating a 32-bit PC-relative offset to a Procedure Linkage Table entry.
- Position Independent Code (PIC)
- Code that can run correctly regardless of where it is loaded in memory. Essential for shared libraries.
- gas
- The GNU Assembler, a component of the GNU Binutils package that translates assembly language code into machine code.
- BFD
- Binary File Descriptor. A library within GNU Binutils that provides a consistent interface for reading and writing various object file formats.