This is an archive of the discontinued LLVM Phabricator instance.

[BOLT][AArch64] Handle external references to the middle of Constant Islands
ClosedPublic

Authored by treapster on Aug 22 2022, 7:16 AM.

Details

Summary

Fix BinaryContext::handleAddressRef to properly detect references to other function's Constant islands.

Diff Detail

Event Timeline

treapster created this revision.Aug 22 2022, 7:16 AM
Herald added a reviewer: Amir. · View Herald Transcript
Herald added a reviewer: maksfb. · View Herald Transcript
Herald added a project: Restricted Project. · View Herald Transcript
treapster requested review of this revision.Aug 22 2022, 7:16 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 22 2022, 7:16 AM
treapster updated this revision to Diff 454782.Aug 23 2022, 4:23 AM

Fix test, handle case when IslandIter == AddressToConstantIslandMap.end()

treapster updated this revision to Diff 454783.Aug 23 2022, 4:25 AM

clang-format

rafauler accepted this revision.Aug 23 2022, 2:18 PM

Thanks for fixing this! LGTM

This revision is now accepted and ready to land.Aug 23 2022, 2:18 PM
yota9 requested changes to this revision.Aug 23 2022, 2:45 PM
yota9 added inline comments.
bolt/lib/Core/BinaryContext.cpp
399
399

I assume we need to add extra check that we're still in bounds of the function. E.g. for the case when IslandIter was originally eq to AddressToConstantIslandMap.end() and we've decremented the iterator.

This revision now requires changes to proceed.Aug 23 2022, 2:45 PM
treapster added inline comments.Aug 23 2022, 2:55 PM
bolt/lib/Core/BinaryContext.cpp
399

getOrCreateIslandAccess (which is called by getOrCreateProxyIslandAccess) returns nullptr if !isInConstantIsland(Address))

treapster added inline comments.Aug 23 2022, 3:05 PM
bolt/lib/Core/BinaryContext.cpp
399

It should be IslandIter = std::prev(IslandIter) or std::advance(IslandIter, -1), but i think there's no need to be verbose here. Why not leave it as a decrement?

yota9 added inline comments.Aug 23 2022, 3:09 PM
bolt/lib/Core/BinaryContext.cpp
399

Than it looks like "IslandIter == AddressToConstantIslandMap.begin()" check above is redundant too (it might be rewritten that iterator not equal to begin() before decrement and without else case). Although I don't might to have both your and mine checks for better code flow control, my IMHO that we need either check both edge cases here or none.

treapster added inline comments.Aug 23 2022, 3:35 PM
bolt/lib/Core/BinaryContext.cpp
399

You're probably right, i'll change to

if (IslandIter != AddressToConstantIslandMap.begin())
  --IslandIter;
yota9 added inline comments.Aug 24 2022, 12:37 AM
bolt/lib/Core/BinaryContext.cpp
399

Yes, I meant that. Because of the standard https://en.cppreference.com/w/cpp/iterator/prev checkout Note section.

treapster added inline comments.Aug 24 2022, 12:40 AM
bolt/lib/Core/BinaryContext.cpp
399

I know that, bit IslandIter is not an rvalue

yota9 added inline comments.Aug 24 2022, 12:45 AM
bolt/lib/Core/BinaryContext.cpp
399

You're right, for some reason I was sure that it was telling about operation on the it == end(), not the end() itself.. NMW

treapster updated this revision to Diff 455150.Aug 24 2022, 4:04 AM

Remove redundant checks

yota9 requested changes to this revision.Aug 24 2022, 4:35 AM
yota9 added inline comments.
bolt/lib/Core/BinaryContext.cpp
396

Unneeded parentheses

This revision now requires changes to proceed.Aug 24 2022, 4:35 AM
treapster updated this revision to Diff 455166.Aug 24 2022, 5:05 AM

Remove unneeded braces

treapster marked an inline comment as done.Aug 24 2022, 5:06 AM
yota9 accepted this revision.Aug 24 2022, 9:45 AM

LGTM

This revision is now accepted and ready to land.Aug 24 2022, 9:45 AM