riscv: Set undefined symbol value to 0 if pointer equality isn't needed
Patch accepted: RISC-V undefined symbols now default to 0 if pointer equality is not required.
This patch modifies the RISC-V ELF backend to set the value of undefined symbols to 0 when pointer equality is not a concern. This resolves a specific build failure for PR29655. The change in riscv_elf_finish_dynamic_symbol improves the linker’s handling of undefined symbols in certain contexts.
- other
Approves the patch and thanks the author.
“LGTM, thanks :)”
- proposer
Submitted a patch to set undefined symbol values to 0 for RISC-V when pointer equality is not needed, fixing PR29655.
“This fixes: FAIL: Build pr29655 * elfnn-riscv.c (riscv_elf_finish_dynamic_symbol): Set undefined symbol value to 0 if pointer equality isn't needed.”
Technical Tradeoffs
- Simplifies symbol resolution in certain RISC-V ELF dynamic linking scenarios by defaulting undefined symbols to 0, potentially improving build stability for specific cases like PR29655, but requires careful consideration if pointer equality is essential.
In Details
This patch adjusts the handling of undefined symbols in the RISC-V ELF linker implementation within binutils. It specifically targets the riscv_elf_finish_dynamic_symbol function. When a symbol is undefined and its value is not critical for pointer equality comparisons (e.g., in cases not related to dynamic linking where addresses must be exact), the symbol's value is now set to 0. This resolves a build issue identified as PR29655.
- undefined symbol
- A symbol (e.g., a variable or function name) that is referenced in one object file but not defined within it. The linker resolves these by finding their definition in another object file or library.
- pointer equality
- In the context of symbol resolution, ensuring that two pointers, even if undefined, are resolved to the same address or value if they represent the same logical entity.
- RISC-V
- An open-source instruction set architecture (ISA) based on RISC principles.
- ELF
- Executable and Linkable Format, a standard file format for object files, executables, and core dumps on Unix-like systems.
- dynamic symbol
- A symbol that is visible and resolved at runtime, typically used in shared libraries and dynamically linked executables.