This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Fix branch range computation when picking ThunkSection
ClosedPublic

Authored by MaskRay on Apr 28 2022, 7:09 PM.

Details

Summary

Similar to D117734. Take AArch64 as an example when the branch range is +-0x8000000.

getISDThunkSec returns ts when src-0x8000000-r_addend <= tsBase < src-0x8000000
and the new thunk will be placed in ts (ts->addThunk(t)). However, the new
thunk (at the end of ts) may be unreachable from src. In the next pass,
normalizeExistingThunk reverts the relocation back to the original target.
Then a new thunk is created and the same ts is picked as before. The ts is
still unreachable.

I have observed it in one test with a sufficiently large r_addend (47664): there
are initially 245 Thunk's, then in each pass 14 new Thunk's are created and get
appended to the unreachable ThunkSection. After 15 passes lld fails with
thunk creation not converged.

The new test aarch64-thunk-reuse2.s checks the case.

Without - pcBias, arm-thumb-thunk-empty-pass.s and arm-thunk-multipass-plt.s
will fail.

Diff Detail

Event Timeline

MaskRay created this revision.Apr 28 2022, 7:09 PM
MaskRay requested review of this revision.Apr 28 2022, 7:09 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 28 2022, 7:09 PM
MaskRay retitled this revision from [ELF] Fix ThunkSection distance computation to [ELF] Fix branch range computation when picking ThunkSection.Apr 28 2022, 7:10 PM
MaskRay updated this revision to Diff 425966.Apr 28 2022, 9:13 PM

add a test

MaskRay edited the summary of this revision. (Show Details)Apr 28 2022, 9:14 PM

I'll push this today to fix some breakage.

peter.smith accepted this revision.May 3 2022, 5:42 AM

Looks good to me.

IIUC the problem case is triggered by relocations with addends. Something like:

  • ThunkSection selected which is in range of the branch, but not branch + offset.
  • Later code identifies the thunk is out of branch range which removes the thunk from the branch
  • Branch chooses the same thunk section as before.
  • Repeat, until error message.
This revision is now accepted and ready to land.May 3 2022, 5:42 AM

Looks good to me.

IIUC the problem case is triggered by relocations with addends. Something like:

  • ThunkSection selected which is in range of the branch, but not branch + offset.
  • Later code identifies the thunk is out of branch range which removes the thunk from the branch
  • Branch chooses the same thunk section as before.
  • Repeat, until error message.

Yes, this. Thanks!

MaskRay edited the summary of this revision. (Show Details)May 3 2022, 8:39 AM