Skip to content

Commit f3ddb55

Browse files
committed
make slop-scale a linker option instead of build-time flag + update docs
1 parent d694297 commit f3ddb55

File tree

5 files changed

+22
-12
lines changed

5 files changed

+22
-12
lines changed

lld/MachO/CMakeLists.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
2-
option(LLD_MACHO_SLOP_FACTOR
3-
"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)
4-
add_definitions("-DLLD_MACHO_SLOP_FACTOR=${LLD_MACHO_SLOP_FACTOR}")
5-
61
set(LLVM_TARGET_DEFINITIONS Options.td)
72
tablegen(LLVM Options.inc -gen-opt-parser-defs)
83
add_public_tablegen_target(MachOOptionsTableGen)

lld/MachO/ConcatOutputSection.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -306,12 +306,7 @@ void TextOutputSection::finalize() {
306306
// contains several branch instructions in succession, then the distance
307307
// from the current position to the position where the thunks are inserted
308308
// grows. So leave room for a bunch of thunks.
309-
#ifdef LLD_MACHO_SLOP_FACTOR
310-
const unsigned kSlopFact = LLD_MACHO_SLOP_FACTOR;
311-
#else
312-
const unsigned kSlopFact = 256;
313-
#endif
314-
unsigned slop = kSlopFact * thunkSize;
309+
unsigned slop = config->slopScale * thunkSize;
315310
while (finalIdx < endIdx) {
316311
uint64_t expectedNewSize =
317312
alignToPowerOf2(addr + size, inputs[finalIdx]->align) +
@@ -389,7 +384,9 @@ void TextOutputSection::finalize() {
389384
// above. If you hit this: For the current algorithm, just bumping up
390385
// slop above and trying again is probably simplest. (See also PR51578
391386
// comment 5).
392-
fatal(Twine(__FUNCTION__) + ": FIXME: thunk range overrun");
387+
fatal(Twine(__FUNCTION__) +
388+
": FIXME: thunk range overrun. Consider increasing the "
389+
"slop-scale with `--slop-scale=<unsigned_int>`.");
393390
}
394391
thunkInfo.isec =
395392
makeSyntheticInputSection(isec->getSegName(), isec->getName());

lld/MachO/Config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ struct Configuration {
224224
bool disableVerify;
225225
bool separateCstringLiteralSections;
226226
bool tailMergeStrings;
227+
unsigned slopScale = 256;
227228

228229
bool callGraphProfileSort = false;
229230
llvm::StringRef printSymbolOrder;

lld/MachO/Driver.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1995,6 +1995,15 @@ bool link(ArrayRef<const char *> argsArr, llvm::raw_ostream &stdoutOS,
19951995
OPT_no_separate_cstring_literal_sections, false);
19961996
config->tailMergeStrings =
19971997
args.hasFlag(OPT_tail_merge_strings, OPT_no_tail_merge_strings, false);
1998+
if (auto *arg = args.getLastArg(OPT_slop_scale_eq)) {
1999+
StringRef v(arg->getValue());
2000+
unsigned slop = 0;
2001+
if (!llvm::to_integer(v, slop, 0))
2002+
error(arg->getSpelling() +
2003+
": expected a non-negative integer, but got '" + arg->getValue() +
2004+
"'");
2005+
config->slopScale = slop;
2006+
}
19982007

19992008
auto IncompatWithCGSort = [&](StringRef firstArgStr) {
20002009
// Throw an error only if --call-graph-profile-sort is explicitly specified

lld/MachO/Options.td

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,6 +1095,14 @@ defm tail_merge_strings
10951095
: BB<"tail-merge-strings", "Enable string tail merging",
10961096
"Disable string tail merging to improve link-time performance">,
10971097
Group<grp_rare>;
1098+
def slop_scale_eq
1099+
: Joined<["--"], "slop_scale=">,
1100+
MetaVarName<"<unsigned_int>">,
1101+
HelpText<"Specify the slop scale. Default value is 256. If your binary "
1102+
"has too many consec branch instructions resulting in "
1103+
"thunk-range overrun, then you need to increase this value to a "
1104+
"higher value, such as 512 or 1024, etc">,
1105+
Group<grp_rare>;
10981106

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

0 commit comments

Comments
 (0)