Validate GOT/PLT/TLS relocations for x86.
Binutils now checks for invalid GOT, PLT, and TLS relocations on x86 to prevent linker errors.
The binutils linker now performs more thorough checks for invalid GOT (Global Offset Table), PLT (Procedure Linkage Table), and TLS (Thread-Local Storage) relocations on x86 architectures. Specifically, it will now report errors for TLS, GOT, and PLT relocations in non-allocating sections, and for TLS relocations targeting non-thread-local symbols. These checks address issues reported in PR ld/34444 and PR ld/34448, enhancing linker robustness and error reporting.
In Details
This commit refines ELF relocation validation for x86 targets. It extends checks in scan_relocs and relocate_section to catch invalid uses of GOT, PLT, and TLS relocations, particularly in non-allocating sections and against incorrect symbol types. The changes involve updating internal error reporting functions and specific architecture files (elf32-i386.c, elf64-x86-64.c, elfxx-x86.c).
- GOT
- The Global Offset Table (GOT) is a data structure used in position-independent code (PIC) on some architectures, like x86, to indirectly access global memory addresses. It allows code to be loaded at any address without modification.
- PLT
- The Procedure Linkage Table (PLT) is used in conjunction with the GOT for shared libraries. It provides a mechanism for lazy binding of function calls, resolving external function addresses only when they are first invoked.
- TLS
- Thread-Local Storage (TLS) is a mechanism that provides each thread in a multi-threaded program with its own private copy of certain variables.
- Relocation
- A relocation is a directive embedded in an object file that tells the linker how to modify certain memory addresses (e.g., to point to the correct location of a function or variable) when linking the object file with others.
- Non-allocating section
- A section in an executable file that does not occupy memory when the program is run. These sections are typically used for metadata, debugging information, or linker-specific data, and are discarded by the operating system loader.