Skip to content

Commit aa10603

Browse files
authored
Work around LLVM JITLink stack overflow issue. (#58579)
The JITLinker recurses for every symbol in the list so limit the size of the list This is kind of ugly. Also 1000 might be too large, we don't want to go too small because that wastes memory and 1000 was fine locally for the things I tested. Fixes #58229
1 parent d88369d commit aa10603

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/jitlayers.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -723,8 +723,17 @@ static void jl_compile_codeinst_now(jl_code_instance_t *codeinst)
723723
if (!decls.specFunctionObject.empty())
724724
NewDefs.push_back(decls.specFunctionObject);
725725
}
726-
auto Addrs = jl_ExecutionEngine->findSymbols(NewDefs);
727-
726+
// Split batches to avoid stack overflow in the JIT linker.
727+
// FIXME: Patch ORCJITs InPlaceTaskDispatcher to not recurse on task dispatches but
728+
// push the tasks to a queue to be drained later. This avoids the stackoverflow caused by recursion
729+
// in the linker when compiling a large number of functions at once.
730+
SmallVector<uint64_t, 0> Addrs;
731+
for (size_t i = 0; i < NewDefs.size(); i += 1000) {
732+
auto end = std::min(i + 1000, NewDefs.size());
733+
SmallVector<StringRef> batch(NewDefs.begin() + i, NewDefs.begin() + end);
734+
auto AddrsBatch = jl_ExecutionEngine->findSymbols(batch);
735+
Addrs.append(AddrsBatch);
736+
}
728737
size_t nextaddr = 0;
729738
for (auto &this_code : linkready) {
730739
auto it = invokenames.find(this_code);

test/cmdlineargs.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,3 +1340,6 @@ end
13401340
end
13411341
end
13421342
end
1343+
1344+
# https://github.com/JuliaLang/julia/issues/58229 Recursion in jitlinking with inline=no
1345+
@test success(`$(Base.julia_cmd()) --inline=no -e 'Base.compilecache(Base.identify_package("Pkg"))'`)

0 commit comments

Comments
 (0)