Hi Lang,
Thank you for your answer! This helped me again a lot!! Also that ResourceTracker is a really neat feature! Looking forward to it! :3
I changed the title cause… there is another issue I have (sorry about that…)
I’m finally allowed to investigate the ORC JIT for integration into our system, which meant I got a few days to actually play around with it. However, another problem arise which breaks my concept. It is the never ending story of “cross references”. I have again two Modules, which are added to two different LLJIT instances, but they are referencing each other. In the past you suggested me to use the LookUp function of the ExecutionSession to get the addresses – so I wrote this:
bool ModuleLoader :: resolve()
{
auto &ES = this->jit->getExecutionSession();
SymbolLookupSet lookupSet;
this->undefinedReferences.clear();
for(const auto &element : this->symbolsOfInterrest)
{
lookupSet.add(element.second.name,llvm::orc::SymbolLookupFlags::WeaklyReferencedSymbol);
}
auto result = ES.lookup({{&jit->getMainJITDylib(), llvm::orc::JITDylibLookupFlags::MatchAllSymbols}}, lookupSet, llvm::orc::LookupKind::Static, llvm::orc::SymbolState::Resolved);
if(result)
{
for(const auto &element : *result)
{
const llvm::StringRef &name = (*element.first);
const size_t hash = calculateHash(name);
printf(“>>>%s @ 0x%p\n”, name.data(), element.second.getAddress());
this->symbolsOfInterrest[hash].adr = element.second.getAddress();
}
}
else
{
ES.reportError(result.takeError());
}
this->mtx.unlock();
return (this->undefinedReferences.size() == 0ull);
}
I also attached a reporter to the ES which will handle “llvm::orc::SymbolsNotFound” by copying SymbolVector to the “undefinedReferences”. If I call this function and have every symbol resolved, then I can use the addresses to actually execute them. That is great! However, when I have an undefined Reference, things get strange… The first call will trigger my “tryToGenerate” function but it will not be able to resolve a certain symbol. The reporter will be triggered and the “undefinedReferences” SymbolVector will have size 1.
When I call the function a second time however, the “tryToGenerate” function will not be called anymore, so my vector will be empty, the undefined reference is still not resolved, but I return with a true and crash my program. So even if I would have an address for that one symbol in the second run, I would have no chance to tell “anyone” cause the “tryToGenerate” function was never called… Said function looks like that though:
llvm::Error ReferenceManager::UndefinedReferenceResolver :: tryToGenerate(llvm::orc::LookupKind K, llvm::orc::JITDylib &JD, llvm::orc::JITDylibLookupFlags JDLookupFlags, const llvm::orc::SymbolLookupSet &LookupSet)
{
llvm::orc::SymbolNameVector notFound;
llvm::orc::SymbolMap NewSymbols;
for(const auto &name : LookupSet)
{
printf(“Generate!\n”);
const uintptr_t adr = UndefinedReferenceResolver::lookup((*name.first).data());
if(adr)
{
NewSymbols[name.first] = llvm::JITEvaluatedSymbol(adr, llvm::JITSymbolFlags::Absolute);
}
else
{
notFound.push_back(name.first);
}
}
JD.define(absoluteSymbols(std::move(NewSymbols)));
return (notFound.size() == 0) ? llvm::Error::success() : llvm::make_errorllvm::orc::SymbolsNotFound(std::move(notFound));
}
When I use “llvm::orc::JITDylibLookupFlags::MatchExportedSymbolsOnly” then I will get 1 undefined Reference in the first run, but a total of 9 in the second run, because every symbol I wanted to lookup was now an undefined reference.
Thank you for the help in advance!
Kind greetings
Björn