Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
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
6 changes: 4 additions & 2 deletions lld/MachO/ConcatOutputSection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ 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;
unsigned slop = config->slopScale * thunkSize;
while (finalIdx < endIdx) {
uint64_t expectedNewSize =
alignToPowerOf2(addr + size, inputs[finalIdx]->align) +
Expand Down Expand Up @@ -384,7 +384,9 @@ void TextOutputSection::finalize() {
// above. If you hit this: For the current algorithm, just bumping up
// slop above and trying again is probably simplest. (See also PR51578
// comment 5).
fatal(Twine(__FUNCTION__) + ": FIXME: thunk range overrun");
fatal(Twine(__FUNCTION__) +
": FIXME: thunk range overrun. Consider increasing the "
"slop-scale with `--slop-scale=<unsigned_int>`.");
}
thunkInfo.isec =
makeSyntheticInputSection(isec->getSegName(), isec->getName());
Expand Down
1 change: 1 addition & 0 deletions lld/MachO/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ struct Configuration {
bool disableVerify;
bool separateCstringLiteralSections;
bool tailMergeStrings;
unsigned slopScale = 256;

bool callGraphProfileSort = false;
llvm::StringRef printSymbolOrder;
Expand Down
9 changes: 9 additions & 0 deletions lld/MachO/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1995,6 +1995,15 @@ bool link(ArrayRef<const char *> argsArr, llvm::raw_ostream &stdoutOS,
OPT_no_separate_cstring_literal_sections, false);
config->tailMergeStrings =
args.hasFlag(OPT_tail_merge_strings, OPT_no_tail_merge_strings, false);
if (auto *arg = args.getLastArg(OPT_slop_scale_eq)) {
StringRef v(arg->getValue());
unsigned slop = 0;
if (!llvm::to_integer(v, slop, 0))
error(arg->getSpelling() +
": expected a non-negative integer, but got '" + arg->getValue() +
"'");
config->slopScale = slop;
}

auto IncompatWithCGSort = [&](StringRef firstArgStr) {
// Throw an error only if --call-graph-profile-sort is explicitly specified
Expand Down
8 changes: 8 additions & 0 deletions lld/MachO/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -1095,6 +1095,14 @@ defm tail_merge_strings
: BB<"tail-merge-strings", "Enable string tail merging",
"Disable string tail merging to improve link-time performance">,
Group<grp_rare>;
def slop_scale_eq
: Joined<["--"], "slop_scale=">,
MetaVarName<"<unsigned_int>">,
HelpText<"Specify the slop scale. Default value is 256. If your binary "
"has too many consec branch instructions resulting in "
"thunk-range overrun, then you need to increase this value to a "
"higher value, such as 512 or 1024, etc">,
Group<grp_rare>;

def grp_deprecated : OptionGroup<"deprecated">, HelpText<"DEPRECATED">;

Expand Down