gas: Avoid section symbols as group signatures
Fixes gas to not reuse section symbols as COMDAT group signatures, preventing invalid object files.
This patch addresses an issue in the GNU Assembler (gas) where it incorrectly reuses unnamed STT_SECTION symbols as COMDAT group signatures. This behavior results in invalid object files, particularly when the signature matches the section name. The fix ensures that gas rejects section symbols for signature matching and creates a distinct named symbol instead. The problem was discovered during an LLVM toolchain port to OpenBSD/sparc64.
- proposer
Submits a patch to prevent gas from using section symbols as COMDAT group signatures, explaining that this leads to invalid object files and the need for distinct named symbols.
“When a COMDAT group signature matches its section name, symbol_find_exact finds the existing section symbol. GAS then reuses this unnamed STT_SECTION symbol as the group signature, although the signature requires a distinct named symbol. Reject section symbols when selecting an existing signature; GAS then creates the usual named local STT_NOTYPE symbol.”
- proposer
Provides context on the issue, noting its discovery during an LLVM toolchain port and upstream attempts to address it, including an LLD workaround that was rejected. The issue was also observed when building GCC on OpenBSD/sparc64.
“This issue was discovered during the OpenBSD/sparc64 LLVM toolchain port and the attempt to upstream its LLVM changes: https://github.com/llvm/llvm-project/pull/207609 An LLD workaround for these objects was rejected upstream: https://github.com/llvm/llvm-project/pull/209841”
Technical Tradeoffs
- Ensures correct object file generation by disallowing section symbols as group signatures.
- Improves compliance with ELF specifications regarding COMDAT groups.
In Details
This patch modifies the gas assembler's ELF object file emission logic. Specifically, it corrects how COMDAT group signatures are handled. When a COMDAT group's signature symbol matches an existing section symbol (e.g., .text for a .text section), symbol_find_exact would find the section symbol. The assembler then incorrectly re-uses this unnamed section symbol as the group signature, violating the requirement for a distinct, named symbol. The fix ensures that such section symbols are rejected, and a proper named symbol is created.
- gas
- The GNU Assembler, a component of the GNU Binutils suite that translates assembly language code into machine code.
- COMDAT group
- A grouping mechanism in object files for selecting a single version of a group of related symbols or sections among potential duplicates. Often used for function or data definitions that might appear in multiple object files.
- signature
- In the context of COMDAT groups, a unique identifier that determines which group 'wins' when multiple object files define the same group.
- STT_SECTION symbol
- A symbol table entry of type STT_SECTION, which refers to a specific section in the object file. These are typically unnamed.
- STT_NOTYPE symbol
- A symbol table entry of type STT_NOTYPE, which indicates that the symbol has no defined type. These can be local or global.
- ELF
- Executable and Linkable Format, a common standard file format for object files, executables, and shared libraries on many Unix-like systems.