Skip to content

Commit

Permalink
[cling] Inject absolute address of lstat
Browse files Browse the repository at this point in the history
This symbol may be in libc_nonshared.a where symbols are not found
automatically. See also upstream issue
llvm/llvm-project#61289. This fixes the
test DynamicLibraryManager/cached_realpath.C.
  • Loading branch information
hahnjo committed Jul 19, 2023
1 parent a50450c commit 7815ddc
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions interpreter/cling/lib/Interpreter/IncrementalJIT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
#include <llvm/Support/TargetRegistry.h>
#include <llvm/Target/TargetMachine.h>

#ifdef __linux__
#include <sys/stat.h>
#endif

using namespace llvm;
using namespace llvm::jitlink;
using namespace llvm::orc;
Expand Down Expand Up @@ -577,6 +581,18 @@ IncrementalJIT::IncrementalJIT(

char LinkerPrefix = this->m_TM->createDataLayout().getGlobalPrefix();

#if defined(__linux__) && defined(__GLIBC__)
// Inject lstat to pass test/DynamicLibraryManager/cached_realpath.C, it may
// be in libc_nonshared.a where symbols are not found automatically. See also
// upstream issue https://github.com/llvm/llvm-project/issues/61289.
SymbolMap LibcNonsharedSymbols;
LibcNonsharedSymbols[Jit->mangleAndIntern("lstat")] = JITEvaluatedSymbol(
static_cast<JITTargetAddress>(reinterpret_cast<uintptr_t>(&lstat)),
JITSymbolFlags::Exported);
cantFail(
Jit->getMainJITDylib().define(absoluteSymbols(LibcNonsharedSymbols)));
#endif

// Process symbol resolution
auto HostProcessLookup
= RTDynamicLibrarySearchGenerator::GetForCurrentProcess(LinkerPrefix,
Expand Down

0 comments on commit 7815ddc

Please sign in to comment.