Thispatch implements the R_RISCV_ADD32 and R_RISCV_SUB32 relocations for
RISC-V.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Add tests.
Note that the reloc-jt.s test is a real-world use case for label subtraction
on RISC-V (jump tables). However, I haven't found a way to implement this test
without having to hardcode the label difference. I have tried to minimize the
fragility of this test by hardcoding the section addresses but ideas to improve
this test would be appreciated.
bolt/lib/Rewrite/RewriteInstance.cpp | ||
---|---|---|
2989 |
The relevant relocations in the reloc-jt.s test case look like this: Relocation section '.rela.data' at offset 0x2068 contains 2 entries: Offset Info Type Sym. Value Sym. Name + Addend 000000002000 000300000023 R_RISCV_ADD32 000000000000100e .LBB0_1 + 0 000000002000 000200000027 R_RISCV_SUB32 0000000000002000 .LJTI0_0 + 0 .LJTI0_0 is a label in .data so the R_RISCV_SUB32 is a data-to-data relocation.
iiuc, BOLT usually doesn't need to update data-to-data relocs because the .data section is not relocated, correct? In this case, however, the data-to-data reloc gets composed (see D146546) with a data-to-code reloc (R_RISCV_ADD32) so BOLT needs to process it to ensure the linker can properly update the value. The condition here might be a bit coarse-grained, though, as all data-to-data relocs on RISC-V will now be processed even though it might not always be necessary. I suppose this doesn't really matter as the linker will just overwrite data contents with its original value. Or am I missing something here? | |
bolt/test/RISCV/reloc-jt.s | ||
14–15 |
No, they aren't, but this is something that also used to confuse me :) Creating a 32-bit PC-relative address on RISC-V works as follows:
The psABI has a good explanation for why it works this way (an important reason is that the auipc and addi are not necessarily consecutive). |
bolt/lib/Rewrite/RewriteInstance.cpp | ||
---|---|---|
2989 | I see, it makes sense. You're correct in your assessment and it should be harmless. it does increase the chance that BOLT might incorrectly update some value that didn't even need updating in the first place, although that would be a hidden bug in BOLT that would need to be solved anyway. | |
bolt/test/RISCV/reloc-jt.s | ||
14–15 | Thanks for explaining |
Aren't these data-to-code relocs? (BOLT doesn't need to update data-to-data relocs).