RISC-V linker supports TLSDESC relaxation for static executables
RISC-V linker now handles TLSDESC relaxation, enabling TLS support in static executables.
This change introduces TLSDESC relaxation for the RISC-V linker, allowing Thread-Local Storage (TLS) descriptors to be correctly handled in static executables. It rewrites TLS access sequences to work without runtime resolution, ensuring TLS functionality even when dynamic linking mechanisms are unavailable.
In Details
This commit enables TLSDESC relaxation in the RISC-V linker backend. It modifies elfnn-riscv.c to transform TLSDESC accesses into either GOT-indirect-entry (IE) or local-exec (LE) forms based on symbol locality, specifically for static executables where runtime descriptor resolution is impossible. The relaxation process ensures that code size remains consistent, either by deleting instructions when -mrelax is used or by rewriting sequences in-place otherwise, mimicking lld's behavior.
- TLSDESC
- Thread-Local Storage Descriptor. A mechanism for accessing thread-local variables, particularly useful for dynamically sized TLS regions.
- relaxation
- A linker optimization process that adjusts instruction addresses and forms to optimize code size or enable features like TLS access in static executables.
- static executable
- An executable file that contains all necessary code and data, without relying on external shared libraries at runtime.
- 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.