From 355983103f008b094b5cdd26233eb0ed7113e7ec Mon Sep 17 00:00:00 2001 From: Lang Hames Date: Thu, 2 Jan 2020 15:47:47 -0800 Subject: [PATCH] [lli] Add a filter to avoid importing the process's main symbol. 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. --- llvm/tools/lli/lli.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/llvm/tools/lli/lli.cpp b/llvm/tools/lli/lli.cpp index 9aaeef0..87a8c9f 100644 --- a/llvm/tools/lli/lli.cpp +++ b/llvm/tools/lli/lli.cpp @@ -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)); -- 2.7.4