riscv: Ignore attributes in empty input file
Patch accepted: RISC-V assembler now ignores attributes in empty input files.
This patch addresses an issue in the RISC-V assembler where attributes in empty or .note.gnu.build-id sections were not being ignored during merging. The change modifies _bfd_riscv_elf_merge_private_bfd_data to correctly handle these cases, passing several linker test cases that previously failed. The patch has been accepted.
- other
Approves the patch and thanks the author.
“LGTM, thanks :)”
- proposer
Submitted a patch to ignore attributes in empty input files and .note.gnu.build-id sections for RISC-V, resolving linker test failures.
“Ignore empty and .note.gnu.build-id sections when merging attributes. The following linker tests now pass for riscv: FAIL: Diagnostics - Wrong magic number mixed with valid CTF sections FAIL: --gc-sections with --defsym FAIL: --gc-sections with KEEP FAIL: --gc-sections with __start_SECTIONNAME FAIL: ld-plugin/lto-10r FAIL: ld-plugin/lto-3r FAIL: ld-plugin/lto-4r-a FAIL: ld-plugin/lto-4r-b FAIL:…”
Technical Tradeoffs
- Improves the robustness of the RISC-V linker by correctly handling edge cases with empty files and specific sections, at the cost of minor complexity in attribute merging logic.
In Details
This patch modifies the BFD library's RISC-V ELF backend (elfnn-riscv.c) to correctly handle attribute merging. It ensures that attributes found in empty input files or sections like .note.gnu.build-id are ignored, preventing issues with linker operations such as garbage collection (--gc-sections) and symbol definition. This resolves several previously failing linker test cases.
- BFD
- Binary File Descriptor library, used by GNU Binutils and GDB to provide a common interface to various object file formats.
- 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.
- attributes
- Metadata embedded within object files that can provide information about symbols, sections, or the file itself, used by linkers and other tools.
- --gc-sections
- A linker option that removes unused sections from the output file, reducing its size.
- .note.gnu.build-id
- An ELF section used to store a unique identifier for the build of an executable or library, often used for debugging and crash report correlation.