Adds new option to GAS for controlling local symbol conversion to section symbols in relocations
A new `gas` option, `--reloc-section-sym`, controls how local symbols are converted to section symbols in relocations for ELF files, offering `all`, `internal`…
Fangrui Song proposes a new command-line option, --reloc-section-sym, for the GNU Assembler (GAS) when building ELF files. This option provides fine-grained control over how GAS transforms local symbols into section symbols within relocation entries during assembly. Historically, GAS converts eligible local symbols to section symbols, potentially reducing the size of the symbol table. The new option offers three modes: all (the current default behavior), internal (only converting compiler-generated symbols), and none (disabling this conversion entirely), which is useful for debugging and tools that rely on preserved symbol names.
- proposer
Proposes a new `gas` option, `--reloc-section-sym`, to control the conversion of local symbols to section symbols in ELF relocations, addressing PR gas/33885.
“Add --reloc-section-sym to control this conversion: - all (default): convert all eligible local symbols - internal: only convert compiler-generated locals (.L prefix) - none: never convert; keep all symbols as-is in relocations”
- reviewer
Acknowledges the patch, contingent on comprehensive testing across diverse targets to ensure expected behavior.
“Okay, provided you checked the new tests pass for a wide range of targets. In particular ...”
Technical Tradeoffs
- Smaller symbol tables and object file sizes versus maintaining full symbol information for debugging and analysis tools.
- Default behavior (all conversion) potentially obscuring local symbols versus an explicit choice by developers (internal/none).
In Details
This proposal enhances the GNU Assembler (gas)'s ELF backend behavior regarding relocation symbol generation. Specifically, it addresses the optimization where gas may convert local STT_NOTYPE or STT_OBJECT symbols referenced by relocations to STT_SECTION symbols, folding the original symbol's offset into the relocation's addend. This reduces the number of entries in the .symtab section. The new reloc-section-sym option provides control over this optimization, allowing 'all' (default), 'internal' (only for compiler-generated .L prefixed symbols), or 'none'. This impacts the de…
For Context
When a computer program is written, it's first translated into assembly code, and then an assembler (like gas in GNU Binutils) turns that assembly into an 'object file'—a kind of intermediate program file. These object files contain 'symbols' (names for functions, variables) and 'relocations' (instructions for the linker to fix up addresses later). One optimization gas does is to sometimes represent local symbols (symbols only known within a single part of the program) as 'section symbols' in the relocations. This can make the symbol table smaller. This proposal adds a new option to gas that gives developers more control over this optimization. They can choose to apply it to all eligible symbols, only to symbols generated by the compiler (which often have special names starting with .L), or not at all. This is important because while the optimization can make files smaller, sometimes debugging tools or other analysis tools need the original, more detailed symbol information to…