[lld] [lld-macho]Define a macro to allow specifying the slop size at build time. (PR #164295)

via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 20 11:20:19 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lld

Author: Vy Nguyen (oontvoo)

<details>
<summary>Changes</summary>



We're seeing thunk size overrun in our large builds and it would be helpful to be able to increase the slop size. However, this should probably not be changed between different runs of LLD, hence making it a build option so that it's fixed per lld binary.

---
Full diff: https://github.com/llvm/llvm-project/pull/164295.diff


2 Files Affected:

- (modified) lld/MachO/CMakeLists.txt (+5) 
- (modified) lld/MachO/ConcatOutputSection.cpp (+6-1) 


``````````diff
diff --git a/lld/MachO/CMakeLists.txt b/lld/MachO/CMakeLists.txt
index 3cd94ced75cc0..5ad12eb04f4c3 100644
--- a/lld/MachO/CMakeLists.txt
+++ b/lld/MachO/CMakeLists.txt
@@ -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)
+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)
diff --git a/lld/MachO/ConcatOutputSection.cpp b/lld/MachO/ConcatOutputSection.cpp
index 8067d23fa6faf..7a3476a145f0b 100644
--- a/lld/MachO/ConcatOutputSection.cpp
+++ b/lld/MachO/ConcatOutputSection.cpp
@@ -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) +

``````````

</details>


https://github.com/llvm/llvm-project/pull/164295


More information about the llvm-commits mailing list