Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lld/MachO/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@

option(LLD_MACHO_SLOP_FACTOR
"Specify the slop factor. For very large build, the default of 256 might be too small, which can cause thunk-range overrun. Recommend increasing this value to 1024 or higher as needed.", 256)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any better documentation we can provide as to what this actually is/does? For example do we know what is causing a thunk-range overrun? Is there some coding patterns that may cause it? This seems like we are just putting a band-aid on what may be a bad coding practice.

Also

"For very large builds" vs "For very large build".

is this something that should maybe be specified as a build flag vs a macro?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any better documentation we can provide as to what this actually is/does? For example do we know what is causing a thunk-range overrun? Is there some coding patterns that may cause it? This seems like we are just putting a band-aid on what may be a bad coding practice.

Ok, how about describing the root cause (ie., too many consec branches)?
As for coding patterns that might cause it, one of them could be not using subsection_via_symbols (or anything that prevent deadstripping), which would create a giant input-section, increasing your chance of hitting this thunk-range overrun error.

Updated the code + docs to reflect that.

add_definitions("-DLLD_MACHO_SLOP_FACTOR=${LLD_MACHO_SLOP_FACTOR}")

set(LLVM_TARGET_DEFINITIONS Options.td)
tablegen(LLVM Options.inc -gen-opt-parser-defs)
add_public_tablegen_target(MachOOptionsTableGen)
Expand Down
7 changes: 6 additions & 1 deletion lld/MachO/ConcatOutputSection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,12 @@ void TextOutputSection::finalize() {
// contains several branch instructions in succession, then the distance
// from the current position to the position where the thunks are inserted
// grows. So leave room for a bunch of thunks.
unsigned slop = 256 * thunkSize;
#ifdef LLD_MACHO_SLOP_FACTOR
const unsigned kSlopFact = LLD_MACHO_SLOP_FACTOR;
#else
const unsigned kSlopFact = 256;
#endif
unsigned slop = kSlopFact * thunkSize;
while (finalIdx < endIdx) {
uint64_t expectedNewSize =
alignToPowerOf2(addr + size, inputs[finalIdx]->align) +
Expand Down
Loading