RISC-V: define elf_backend_dtrel_excludes_plt
RISC-V binutils patch defines elf_backend_dtrel_excludes_plt to correctly handle DT_RELASZ, preventing double processing by tools like llvm-bolt.
This patch defines elf_backend_dtrel_excludes_plt for the RISC-V port in binutils, correcting how DT_RELASZ is calculated. Previously, it incorrectly included .rela.plt sections, causing aliasing issues when .rela.dyn was empty. This led to tools like llvm-bolt processing sections twice. Defining the macro ensures DT_RELASZ excludes .rela.plt, aligning with other targets and resolving the aliasing problem.
- proposer
Submits a patch to define `elf_backend_dtrel_excludes_plt` for RISC-V to fix DT_RELASZ calculation and prevent double processing by tools.
“The RISC-V port never defined elf_backend_dtrel_excludes_plt, unlike x86-64, AArch64, arm, ppc, mips and s390. As a result DT_RELASZ counted .rela.dyn + .rela.plt instead of just .rela.dyn. With an empty .rela.dyn this makes DT_RELA alias DT_JMPREL (DT_RELA == DT_JMPREL, DT_RELASZ == DT_PLTRELSZ). glibc accepts the aliased range, but tools that read the two ranges independently, such as llvm-bol…”
In Details
This patch addresses an ELF parsing detail in binutils for the RISC-V architecture. It corrects the calculation of the DT_RELASZ dynamic tag by defining elf_backend_dtrel_excludes_plt. This macro ensures that the size of the relocation section (DT_RELASZ) correctly excludes the jump slot relocations (.rela.plt), preventing issues with tools like llvm-bolt that parse .rela.dyn and .rela.plt independently. This aligns RISC-V's behavior with other architectures like x86-64 and ARM.
- RISC-V
- An open-source instruction set architecture (ISA) based on reduced instruction set computing principles.
- ELF
- Executable and Linkable Format, a common standard file format for executable, object code, shared libraries, and core dumps on Unix-like systems.
- DT_RELASZ
- An entry in the ELF dynamic section that specifies the size of the relocation entries (Rela entries).
- DT_RELASZ
- An entry in the ELF dynamic section that specifies the size of the relocation entries (Rela entries).
- .rela.dyn
- An ELF section containing relocation entries that apply to the dynamic linker, used for resolving symbolic references at runtime.
- .rela.plt
- An ELF section containing relocation entries specifically for the Procedure Linkage Table (PLT), used to resolve dynamic function calls.
- llvm-bolt
- A post-linkage binary optimization tool from the LLVM project that optimizes executables by reordering code and data.