This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Fix edge condition in thunk offset calculation
ClosedPublic

Authored by smeenai on Sep 20 2017, 5:16 PM.

Details

Summary

For ARM thunks, the movt half of the relocation was using an incorrect
offset (it was off by 4 bytes). The original intent seems to have been
for the offset to have been relative to the current instruction, in
which case the difference of 4 makes sense. As the code stands, however,
the offset is always calculated relative to the start of the thunk
(P), and so the movw and movt halves should use the same offset.
This requires a very particular offset between the thunk and its target
to be triggered, and it results in the movt half of the relocation
being off-by-one.

The tests here use ARM-Thumb interworking thunks, since those are the
only ARM thunks currently implemented. I actually encountered this with
a range extension thunk (having Peter's patches cherry-picked locally),
but the underlying issue is identical.

Diff Detail

Repository
rL LLVM

Event Timeline

smeenai created this revision.Sep 20 2017, 5:16 PM
smeenai updated this revision to Diff 116132.Sep 20 2017, 6:28 PM

Fold inputs into test case

smeenai updated this revision to Diff 116136.Sep 20 2017, 7:25 PM

Correct comment

Thanks for spotting that, and my apologies for the mistake, I agree the offset needs to be from the add ip, ip, pc, and shouldn't vary between the movw and movt that construct the offset. Looks good to me, but will be worth waiting to see if Rui or Rafael have any comments.

Gah, I added the wrong account as a reviewer. Thanks for taking a look though, @peter.smith!

I'm gonna go ahead and commit this, since it's quite small and self-contained, and since Peter wrote the original code and is okay with the change. I can address any post-commit comments in a follow-up.

This revision was automatically updated to reflect the committed changes.

Gah, I added the wrong account as a reviewer. Thanks for taking a look though, @peter.smith!

No problem, they are both my accounts, I'm assigned to Linaro so all my OSS work needs to go through the Linaro account.