[lld] [lld-macho]Define a macro to allow specifying the slop size at build time. (PR #164295)
    Vy Nguyen via llvm-commits 
    llvm-commits at lists.llvm.org
       
    Mon Oct 20 11:19:43 PDT 2025
    
    
  
https://github.com/oontvoo created https://github.com/llvm/llvm-project/pull/164295
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.
>From d6942973ad81b04e47f88d57c9d3fc96fb949b75 Mon Sep 17 00:00:00 2001
From: Vy Nguyen <vyng at google.com>
Date: Mon, 20 Oct 2025 14:17:17 -0400
Subject: [PATCH] [lld-macho]Define a macro to allow specifying the slop size
 at build time.
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.
---
 lld/MachO/CMakeLists.txt          | 5 +++++
 lld/MachO/ConcatOutputSection.cpp | 7 ++++++-
 2 files changed, 11 insertions(+), 1 deletion(-)
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) +
    
    
More information about the llvm-commits
mailing list