Skip to content

Commit

Permalink
[lli] Add a filter to avoid importing the process's main symbol.
Browse files Browse the repository at this point in the history
If JIT'd code fails to define a main function and we import the process's
definition then we will end up recursively calling lli's main until we overflow
the stack and crash. This filter fixes the issue by ensuring that the process's
main function is never imported. This results in lli producing a much friendlier
"symbol not found" error when JIT'd code fails to define main.
  • Loading branch information
lhames committed Jan 3, 2020
1 parent 3e5eac0 commit 3559831
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions llvm/tools/lli/lli.cpp
Expand Up @@ -792,11 +792,15 @@ int runOrcLazyJIT(const char *ProgName) {
});
return TSM;
});

orc::MangleAndInterner Mangle(J->getExecutionSession(), J->getDataLayout());
J->getMainJITDylib().addGenerator(
ExitOnErr(orc::DynamicLibrarySearchGenerator::GetForCurrentProcess(
J->getDataLayout().getGlobalPrefix())));
J->getDataLayout().getGlobalPrefix(),
[MainName = Mangle("main")](const orc::SymbolStringPtr &Name) {
return Name != MainName;
})));

orc::MangleAndInterner Mangle(J->getExecutionSession(), J->getDataLayout());
orc::LocalCXXRuntimeOverrides CXXRuntimeOverrides;
ExitOnErr(CXXRuntimeOverrides.enable(J->getMainJITDylib(), Mangle));

Expand Down

0 comments on commit 3559831

Please sign in to comment.