mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-03 16:41:06 +03:00
Symbol resolving refactoring and more logs
This commit is contained in:
parent
6476710be9
commit
8001bad9cf
1 changed files with 25 additions and 13 deletions
|
@ -3,6 +3,7 @@
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
#include "optimizer.h"
|
#include "optimizer.h"
|
||||||
#include "context.h"
|
#include "context.h"
|
||||||
|
@ -213,6 +214,21 @@ llvm::ArrayRef<T> toArray(T* ptr, size_t size) {
|
||||||
return llvm::ArrayRef<T>(ptr, size);
|
return llvm::ArrayRef<T>(ptr, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void* resolveSymbol(llvm::JITSymbol& symbol) {
|
||||||
|
auto addr = symbol.getAddress();
|
||||||
|
#if LDC_LLVM_VER >= 500
|
||||||
|
if (!addr) {
|
||||||
|
consumeError(addr.takeError());
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return reinterpret_cast<void*>(addr.get());
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
return reinterpret_cast<void*>(addr);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
struct JitFinaliser final {
|
struct JitFinaliser final {
|
||||||
MyJIT& jit;
|
MyJIT& jit;
|
||||||
bool finalized = false;
|
bool finalized = false;
|
||||||
|
@ -296,25 +312,21 @@ void rtCompileProcessImplSoInternal(const RtComileModuleList* modlist_head, cons
|
||||||
interruptPoint(context, "Resolve functions");
|
interruptPoint(context, "Resolve functions");
|
||||||
for (auto&& fun: functions) {
|
for (auto&& fun: functions) {
|
||||||
auto symbol = myJit.findSymbol(fun.first);
|
auto symbol = myJit.findSymbol(fun.first);
|
||||||
auto addr = symbol.getAddress();
|
auto addr = resolveSymbol(symbol);
|
||||||
#if LDC_LLVM_VER >= 500
|
if (nullptr == addr) {
|
||||||
if (!addr) {
|
|
||||||
consumeError(addr.takeError());
|
|
||||||
std::string desc = std::string("Symbol not found in jitted code: ") + fun.first;
|
std::string desc = std::string("Symbol not found in jitted code: ") + fun.first;
|
||||||
fatal(context, desc);
|
fatal(context, desc);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
*fun.second = reinterpret_cast<void*>(addr.get());
|
*fun.second = addr;
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
if (0 == addr) {
|
if (nullptr != context.interruptPointHandler) {
|
||||||
std::string desc = std::string("Symbol not found in jitted code: ") + fun.first;
|
std::stringstream ss;
|
||||||
fatal(context, desc);
|
ss << fun.first << " to " << addr;
|
||||||
|
auto str = ss.str();
|
||||||
|
interruptPoint(context, "Resolved", str.c_str());
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
*fun.second = reinterpret_cast<void*>(addr);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
jitFinalizer.finalze();
|
jitFinalizer.finalze();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue