Re-teach getAddressOfGlobal to tell if something came from the JIT.
This patch also inverts the parameter from ExcludeHostSymbols to IncludeHostSymbols to improve readability. As written in one of the FIXMEs this is a temporary solution which allows us to go further with the llvm-13 upgrade. We can rework the getAddress* functionality to reuse more the ORCV2 infrastructure and more importantly to use that infrastructure in the recommended way.
This commit is contained in:
parent
6656a92d22
commit
3ea6cd0e18
@ -141,7 +141,7 @@ namespace {
|
||||
return false;
|
||||
|
||||
// Find the symbol in JIT or shared libraries.
|
||||
if (m_JIT.getSymbolAddress(GV.getName(), /*ExcludeHostSymbols*/ false)) {
|
||||
if (m_JIT.getSymbolAddress(GV.getName(), /*IncludeHostSymbols*/ true)) {
|
||||
#if !defined(_WIN32)
|
||||
// Heuristically, Windows cannot handle cross-library variables; they
|
||||
// must be library-local.
|
||||
|
@ -329,15 +329,36 @@ void IncrementalExecutor::replaceSymbol(const char* Name, void* Addr) const {
|
||||
|
||||
void* IncrementalExecutor::getAddressOfGlobal(llvm::StringRef symbolName,
|
||||
bool* fromJIT /*=0*/) const {
|
||||
constexpr bool excludeHostSymbols = true;
|
||||
if (void* addr = m_JIT->getSymbolAddress(symbolName, excludeHostSymbols)) {
|
||||
// It's not from the JIT if it's in a dylib.
|
||||
if (fromJIT)
|
||||
*fromJIT = true;
|
||||
return addr;
|
||||
constexpr bool includeHostSymbols = true;
|
||||
|
||||
void* address = m_JIT->getSymbolAddress(symbolName, includeHostSymbols);
|
||||
|
||||
// FIXME: If we split the loaded libraries into a separate JITDylib we should
|
||||
// be able to delete this code and use something like:
|
||||
// if (IncludeHostSymbols) {
|
||||
// if (auto Sym = lookup(<HostSymbolsJD>, Name)) {
|
||||
// fromJIT = false;
|
||||
// return Sym;
|
||||
// }
|
||||
// }
|
||||
// if (auto Sym = lookup(<REPLJD>, Name)) {
|
||||
// fromJIT = true;
|
||||
// return Sym;
|
||||
// }
|
||||
// fromJIT = false;
|
||||
// return nullptr;
|
||||
if (fromJIT) {
|
||||
// FIXME: See comments on DLSym below.
|
||||
// We use dlsym to just tell if somethings was from the jit or not.
|
||||
#if !defined(_WIN32)
|
||||
void* Addr = llvm::sys::DynamicLibrary::SearchForAddressOfSymbol(symbolName.str());
|
||||
#else
|
||||
void* Addr = const_cast<void*>(platform::DLSym(Name));
|
||||
#endif
|
||||
*fromJIT = !Addr;
|
||||
}
|
||||
|
||||
return m_JIT->getSymbolAddress(symbolName, !excludeHostSymbols);
|
||||
return address;
|
||||
}
|
||||
|
||||
void*
|
||||
|
@ -133,6 +133,7 @@ llvm::Error IncrementalJIT::removeModule(const Transaction& T) {
|
||||
|
||||
JITTargetAddress IncrementalJIT::addOrReplaceDefinition(StringRef LinkerMangledName,
|
||||
JITTargetAddress KnownAddr) {
|
||||
void* Symbol = getSymbolAddress(LinkerMangledName, /*IncludeFromHost=*/true);
|
||||
|
||||
// Nothing to define, we are redefining the same function. FIXME: Diagnose.
|
||||
if (Symbol && (JITTargetAddress)Symbol == KnownAddr)
|
||||
@ -161,9 +162,9 @@ JITTargetAddress IncrementalJIT::addOrReplaceDefinition(StringRef LinkerMangledN
|
||||
return KnownAddr;
|
||||
}
|
||||
|
||||
void* IncrementalJIT::getSymbolAddress(StringRef Name, bool ExcludeHostSymbols) {
|
||||
void* IncrementalJIT::getSymbolAddress(StringRef Name, bool IncludeHostSymbols) {
|
||||
std::unique_lock<SharedAtomicFlag> G(SkipHostProcessLookup, std::defer_lock);
|
||||
if (ExcludeHostSymbols)
|
||||
if (!IncludeHostSymbols)
|
||||
G.lock();
|
||||
|
||||
Expected<JITEvaluatedSymbol> Symbol = Jit->lookup(Name);
|
||||
|
@ -62,9 +62,9 @@ public:
|
||||
llvm::Error removeModule(const Transaction& T);
|
||||
|
||||
/// Get the address of a symbol based on its IR name (as coming from clang's
|
||||
/// mangler). The ExcludeHostSymbols parameter controls whether the lookup
|
||||
/// should include symbols from the host process or not.
|
||||
void* getSymbolAddress(llvm::StringRef Name, bool ExcludeHostSymbols);
|
||||
/// mangler). The IncludeHostSymbols parameter controls whether the lookup
|
||||
/// should include symbols from the host process (via dlsym) or not.
|
||||
void* getSymbolAddress(llvm::StringRef Name, bool IncludeHostSymbols);
|
||||
|
||||
/// Inject a symbol with a known address.
|
||||
llvm::JITTargetAddress addOrReplaceDefinition(llvm::StringRef LinkerMangledName,
|
||||
|
Loading…
x
Reference in New Issue
Block a user