lto: Use LDPR_PREVAILING_DEF for common symbols from IR objects
Fixes linker to correctly handle common symbols from LTO objects by using LDPR_PREVAILING_DEF resolution.
This change modifies the linker’s LTO plugin to set the symbol resolution to LDPR_PREVAILING_DEF for common symbols encountered in regular objects when processing an undefined or common symbol from an IR object. This addresses a bug where an incorrect resolution (LDPR_RESOLVED_EXEC) was used, potentially leading to issues when common symbols’ sizes or alignments are overridden. New test cases are added to verify the fix.
In Details
In the context of Link-Time Optimization (LTO) and the linker plugin API, get_symbols in ld/plugin.c is responsible for processing symbols from IR objects. When an undefined or common symbol is encountered in a regular object that originates from an IR object, its resolution needs careful handling. This commit changes the resolution from LDPR_RESOLVED_EXEC to LDPR_PREVAILING_DEF for common symbols, accommodating cases where other common symbols might override their size or alignment, as per PR ld/34570.
- LTO
- Link-Time Optimization. A compilation technique where the linker performs optimizations across multiple object files, often using an intermediate representation (IR) generated by the compiler.
- Common symbol
- A symbol that has been declared but not yet defined. The linker typically allocates space for common symbols, often resolving multiple declarations into a single definition with the largest size.
- IR object
- An object file or representation that contains intermediate code or data, typically used during Link-Time Optimization (LTO) before final machine code generation.
- LDPR_PREVAILING_DEF
- A linker symbol resolution type, indicating that the symbol's definition should be based on the 'prevailing' definition, likely the one with the largest size or most specific attributes among common symbols.
- LDPR_RESOLVED_EXEC
- A linker symbol resolution type, suggesting that the symbol is resolved within the executable's context, possibly implying a static resolution.