If none of the input files are ELF object files (for example, when
generating an object file from a single binary input file via
"-b binary"), use a fallback value for the ELF header flags instead
of crashing with an assertion failure.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
This is needed to link kernel modules for firmware blobs used in a FreeBSD/riscv64 kernel.
lld/ELF/Arch/RISCV.cpp | ||
---|---|---|
123 | The BFD linker is a bit more forgiving in these flag checks to seemingly cater to mixing objects linked with '-b binary' with other objects. Specifically, it only checks for flag mismatches when an object file contains text sections (since the float ABI and RVE only matter for instructions). In FreeBSD's case the kernel is soft-float and doesn't use RVE, so a flags value of 0 for the '-b binary' case is already compatible. |
lld/ELF/Arch/RISCV.cpp | ||
---|---|---|
123 | It's worth noting that, just because an object file only has data, doesn't mean it's ABI-independent. For example, a jmp_buf will change size based on the floating-point ABI. Having said that, that is a rare case, and the flags are never intended to stop every way of screwing things up, but as a safety net to spot obviously-wrong things, so I think it's ok to have that accepted. |
lld/ELF/Arch/RISCV.cpp | ||
---|---|---|
111–114 | For reasonable change that applies to other targets as well, we should try making them generic. |
lld/ELF/Arch/RISCV.cpp | ||
---|---|---|
111–114 | There are only 6 architectures that override calcEFlags to be non-zero: AMDGPU: Also has the same assert calcEFlags is already very target-specific and inconsistent, so I don't know how you intend to make this generic? |
lld/ELF/Arch/RISCV.cpp | ||
---|---|---|
111–114 | I think defaulting to 0 is fine, as that is the best that we could do if no object files are given. A short comment explaining that objectFiles is empty if for example the only file given to the linker is -b <somefile> and we don't want to crash but instead create an output would help readers of the code, though. |
lld/test/ELF/riscv-binary.s | ||
---|---|---|
1 ↗ | (On Diff #232476) | This test touches logic in RISCV::calcEFlags(), i.e. it is RISC-V specific, so I am fine with # REQUIRES: riscv But I wonder if we want to have something more generic as a rest name rather than riscv-binary.s? |
lld/ELF/Arch/RISCV.cpp | ||
---|---|---|
111–114 | I agree with others on this review that defaulting to 0 seems safe here, but I feel the rationale and reasoning needs to be captured:
|
lld/ELF/Arch/RISCV.cpp | ||
---|---|---|
111–114 | Minor correction: mips new-ish behavior is to derive eflags from emulation string if the input list is empty, which was introduced initially to fix FreeBSD kmod builds on mips n32, since ABI is described here and lld refuses to link later due to ABI mismatch otherwise. |
- Add a comment and expand the description in the commit log.
- Rename test from riscv-binary.s to riscv-elf-flags.s
For reasonable change that applies to other targets as well, we should try making them generic.