Unifies RISC-V TLS relocation handling in linker
RISC-V linker's relocation checking code now unifies handling for various TLS relocation types.
The RISC-V linker’s riscv_elf_check_relocs function now consolidates the handling of different Thread-Local Storage (TLS) relocation types. This unification simplifies the code by allowing common checks for relocations that map to GOT_TLS_IE or GOT_TLS_LE, improving maintainability.
In Details
In bfd/elfnn-riscv.c, this commit merges several case statements within riscv_elf_check_relocs that previously handled distinct RISC-V TLS relocation types (e.g., R_RISCV_TLS_GD_HI20, R_RISCV_TLS_GOT_HI20, R_RISCV_TLSDESC_HI20, R_RISCV_TPREL_HI20). The refactored code now uses a helper function riscv_elf_tls_type_from_hi_reloc to determine the TLS type and then applies common checks for GOT reference and TLS type recording, streamlining the relocation validation logic.
- TLS
- Thread-Local Storage. A mechanism that allows each thread in a process to have its own copy of a variable.
- relocation
- The process of updating symbolic references in an object file to absolute addresses, typically performed by the linker.
- RISC-V
- An open-standard instruction set architecture based on reduced instruction set computing principles.
- GOT
- Global Offset Table. A table used by dynamically linked executables to store addresses of functions and variables.
- IE
- Indirect Entry. A TLS access model where the address is retrieved from a descriptor.
- LE
- Local Entry. A TLS access model where the address is calculated directly relative to the thread pointer.