Skip to content

Commit 72ddefa

Browse files
committed
Refactor code to return Optional<ExecutorSymbolDef>
1 parent 246fb49 commit 72ddefa

14 files changed

+62
-50
lines changed

llvm/include/llvm/ExecutionEngine/Orc/EPCGenericDylibManager.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,25 +52,25 @@ class EPCGenericDylibManager {
5252
LLVM_ABI Expected<tpctypes::DylibHandle> open(StringRef Path, uint64_t Mode);
5353

5454
/// Looks up symbols within the given dylib.
55-
Expected<std::vector<ExecutorSymbolDef>>
55+
Expected<tpctypes::LookupResult>
5656
lookup(tpctypes::DylibHandle H, const SymbolLookupSet &Lookup) {
57-
std::promise<MSVCPExpected<std::vector<ExecutorSymbolDef>>> RP;
57+
std::promise<MSVCPExpected<tpctypes::LookupResult>> RP;
5858
auto RF = RP.get_future();
5959
lookupAsync(H, Lookup, [&RP](auto R) { RP.set_value(std::move(R)); });
6060
return RF.get();
6161
}
6262

6363
/// Looks up symbols within the given dylib.
64-
Expected<std::vector<ExecutorSymbolDef>>
64+
Expected<tpctypes::LookupResult>
6565
lookup(tpctypes::DylibHandle H, const RemoteSymbolLookupSet &Lookup) {
66-
std::promise<MSVCPExpected<std::vector<ExecutorSymbolDef>>> RP;
66+
std::promise<MSVCPExpected<tpctypes::LookupResult>> RP;
6767
auto RF = RP.get_future();
6868
lookupAsync(H, Lookup, [&RP](auto R) { RP.set_value(std::move(R)); });
6969
return RF.get();
7070
}
7171

7272
using SymbolLookupCompleteFn =
73-
unique_function<void(Expected<std::vector<ExecutorSymbolDef>>)>;
73+
unique_function<void(Expected<tpctypes::LookupResult>)>;
7474

7575
/// Looks up symbols within the given dylib.
7676
LLVM_ABI void lookupAsync(tpctypes::DylibHandle H,

llvm/include/llvm/ExecutionEngine/Orc/Shared/OrcRTBridge.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ using SPSSimpleExecutorDylibManagerLookupSignature =
7272
shared::SPSExecutorAddr, shared::SPSExecutorAddr,
7373
shared::SPSRemoteSymbolLookupSet);
7474

75-
using SPSSimpleExecutorDylibManagerResolveSignature =
76-
shared::SPSExpected<shared::SPSSequence<shared::SPSExecutorSymbolDef>>(
77-
shared::SPSExecutorAddr, shared::SPSRemoteSymbolLookupSet);
75+
using SPSSimpleExecutorDylibManagerResolveSignature = shared::SPSExpected<
76+
shared::SPSSequence<shared::SPSOptional<shared::SPSExecutorSymbolDef>>>(
77+
shared::SPSExecutorAddr, shared::SPSRemoteSymbolLookupSet);
7878

7979
using SPSSimpleExecutorMemoryManagerReserveSignature =
8080
shared::SPSExpected<shared::SPSExecutorAddr>(shared::SPSExecutorAddr,

llvm/include/llvm/ExecutionEngine/Orc/Shared/TargetProcessControlTypes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ using DylibHandle = ExecutorAddr;
118118
/// dylib in the target process.
119119
using ResolverHandle = ExecutorAddr;
120120

121-
using LookupResult = std::vector<ExecutorSymbolDef>;
121+
using LookupResult = std::vector<std::optional<ExecutorSymbolDef>>;
122122

123123
} // end namespace tpctypes
124124

llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/ExecutorResolver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace llvm::orc {
2323

2424
class ExecutorResolver {
2525
public:
26-
using ResolveResult = Expected<std::vector<ExecutorSymbolDef>>;
26+
using ResolveResult = Expected<std::vector<std::optional<ExecutorSymbolDef>>>;
2727
using YieldResolveResultFn = unique_function<void(ResolveResult)>;
2828

2929
virtual ~ExecutorResolver() = default;

llvm/lib/ExecutionEngine/Orc/EPCDebugObjectRegistrar.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@ Expected<std::unique_ptr<EPCDebugObjectRegistrar>> createJITLoaderGDBRegistrar(
4141
assert(Result->size() == 1 && "Unexpected number of dylibs in result");
4242
assert((*Result)[0].size() == 1 &&
4343
"Unexpected number of addresses in result");
44+
assert((*Result)[0][0].has_value() &&
45+
"Expected a valid address in the lookup result");
4446

45-
ExecutorAddr RegisterAddr = (*Result)[0][0].getAddress();
47+
ExecutorAddr RegisterAddr = (*Result)[0][0]->getAddress();
4648
return std::make_unique<EPCDebugObjectRegistrar>(ES, RegisterAddr);
4749
}
4850

llvm/lib/ExecutionEngine/Orc/EPCDynamicLibrarySearchGenerator.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,15 @@ Error EPCDynamicLibrarySearchGenerator::tryToGenerate(
7979
assert(Result->front().size() == LookupSymbols.size() &&
8080
"Result has incorrect number of elements");
8181

82+
auto SymsIt = Result->front().begin();
83+
SymbolNameSet MissingSymbols;
8284
SymbolMap NewSymbols;
83-
auto ResultI = Result->front().begin();
84-
for (auto &KV : LookupSymbols) {
85-
if (ResultI->getAddress())
86-
NewSymbols[KV.first] = *ResultI;
87-
++ResultI;
85+
for (auto &[Name, Flags] : LookupSymbols) {
86+
const auto &Sym = *SymsIt++;
87+
if (Sym && Sym->getAddress())
88+
NewSymbols[Name] = *Sym;
89+
else if (LLVM_UNLIKELY(!Sym && Flags == SymbolLookupFlags::RequiredSymbol))
90+
MissingSymbols.insert(Name);
8891
}
8992

9093
LLVM_DEBUG({
@@ -96,6 +99,10 @@ Error EPCDynamicLibrarySearchGenerator::tryToGenerate(
9699
if (NewSymbols.empty())
97100
return LS.continueLookup(Error::success());
98101

102+
if (LLVM_UNLIKELY(!MissingSymbols.empty()))
103+
return LS.continueLookup(make_error<SymbolsNotFound>(
104+
this->EPC.getSymbolStringPool(), std::move(MissingSymbols)));
105+
99106
// Define resolved symbols.
100107
Error Err = addAbsolutes(JD, std::move(NewSymbols));
101108

llvm/lib/ExecutionEngine/Orc/EPCGenericDylibManager.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ void EPCGenericDylibManager::lookupAsync(tpctypes::DylibHandle H,
8989
SAs.Resolve,
9090
[Complete = std::move(Complete)](
9191
Error SerializationErr,
92-
Expected<std::vector<ExecutorSymbolDef>> Result) mutable {
92+
Expected<std::vector<std::optional<ExecutorSymbolDef>>>
93+
Result) mutable {
9394
if (SerializationErr) {
9495
cantFail(Result.takeError());
9596
Complete(std::move(SerializationErr));
@@ -107,7 +108,8 @@ void EPCGenericDylibManager::lookupAsync(tpctypes::DylibHandle H,
107108
SAs.Resolve,
108109
[Complete = std::move(Complete)](
109110
Error SerializationErr,
110-
Expected<std::vector<ExecutorSymbolDef>> Result) mutable {
111+
Expected<std::vector<std::optional<ExecutorSymbolDef>>>
112+
Result) mutable {
111113
if (SerializationErr) {
112114
cantFail(Result.takeError());
113115
Complete(std::move(SerializationErr));

llvm/lib/ExecutionEngine/Orc/ExecutorResolutionGenerator.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,16 @@ Error ExecutorResolutionGenerator::tryToGenerate(
6262
assert(Result->front().size() == LookupSymbols.size() &&
6363
"Result has incorrect number of elements");
6464

65-
const std::vector<ExecutorSymbolDef> &Syms = Result->front();
66-
size_t SymIdx = 0;
65+
// const tpctypes::LookupResult &Syms = Result->front();
66+
// size_t SymIdx = 0;
67+
auto Syms = Result->front().begin();
6768
SymbolNameSet MissingSymbols;
6869
SymbolMap NewSyms;
6970
for (auto &[Name, Flags] : LookupSymbols) {
70-
auto Sym = Syms[SymIdx++];
71-
if (Sym.getAddress())
72-
NewSyms[Name] = Sym;
73-
else if (LLVM_UNLIKELY(Flags == SymbolLookupFlags::RequiredSymbol))
71+
const auto &Sym = *Syms++;
72+
if (Sym && Sym->getAddress())
73+
NewSyms[Name] = *Sym;
74+
else if (LLVM_UNLIKELY(!Sym && Flags == SymbolLookupFlags::RequiredSymbol))
7475
MissingSymbols.insert(Name);
7576
}
7677

llvm/lib/ExecutionEngine/Orc/LookupAndRecordAddrs.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,10 @@ Error lookupAndRecordAddrs(
7272
return make_error<StringError>("Error in lookup result elements",
7373
inconvertibleErrorCode());
7474

75-
for (unsigned I = 0; I != Pairs.size(); ++I)
76-
*Pairs[I].second = Result->front()[I].getAddress();
77-
75+
for (unsigned I = 0; I != Pairs.size(); ++I) {
76+
if (Result->front()[I])
77+
*Pairs[I].second = Result->front()[I]->getAddress();
78+
}
7879
return Error::success();
7980
}
8081

llvm/lib/ExecutionEngine/Orc/SelfExecutorProcessControl.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -91,22 +91,18 @@ void SelfExecutorProcessControl::lookupSymbolsAsync(
9191

9292
for (auto &Elem : Request) {
9393
sys::DynamicLibrary Dylib(Elem.Handle.toPtr<void *>());
94-
R.push_back(std::vector<ExecutorSymbolDef>());
94+
R.push_back(tpctypes::LookupResult());
9595
for (auto &KV : Elem.Symbols) {
9696
auto &Sym = KV.first;
9797
std::string Tmp((*Sym).data() + !!GlobalManglingPrefix,
9898
(*Sym).size() - !!GlobalManglingPrefix);
9999
void *Addr = Dylib.getAddressOfSymbol(Tmp.c_str());
100-
if (!Addr && KV.second == SymbolLookupFlags::RequiredSymbol) {
101-
// FIXME: Collect all failing symbols before erroring out.
102-
SymbolNameVector MissingSymbols;
103-
MissingSymbols.push_back(Sym);
104-
return Complete(
105-
make_error<SymbolsNotFound>(SSP, std::move(MissingSymbols)));
106-
}
107-
// FIXME: determine accurate JITSymbolFlags.
108-
R.back().push_back(
109-
{ExecutorAddr::fromPtr(Addr), JITSymbolFlags::Exported});
100+
if (!Addr && KV.second == SymbolLookupFlags::RequiredSymbol)
101+
R.back().emplace_back();
102+
else
103+
// FIXME: determine accurate JITSymbolFlags.
104+
R.back().emplace_back(ExecutorSymbolDef(ExecutorAddr::fromPtr(Addr),
105+
JITSymbolFlags::Exported));
110106
}
111107
}
112108

0 commit comments

Comments
 (0)