This is an archive of the discontinued LLVM Phabricator instance.

[lld-macho] Increase slops to prevent thunk out of range
ClosedPublic

Authored by thevinster on Jan 5 2022, 3:05 PM.

Details

Reviewers
thakis
Group Reviewers
Restricted Project
Commits
rGa963bc490d68: [lld-macho] Increase slops to prevent thunk out of range
Summary

One of our internal arm64 apps hit a thunk out of range error when building
with LLD. Per the comment, I'm arbitrarily increasing slop size to 256.

Diff Detail

Event Timeline

thevinster created this revision.Jan 5 2022, 3:05 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 5 2022, 3:05 PM
Herald added a reviewer: Restricted Project. · View Herald Transcript
thevinster edited the summary of this revision. (Show Details)Jan 5 2022, 3:07 PM
thevinster published this revision for review.Jan 5 2022, 3:08 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 5 2022, 3:08 PM
oontvoo added a subscriber: oontvoo.Jan 5 2022, 5:36 PM
oontvoo added inline comments.
lld/MachO/ConcatOutputSection.cpp
247

Where is this number from?
(would have asked the same question for '100').

Is this just kicking the can down the road?

smeenai added a subscriber: smeenai.Jan 5 2022, 6:01 PM
smeenai added inline comments.
lld/MachO/ConcatOutputSection.cpp
247

Also can we make it a power of two? :p

thevinster added inline comments.
lld/MachO/ConcatOutputSection.cpp
247

200 is 2 * 100. The 2x multiplier is arbitrary as stated in the summary. To address the question of why it was 100, my guess is that it needed to be a number sufficiently large enough to handle multiple branch instructions in succession. PR51578 has a better explanation of the history of this change.

Is this just kicking the can down the road?

My interpretation of PR51578 is that this increasing slop sizes is the solution to this problem. The actual solution is a larger fix and overly complicates things when "leaving more room for thunks will fix this in practice and should be good enough." cc: @thakis who came up with this approach.

247

I don't see why not. Did you have a number in mind? The closest power of two to 200 seems to be 256. I'm also happy to bump this number even higher if people feel like it should be higher. D108930 says "bumping it to 1000 would probably be fine."

int3 added a subscriber: int3.Jan 6 2022, 6:22 AM

Maybe make it configurable too?

thakis accepted this revision.Jan 6 2022, 6:49 AM

For "why 100": My repro worked with 10, so I figured if I put in ten times that nobody should ever hit this again. Looks like that didn't work out 😓

This looks fine. 256 is fine too. It means we insert thunks we don't need slightly more often, but still only very rarely.

This revision is now accepted and ready to land.Jan 6 2022, 6:49 AM
oontvoo added inline comments.Jan 6 2022, 10:47 AM
lld/MachO/ConcatOutputSection.cpp
247

makes sense! thanks for the details!

thevinster marked 2 inline comments as done.Jan 6 2022, 11:51 AM

Maybe make it configurable too?

I lean towards not making it configurable because it's not meant to be adjusted frequently (or even adjusted at all by the user). I'm hoping 256 (which seems to be the consensus) is enough to handle virtually everything now.

thevinster edited the summary of this revision. (Show Details)

Increase to 256

thevinster edited the summary of this revision. (Show Details)Jan 6 2022, 11:57 AM

FWIW, we've had this happen recently on non-optimized builds of Firefox with the 256 value (although it's not happening anymore as of writing, whatever made it disappear)... is there a point where increasing the slop is going to be a problem?

Herald added a project: Restricted Project. · View Herald TranscriptNov 15 2022, 8:27 PM
int3 added a comment.Nov 16 2022, 6:09 PM

is there a point where increasing the slop is going to be a problem?

Not really, it just makes things slightly less efficient size-wise. We should deal with this more cleanly though by making the slop a dynamically-adjusted parameter (i.e. if it isn't enough, LLD should just bump it up and retry w/o user intervention)