LoongArch: Fix relocation of ignored undefined symbols
Fixes a BFD assertion in LoongArch linking by correctly classifying ignored undefined symbols.
This patch addresses a bug in the LoongArch linker where ignored undefined symbols could lead to a BFD assertion. Previously, ignored undefined symbols were treated as dynamically resolved, causing issues with branch and call relocations. The fix classifies these symbols as constants if they lack dynamic entries, while maintaining dynamic resolution for those with dynamic entries to ensure shared link compatibility.
- proposer
Submits a patch to correct how ignored undefined symbols are handled in LoongArch linking, preventing BFD assertions.
“For LoongArch, an ignored undefined symbol that fails to resolve locally is treated as dynamically resolved. Enable --unresolved-symbols=ignore-all Branch and call relocations of ignored undefined symbol could request a non-exist PLT entry thus trigger a BFD assertion.”
In Details
This patch modifies bfd/elfnn-loongarch.c and adds test cases to ld/testsuite/ld-loongarch-elf/. It addresses a specific issue where the LoongArch ELF linker, when encountering undefined symbols marked with RM_IGNORE and not having a dynamic symbol entry, would incorrectly attempt to resolve them dynamically. This leads to a BFD assertion when processing call-related relocations that expect a PLT entry. The change reclassifies these symbols to avoid the assertion.
- LoongArch
- A family of instruction set architectures developed in China.
- relocation
- A process performed by the linker to adjust symbolic addresses in machine code after it has been assembled, typically to account for the final memory locations of code and data.
- undefined symbol
- A symbol that is referenced in object code but not defined within any of the object files being linked. The linker typically resolves these by finding their definition in other object files or libraries.
- BFD
- Binary File Descriptor library, a library used by GNU Binutils to support various object file formats.
- PLT
- Procedure Linkage Table, a table used in dynamically linked executables to resolve addresses of functions at runtime.