|
31 | 31 | #include <llvm/Support/TargetRegistry.h>
|
32 | 32 | #include <llvm/Target/TargetMachine.h>
|
33 | 33 |
|
| 34 | +#ifdef __linux__ |
| 35 | +#include <sys/stat.h> |
| 36 | +#endif |
| 37 | + |
34 | 38 | using namespace llvm;
|
35 | 39 | using namespace llvm::jitlink;
|
36 | 40 | using namespace llvm::orc;
|
@@ -489,6 +493,32 @@ CreateTargetMachine(const clang::CompilerInstance& CI, bool JITLink) {
|
489 | 493 |
|
490 | 494 | return cantFail(JTMB.createTargetMachine());
|
491 | 495 | }
|
| 496 | + |
| 497 | +#if defined(__linux__) && defined(__GLIBC__) |
| 498 | +static SymbolMap GetListOfLibcNonsharedSymbols(const LLJIT& Jit) { |
| 499 | + // Inject a number of symbols that may be in libc_nonshared.a where they are |
| 500 | + // not found automatically. Before DefinitionGenerators in ORCv2, this used |
| 501 | + // to be done by RTDyldMemoryManager::getSymbolAddressInProcess See also the |
| 502 | + // upstream issue https://github.com/llvm/llvm-project/issues/61289. |
| 503 | + |
| 504 | + static const std::pair<const char*, const void*> NamePtrList[] = { |
| 505 | + {"stat", (void*)&stat}, {"fstat", (void*)&fstat}, |
| 506 | + {"lstat", (void*)&lstat}, {"stat64", (void*)&stat64}, |
| 507 | + {"fstat64", (void*)&fstat64}, {"lstat64", (void*)&lstat64}, |
| 508 | + {"fstatat", (void*)&fstatat}, {"fstatat64", (void*)&fstatat64}, |
| 509 | + {"mknod", (void*)&mknod}, {"mknodat", (void*)&mknodat}, |
| 510 | + }; |
| 511 | + |
| 512 | + SymbolMap LibcNonsharedSymbols; |
| 513 | + for (const auto& NamePtr : NamePtrList) { |
| 514 | + auto Addr = static_cast<JITTargetAddress>( |
| 515 | + reinterpret_cast<uintptr_t>(NamePtr.second)); |
| 516 | + LibcNonsharedSymbols[Jit.mangleAndIntern(NamePtr.first)] = |
| 517 | + JITEvaluatedSymbol(Addr, JITSymbolFlags::Exported); |
| 518 | + } |
| 519 | + return LibcNonsharedSymbols; |
| 520 | +} |
| 521 | +#endif |
492 | 522 | } // unnamed namespace
|
493 | 523 |
|
494 | 524 | namespace cling {
|
@@ -598,6 +628,12 @@ IncrementalJIT::IncrementalJIT(
|
598 | 628 | return !m_ForbidDlSymbols.contains(*Sym); });
|
599 | 629 | Jit->getMainJITDylib().addGenerator(std::move(LibLookup));
|
600 | 630 |
|
| 631 | +#if defined(__linux__) && defined(__GLIBC__) |
| 632 | + // See comment in ListOfLibcNonsharedSymbols. |
| 633 | + cantFail(Jit->getMainJITDylib().define( |
| 634 | + absoluteSymbols(GetListOfLibcNonsharedSymbols(*Jit)))); |
| 635 | +#endif |
| 636 | + |
601 | 637 | // This replaces llvm::orc::ExecutionSession::logErrorsToStdErr:
|
602 | 638 | auto&& ErrorReporter = [&Executor, LinkerPrefix, Verbose](Error Err) {
|
603 | 639 | Err = handleErrors(std::move(Err),
|
|
0 commit comments