RISC-V: Add DT_RELR support for position-independent code
RISC-V now supports DT_RELR for efficient handling of position-independent code relocations.
This commit introduces support for DT_RELR in the RISC-V ELF toolchain, enhancing the handling of position-independent code (PIC). It includes modifications to the assembler, linker, and readelf utility to correctly process and display these relocations, mirroring implementations from AArch64 and LoongArch.
In Details
This patch brings DT_RELR support to RISC-V ELF, enabling the linker to generate RELR-based dynamic executables and shared objects. It introduces the DT_RELR dynamic tag and updates bfd/elfnn-riscv.c to handle relr-relocs.ld and associated special symbols like mapping symbols and __DATA_BEGIN__. binutils/readelf.c is updated to display these relocations, and ld/emulparams/elf32lriscv-defs.sh is modified to enable DT_RELR only for Linux. Test cases for RELR relocations and relaxation are also added. This is crucial for efficient PIC on RISC-V.
- DT_RELR
- A dynamic tag in an ELF file that indicates the presence of RELR (relative relocations) in the dynamic section. RELR is a more compact format for relocations used in position-independent code.
- Position-Independent Code (PIC)
- Code that can be loaded and executed at any memory address without modification. It's essential for shared libraries and modern executable security.
- Relocation
- Information in an object file that describes how to modify code or data after it has been linked, typically to resolve addresses or symbol references.
- ELF
- Executable and Linkable Format. A common file format for object files, executables, and shared libraries on Unix-like systems.
- DT_RELR
- A dynamic tag in an ELF file that indicates the presence of RELR (relative relocations) in the dynamic section. RELR is a more compact format for relocations used in position-independent code.
- Dynamic Section
- A section within an ELF file that contains information required by the dynamic linker, such as the shared libraries the program depends on and relocation information.
- readelf
- A utility that displays information about ELF files, including headers, sections, and symbols.
- linker
- A program that combines object files and libraries into an executable or library, resolving symbol references and performing relocations.