Index: lld/MachO/Arch/ARM64.cpp =================================================================== --- lld/MachO/Arch/ARM64.cpp +++ lld/MachO/Arch/ARM64.cpp @@ -134,7 +134,7 @@ stubSize = sizeof(stubCode); thunkSize = sizeof(thunkCode); - branchRange = maxIntN(28) - thunkSize; + branchRange = 128 * 1024 * 1024; stubHelperHeaderSize = sizeof(stubHelperHeaderCode); stubHelperEntrySize = sizeof(stubHelperEntryCode); } Index: lld/MachO/ConcatOutputSection.cpp =================================================================== --- lld/MachO/ConcatOutputSection.cpp +++ lld/MachO/ConcatOutputSection.cpp @@ -225,8 +225,8 @@ assert(isec->isFinal); uint64_t isecVA = isec->getVA(); // Assign addresses up-to the forward branch-range limit - while (finalIdx < endIdx && - isecAddr + inputs[finalIdx]->getSize() < isecVA + branchRange) + while (finalIdx < endIdx && isecAddr + inputs[finalIdx]->getSize() < + isecVA + branchRange - thunkSize) finalizeOne(inputs[finalIdx++]); if (isec->callSiteCount == 0) continue; @@ -255,7 +255,7 @@ // Calculate branch reachability boundaries uint64_t callVA = isecVA + r.offset; uint64_t lowVA = branchRange < callVA ? callVA - branchRange : 0; - uint64_t highVA = callVA + branchRange; + uint64_t highVA = callVA + branchRange - 4; // Calculate our call referent address auto *funcSym = r.referent.get(); ThunkInfo &thunkInfo = thunkMap[funcSym]; @@ -267,7 +267,7 @@ } uint64_t funcVA = funcSym->resolveBranchVA(); ++thunkInfo.callSitesUsed; - if (lowVA < funcVA && funcVA < highVA) { + if (lowVA <= funcVA && funcVA <= highVA) { // The referent is reachable with a simple call instruction. continue; } @@ -276,7 +276,7 @@ // If an existing thunk is reachable, use it ... if (thunkInfo.sym) { uint64_t thunkVA = thunkInfo.isec->getVA(); - if (lowVA < thunkVA && thunkVA < highVA) { + if (lowVA <= thunkVA && thunkVA <= highVA) { r.referent = thunkInfo.sym; continue; }