[PATCH] D72046: [ELF][RISCV] Resolve undefined weak R_PC relocations to p+a
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 31 18:38:19 PST 2019
MaskRay added a comment.
In D72046#1800264 <https://reviews.llvm.org/D72046#1800264>, @jrtc27 wrote:
> For calls, whilst it differs from BFD, it can work just fine as it’s what AArch64 does.
> For data references, however, this is highly inappropriate. They *need* to resolve to 0 as *real world code* relies on that, and it’s what happens on every architecture out there. Code generated by both GCC and LLVM uses PC-relative relocations to refer to external weak symbols. We can argue all we like about whether that’s good or not, but at the end of the day *that is what happens* and we need to not break that.
No. GCC/clang emit either absolute or GOT-generating relocations (R_RISCV_HI20+R_RISCV_LO12_I; R_RISCV_GOT_HI20+R_RISCV_PCREL_LO12_I). Such relocations to weak undefined symbols can be relied on by real world code. The linker only has to resolve absolute relocations to 0 and fill GOT entries with 0.
PC-relative relocations to undefined weak symbols should not be emitted by compilers. Such hand-written assembly is just broken.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D72046/new/
https://reviews.llvm.org/D72046
More information about the llvm-commits
mailing list