This is an archive of the discontinued LLVM Phabricator instance.

[ELF][ARM] Add getPCBias()
ClosedPublic

Authored by MaskRay on Nov 25 2019, 11:30 AM.

Details

Summary

ThunkCreator::getThunk and ThunkCreator::normalizeExistingThunk
currently assume that the implicit addends are -8 for ARM and -4 for
Thumb. In D70637, ThunkCreator::getThunk will need to take care of the
relocation addend explicitly.

Add the utility function getPCBias() as a prerequisite so that the getThunk change in D70637
can be more general.

Diff Detail

Event Timeline

MaskRay created this revision.Nov 25 2019, 11:30 AM
grimar added inline comments.Nov 26 2019, 12:31 AM
lld/ELF/Arch/ARM.cpp
391 ↗(On Diff #230952)

nit: I guess using if might be a bit nicer and shorter here.

Is there any reason not to have just one function inBranchRange() and assume that it needs to take care of the relocation addend explicitly, that way the PC Bias could be limited to the ARM implementation of inBranchRange() and inBranchRangeBeforePCBias wouldn't be needed?

The only other call sites that I could find that would need to be adjusted are:
In Relocations.cpp the relocation addend could be passed to getISDThunkSec (line 1634) so that it can be passed through to the two calls to target->inBranchRange() in there.
In ARMErrataFix.cpp we are generating the branch instruction (it is always Thumb and its addend is hard-coded to -4) so we could easily account for this at the call site.
needsThunk() would either need the addend to pass through to inBranchRange(). In D70637 you are passing in the addend, in this patch it might be simple enough to say if Arm Relocation pass in -8, if thumb pass in -4.

It maybe that across this patch and D70637 we can convert all the callsites so that there is just inBranchRange() which expects the relocation addend to have been accounted for in dst.

Is there any reason not to have just one function inBranchRange() and assume that it needs to take care of the relocation addend explicitly, that way the PC Bias could be limited to the ARM implementation of inBranchRange() and inBranchRangeBeforePCBias wouldn't be needed?

If we require that the call sites of inBranchRange() account for both the addend and the PC Bias (e.g. target->inBranchRange(rel.type, src, t->getThunkTargetSym()->getVA(rel.addend) + getPCBias(rel.type))), I find that we just need to adjust ThunkCreator::getThunk and ThunkCreator::normalizeExistingThunk.

The only other call sites that I could find that would need to be adjusted are:
In Relocations.cpp the relocation addend could be passed to getISDThunkSec (line 1634) so that it can be passed through to the two calls to target->inBranchRange() in there.
In ARMErrataFix.cpp we are generating the branch instruction (it is always Thumb and its addend is hard-coded to -4) so we could easily account for this at the call site.
needsThunk() would either need the addend to pass through to inBranchRange(). In D70637 you are passing in the addend, in this patch it might be simple enough to say if Arm Relocation pass in -8, if thumb pass in -4.

The two places will not be needed to be adjusted.

It maybe that across this patch and D70637 we can convert all the callsites so that there is just inBranchRange() which expects the relocation addend to have been accounted for in dst.

MaskRay updated this revision to Diff 231097.Nov 26 2019, 10:15 AM
MaskRay retitled this revision from [ELF][ARM] Add ARM::isBranchRangeBeforePCBias to remove assumption on implicit addends being -8 (ARM) or -4 (Thumb) to [ELF][ARM] Add getPCBias().
MaskRay edited the summary of this revision. (Show Details)

TargetInfo::inBranchRangeBeforePCBias -> getPCBias()

MaskRay updated this revision to Diff 231100.Nov 26 2019, 10:21 AM

Change the parameter type of type to RelType

Harbormaster completed remote builds in B41505: Diff 231100.
MaskRay edited the summary of this revision. (Show Details)Nov 26 2019, 10:22 AM
peter.smith accepted this revision.Nov 27 2019, 6:37 AM

LGTM. I think this looks a lot cleaner thanks. I also agree that the getISDThunk call sites don't need modifying as at this point the Thunk is our destination and we don't want an addend from the thunk symbol.

This revision is now accepted and ready to land.Nov 27 2019, 6:37 AM
This revision was automatically updated to reflect the committed changes.