Currently we treat SHT_RISCV_ATTRIBUTES like a normal section and
concatenate all such input sections, yielding invalid output unless only
a single attributes section is present in the input. Instead, pick the
first as with SHT_ARM_ATTRIBUTES. We do not currently need to condition
our behaviour on the contents, unlike Arm. In future, we should both do
stricter validation of the input and merge all sections together to
ensure we have, for example, the full arch string requirement, but this
rudimentary implementation is good enough for most common cases.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
lld/ELF/InputFiles.cpp | ||
---|---|---|
871 | NB: There is no default case for the switch statement so hoisting these out (required since SHT_ARM_ATTRIBUTES and SHT_RISCV_ATTRIBUTES use the same encoding in the arch-specific range) and thus losing the ability to break to the end of the switch shouldn't be a change of behaviour. |
lld/ELF/InputFiles.cpp | ||
---|---|---|
869 | Keeping the switch may be fine. case SHT_ARM_ATTRIBUTES: assert(SHT_ARM_ATTRIBUTES == SHT_RISCV_ATTRIBUTES); if (EM_ARM) { } else if (EM_RISCV) { } else break; Adding assert(SHT_ARM_ATTRIBUTES == SHT_RISCV_ATTRIBUTES); should be sufficiently clear. | |
lld/test/ELF/riscv-attributes.s | ||
5 | Does llvm-readelf --arch-specific work? |
Use llvm-readelf rather than llvm-readobj
They both have the same format for BuildAttributes, but llvm-readelf only emits
that whereas llvm-readobj emits additional information about the file we don't
care about.
lld/ELF/InputFiles.cpp | ||
---|---|---|
869 | I considered that but it just feels too dirty... and what happens if another architecture allocates LOPROC+3 to a different kind of section? Then you have completely unrelated code under SHT_ARM_ATTRIBUTES. |
LGTM.
lld/ELF/InputFiles.cpp | ||
---|---|---|
869 |
This is probably unlikely. The logic is a bit complex now. So moving it outside can reduce indentation, which seems fine. |
Keeping the switch may be fine.
Adding assert(SHT_ARM_ATTRIBUTES == SHT_RISCV_ATTRIBUTES); should be sufficiently clear.