Gas/ELF: Warn Upon Non-Default Visibility of Local Symbols
The patch proposes a warning when local symbols have non-default visibility, which is against ELF spec. The author considers reverting to earlier behavior.
This patch warns when local symbols are declared with non-default visibility (protected/hidden/internal), as the ELF spec forbids mixing STB_LOCAL with those STV_* attributes. The author is now reconsidering whether to instead treat symbols with non-default visibility as global, but hidden. The discussion weighs the risk of introducing unexpected globals against the benefit of adhering to the ELF specification.
- proposer
Proposes a warning for non-default visibility of local symbols in gas/ELF, as the ELF spec doesn't allow STB_LOCAL with STV_PROTECTED/HIDDEN/INTERNAL.
“The spec explicitly precludes STB_LOCAL together with STV_PROTECTED (and, implicity, STV_HIDDEN or STV_INTERNAL), so we better wouldn't entirely silently write out symbols violating this.”
- reviewer
Questions whether the change might cause issues for existing code and suggests treating '.hidden' as making the symbol global, but hidden.
“Do we know that this won't cause issues for real code out in the wild? Might it not be better to just treat .hidden as making the symbol global, but hidden?”
- contributor
States that after reconsideration, implying global from hidden feels riskier and may stick with the current approach.
“Having thought about this more, implying global from hidden (etc) feels more risky than keeping things as they are in v1: People suddenly may face dupli”
Technical Tradeoffs
- Warning on invalid symbol visibility may break existing builds.
- Silently upgrading visibility to global may introduce unexpected symbol collisions.
- Changing visibility semantics might affect linking behavior.
In Details
The GNU Assembler (gas) handles symbol visibility when creating ELF objects. STB_LOCAL symbols should not have STV_HIDDEN, STV_PROTECTED, or STV_INTERNAL visibility. This patch checks and warns on encountering that invalid combination. The concern is whether to silently upgrade such symbols to global scope (but hidden) instead of warning.
For Context
When assembling code, symbols (names for memory locations or functions) are defined with specific attributes. One such attribute is visibility, which dictates where the symbol can be accessed from. In ELF (Executable and Linkable Format), the standard binary format on Linux, symbols can be local (visible only within the object file) or global (visible to other object files). This patch deals with the assembler's behavior when a symbol is marked as both local and having a visibility attribute that implies it should be global. Binutils is the project that hosts the assembler, linker and other binary tools.