binutils Newspaper
JULY 29, 2026
x86 Proposed

x86: Generate PLT32 relocation for .long foo@PLT - .L4

Adds support for generating PLT32 relocations for x86 and x86-64, mirroring LLVM assembler's behavior for directives like '.long foo@PLT - .L4'.

This patch introduces support for generating PLT32 relocations for x86 and x86-64 architectures, aligning with the functionality of the LLVM assembler. It enables the handling of directives such as “.long foo@PLT - .L4” by generating R_X86_64_PLT32 relocations, which utilize PLT entries to resolve PC32 relocations against function symbols. This addresses PR gas/34423 and includes updates to BFD, gas, and ld components, along with new test cases.

In the Thread 1 participant
  1. H.J. Lu <hjl.tools@gmail.com> proposer

    Submits a v2 patch to add PLT32 relocation generation for x86 and x86-64, mirroring LLVM assembler and addressing PR gas/34423.

    “Add i386 support like LLVM assembler in the v2 patch. LLVM assembler supports directives like ".long foo@PLT - .L4" for i386 and x86-64. Implement the same feature to generate PLT32 relocation for directives like ".long foo@PLT - .L4" so that PLT entries are used to resolve the PC32 relocation against function symbols.”

In Details

This patch series (v2) introduces support for the BFD_RELOC_X86_64_PLT32 relocation type in the binutils, specifically for the x86-64 and i386 architectures. It enables the assembler (gas) to generate R_X86_64_PLT32 for expressions like .long foo@PLT - .L4, which involves calculating a PC-relative offset to a PLT entry. This behavior mirrors that of the LLVM assembler. The changes span BFD (by adding the new relocation type), gas (by modifying the assembler's logic to recognize and generate this relocation), and ld (with test cases). The goal is to ensure that indirect function calls us…

For Context
PLT
Procedure Linkage Table. A table used in executable files and shared libraries to resolve indirect function calls to functions that are not defined in the current module, typically used for dynamic linking.
PLT32 / R_X86_64_PLT32
A specific type of ELF relocation used on x86-64 architectures. It indicates that a 32-bit PC-relative offset to an entry in the Procedure Linkage Table (PLT) needs to be calculated and patched into the code at link time.
PC32 relocation
A type of relocation that calculates an offset relative to the current Program Counter (PC). On x86-64, R_X86_64_PC32 is used for 32-bit PC-relative addressing.
BFD
Binary File Descriptor library. A library used by GNU Binutils to provide a common interface for reading and writing various object file formats.
gas
The GNU Assembler, part of the GNU Binutils, responsible for translating assembly language code into machine code.
ld
The GNU linker, responsible for combining object files and libraries into an executable or shared library.
PR gas/34423
Problem Report number 34423 filed against the GNU Assembler, likely related to the functionality addressed by this patch.
Filed Under: x86relocationassemblerlinkerpatch