[llvm-dev] Need help implementing relocations

Tim Northover via llvm-dev llvm-dev at lists.llvm.org
Sun Mar 31 00:51:14 PDT 2019


Hi Josh,

On Sat, 30 Mar 2019 at 22:21, Josh Sharp <mm92126 at hotmail.com> wrote:
> In function relocateone() in lld/ELF/Arch/XXX.cpp, I need to compute the difference between the PC and the 'Val' function argument so that I can increment the PC by that difference. Is there a relationship between the PC and 'Loc'? Thanks.

There isn't any relationship between those because Loc is a pointer
into lld's address space (your job in relocateOne is to modify what's
there). Arranging for all sections to be in lld at their final
destination location would be impossible in general and needlessly
complicated even when possible.

This kind of calculation looks like it's handled by getRelocTargetVA
in InputSection.cpp, which your target tells what to do by overriding
getRelExpr in its XXX.cpp. There's a pretty good chance this
relocation just needs to return R_PC, but you should cross-check that
actually is the calculation you want.

Cheers.

Tim.


More information about the llvm-dev mailing list