2018-01-10 01:09:38 +01:00
|
|
|
//===----------- CoreAPIsTest.cpp - Unit tests for Core ORC APIs ----------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "OrcTestCommon.h"
|
2018-04-30 16:59:11 +02:00
|
|
|
#include "llvm/Config/llvm-config.h"
|
2018-01-10 01:09:38 +01:00
|
|
|
#include "llvm/ExecutionEngine/Orc/Core.h"
|
2018-06-14 23:16:29 +02:00
|
|
|
#include "llvm/ExecutionEngine/Orc/OrcError.h"
|
2018-01-10 01:09:38 +01:00
|
|
|
|
|
|
|
#include <set>
|
2018-03-14 05:18:04 +01:00
|
|
|
#include <thread>
|
2018-01-10 01:09:38 +01:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
using namespace llvm::orc;
|
|
|
|
|
2018-07-20 20:31:50 +02:00
|
|
|
class CoreAPIsStandardTest : public CoreAPIsBasedStandardTest {};
|
|
|
|
|
2018-01-10 01:09:38 +01:00
|
|
|
namespace {
|
|
|
|
|
2018-03-20 04:49:29 +01:00
|
|
|
class SimpleMaterializationUnit : public MaterializationUnit {
|
2018-01-10 01:09:38 +01:00
|
|
|
public:
|
2018-04-16 20:05:24 +02:00
|
|
|
using MaterializeFunction =
|
|
|
|
std::function<void(MaterializationResponsibility)>;
|
|
|
|
using DiscardFunction = std::function<void(const VSO &, SymbolStringPtr)>;
|
2018-04-12 20:35:08 +02:00
|
|
|
using DestructorFunction = std::function<void()>;
|
2018-01-10 01:09:38 +01:00
|
|
|
|
2018-04-12 20:35:08 +02:00
|
|
|
SimpleMaterializationUnit(
|
2018-05-17 00:24:30 +02:00
|
|
|
SymbolFlagsMap SymbolFlags, MaterializeFunction Materialize,
|
|
|
|
DiscardFunction Discard = DiscardFunction(),
|
2018-04-12 20:35:08 +02:00
|
|
|
DestructorFunction Destructor = DestructorFunction())
|
2018-05-17 00:24:30 +02:00
|
|
|
: MaterializationUnit(std::move(SymbolFlags)),
|
|
|
|
Materialize(std::move(Materialize)), Discard(std::move(Discard)),
|
|
|
|
Destructor(std::move(Destructor)) {}
|
2018-04-12 20:35:08 +02:00
|
|
|
|
|
|
|
~SimpleMaterializationUnit() override {
|
|
|
|
if (Destructor)
|
|
|
|
Destructor();
|
|
|
|
}
|
2018-01-10 01:09:38 +01:00
|
|
|
|
2018-04-16 20:05:24 +02:00
|
|
|
void materialize(MaterializationResponsibility R) override {
|
|
|
|
Materialize(std::move(R));
|
|
|
|
}
|
2018-01-10 01:09:38 +01:00
|
|
|
|
2018-04-16 20:05:24 +02:00
|
|
|
void discard(const VSO &V, SymbolStringPtr Name) override {
|
2018-05-17 00:24:30 +02:00
|
|
|
if (Discard)
|
|
|
|
Discard(V, std::move(Name));
|
|
|
|
else
|
|
|
|
llvm_unreachable("Discard not supported");
|
2018-01-10 01:09:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
MaterializeFunction Materialize;
|
|
|
|
DiscardFunction Discard;
|
2018-04-12 20:35:08 +02:00
|
|
|
DestructorFunction Destructor;
|
2018-01-10 01:09:38 +01:00
|
|
|
};
|
|
|
|
|
2018-07-20 22:20:45 +02:00
|
|
|
|
|
|
|
TEST_F(CoreAPIsStandardTest, AsynchronousSymbolQuerySuccessfulResolutionOnly) {
|
2018-01-10 01:09:38 +01:00
|
|
|
bool OnResolutionRun = false;
|
|
|
|
bool OnReadyRun = false;
|
2018-07-20 22:20:45 +02:00
|
|
|
auto OnResolution =
|
|
|
|
[&](Expected<AsynchronousSymbolQuery::ResolutionResult> Result) {
|
|
|
|
EXPECT_TRUE(!!Result) << "Resolution unexpectedly returned error";
|
|
|
|
auto &Resolved = Result->Symbols;
|
|
|
|
auto I = Resolved.find(Foo);
|
|
|
|
EXPECT_NE(I, Resolved.end()) << "Could not find symbol definition";
|
|
|
|
EXPECT_EQ(I->second.getAddress(), FooAddr)
|
|
|
|
<< "Resolution returned incorrect result";
|
|
|
|
OnResolutionRun = true;
|
|
|
|
};
|
2018-01-10 01:09:38 +01:00
|
|
|
auto OnReady = [&](Error Err) {
|
|
|
|
cantFail(std::move(Err));
|
|
|
|
OnReadyRun = true;
|
|
|
|
};
|
|
|
|
|
2018-07-20 22:20:45 +02:00
|
|
|
AsynchronousSymbolQuery Q(SymbolNameSet({Foo}), OnResolution, OnReady);
|
2018-05-17 00:24:30 +02:00
|
|
|
|
2018-07-20 22:20:45 +02:00
|
|
|
Q.resolve(Foo, FooSym);
|
2018-05-17 00:24:30 +02:00
|
|
|
|
2018-07-20 22:20:45 +02:00
|
|
|
EXPECT_TRUE(Q.isFullyResolved()) << "Expected query to be fully resolved";
|
2018-05-17 00:24:30 +02:00
|
|
|
|
2018-07-20 22:20:45 +02:00
|
|
|
if (!Q.isFullyResolved())
|
|
|
|
return;
|
2018-07-20 20:31:53 +02:00
|
|
|
|
2018-07-20 22:20:45 +02:00
|
|
|
Q.handleFullyResolved();
|
2018-07-20 20:31:53 +02:00
|
|
|
|
2018-07-20 22:20:45 +02:00
|
|
|
EXPECT_TRUE(OnResolutionRun) << "OnResolutionCallback was not run";
|
|
|
|
EXPECT_FALSE(OnReadyRun) << "OnReady unexpectedly run";
|
2018-01-10 01:09:38 +01:00
|
|
|
}
|
|
|
|
|
2018-07-11 05:09:36 +02:00
|
|
|
TEST_F(CoreAPIsStandardTest, ExecutionSessionFailQuery) {
|
2018-01-10 01:09:38 +01:00
|
|
|
bool OnResolutionRun = false;
|
|
|
|
bool OnReadyRun = false;
|
|
|
|
|
2018-07-20 22:20:45 +02:00
|
|
|
auto OnResolution =
|
|
|
|
[&](Expected<AsynchronousSymbolQuery::ResolutionResult> Result) {
|
|
|
|
EXPECT_FALSE(!!Result) << "Resolution unexpectedly returned success";
|
|
|
|
auto Msg = toString(Result.takeError());
|
|
|
|
EXPECT_EQ(Msg, "xyz") << "Resolution returned incorrect result";
|
|
|
|
OnResolutionRun = true;
|
|
|
|
};
|
2018-01-10 01:09:38 +01:00
|
|
|
auto OnReady = [&](Error Err) {
|
|
|
|
cantFail(std::move(Err));
|
|
|
|
OnReadyRun = true;
|
|
|
|
};
|
|
|
|
|
2018-07-11 05:09:36 +02:00
|
|
|
AsynchronousSymbolQuery Q(SymbolNameSet({Foo}), OnResolution, OnReady);
|
2018-01-10 01:09:38 +01:00
|
|
|
|
2018-07-20 22:20:45 +02:00
|
|
|
ES.failQuery(Q, make_error<StringError>("xyz", inconvertibleErrorCode()));
|
2018-01-10 01:09:38 +01:00
|
|
|
|
|
|
|
EXPECT_TRUE(OnResolutionRun) << "OnResolutionCallback was not run";
|
|
|
|
EXPECT_FALSE(OnReadyRun) << "OnReady unexpectedly run";
|
|
|
|
}
|
|
|
|
|
2018-07-20 22:20:45 +02:00
|
|
|
TEST_F(CoreAPIsStandardTest, SimpleAsynchronousSymbolQueryAgainstVSO) {
|
|
|
|
bool OnResolutionRun = false;
|
2018-01-10 01:09:38 +01:00
|
|
|
bool OnReadyRun = false;
|
|
|
|
|
2018-07-20 22:20:45 +02:00
|
|
|
auto OnResolution =
|
|
|
|
[&](Expected<AsynchronousSymbolQuery::ResolutionResult> Result) {
|
|
|
|
EXPECT_TRUE(!!Result) << "Query unexpectedly returned error";
|
|
|
|
auto &Resolved = Result->Symbols;
|
|
|
|
auto I = Resolved.find(Foo);
|
|
|
|
EXPECT_NE(I, Resolved.end()) << "Could not find symbol definition";
|
|
|
|
EXPECT_EQ(I->second.getAddress(), FooSym.getAddress())
|
|
|
|
<< "Resolution returned incorrect result";
|
|
|
|
OnResolutionRun = true;
|
|
|
|
};
|
2018-01-10 01:09:38 +01:00
|
|
|
|
|
|
|
auto OnReady = [&](Error Err) {
|
|
|
|
cantFail(std::move(Err));
|
|
|
|
OnReadyRun = true;
|
|
|
|
};
|
|
|
|
|
2018-07-20 22:20:45 +02:00
|
|
|
SymbolNameSet Names({Foo});
|
|
|
|
|
|
|
|
auto Q =
|
|
|
|
std::make_shared<AsynchronousSymbolQuery>(Names, OnResolution, OnReady);
|
|
|
|
|
|
|
|
auto Defs = absoluteSymbols({{Foo, FooSym}});
|
|
|
|
cantFail(V.define(Defs));
|
|
|
|
assert(Defs == nullptr && "Defs should have been accepted");
|
|
|
|
V.lookup(Q, Names);
|
|
|
|
|
|
|
|
EXPECT_TRUE(OnResolutionRun) << "OnResolutionCallback was not run";
|
|
|
|
EXPECT_TRUE(OnReadyRun) << "OnReady was not run";
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(CoreAPIsStandardTest, EmptyVSOAndQueryLookup) {
|
|
|
|
bool OnResolvedRun = false;
|
|
|
|
bool OnReadyRun = false;
|
|
|
|
|
|
|
|
auto Q = std::make_shared<AsynchronousSymbolQuery>(
|
|
|
|
SymbolNameSet(),
|
|
|
|
[&](Expected<AsynchronousSymbolQuery::ResolutionResult> RR) {
|
|
|
|
cantFail(std::move(RR));
|
|
|
|
OnResolvedRun = true;
|
|
|
|
},
|
|
|
|
[&](Error Err) {
|
|
|
|
cantFail(std::move(Err));
|
|
|
|
OnReadyRun = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
V.lookup(std::move(Q), {});
|
2018-06-17 20:59:01 +02:00
|
|
|
|
|
|
|
EXPECT_TRUE(OnResolvedRun) << "OnResolved was not run for empty query";
|
|
|
|
EXPECT_TRUE(OnReadyRun) << "OnReady was not run for empty query";
|
|
|
|
}
|
|
|
|
|
2018-07-11 05:09:36 +02:00
|
|
|
TEST_F(CoreAPIsStandardTest, ChainedVSOLookup) {
|
|
|
|
cantFail(V.define(absoluteSymbols({{Foo, FooSym}})));
|
2018-06-17 20:59:01 +02:00
|
|
|
|
|
|
|
auto &V2 = ES.createVSO("V2");
|
|
|
|
|
|
|
|
bool OnResolvedRun = false;
|
|
|
|
bool OnReadyRun = false;
|
|
|
|
|
|
|
|
auto Q = std::make_shared<AsynchronousSymbolQuery>(
|
|
|
|
SymbolNameSet({Foo}),
|
2018-07-20 22:20:45 +02:00
|
|
|
[&](Expected<AsynchronousSymbolQuery::ResolutionResult> RR) {
|
|
|
|
cantFail(std::move(RR));
|
2018-06-17 20:59:01 +02:00
|
|
|
OnResolvedRun = true;
|
|
|
|
},
|
|
|
|
[&](Error Err) {
|
|
|
|
cantFail(std::move(Err));
|
|
|
|
OnReadyRun = true;
|
|
|
|
});
|
|
|
|
|
2018-07-20 22:20:45 +02:00
|
|
|
V2.lookup(Q, V.lookup(Q, {Foo}));
|
2018-06-17 20:59:01 +02:00
|
|
|
|
|
|
|
EXPECT_TRUE(OnResolvedRun) << "OnResolved was not run for empty query";
|
|
|
|
EXPECT_TRUE(OnReadyRun) << "OnReady was not run for empty query";
|
|
|
|
}
|
|
|
|
|
2018-07-11 05:09:36 +02:00
|
|
|
TEST_F(CoreAPIsStandardTest, LookupFlagsTest) {
|
2018-01-21 04:20:39 +01:00
|
|
|
// Test that lookupFlags works on a predefined symbol, and does not trigger
|
2018-07-11 05:09:36 +02:00
|
|
|
// materialization of a lazy symbol. Make the lazy symbol weak to test that
|
|
|
|
// the weak flag is propagated correctly.
|
2018-01-21 04:20:39 +01:00
|
|
|
|
2018-07-11 05:09:36 +02:00
|
|
|
BarSym.setFlags(static_cast<JITSymbolFlags::FlagNames>(
|
|
|
|
JITSymbolFlags::Exported | JITSymbolFlags::Weak));
|
2018-03-20 04:49:29 +01:00
|
|
|
auto MU = llvm::make_unique<SimpleMaterializationUnit>(
|
2018-07-11 05:09:36 +02:00
|
|
|
SymbolFlagsMap({{Bar, BarSym.getFlags()}}),
|
2018-04-16 20:05:24 +02:00
|
|
|
[](MaterializationResponsibility R) {
|
2018-01-21 04:20:39 +01:00
|
|
|
llvm_unreachable("Symbol materialized on flags lookup");
|
|
|
|
});
|
|
|
|
|
2018-07-11 05:09:36 +02:00
|
|
|
cantFail(V.define(absoluteSymbols({{Foo, FooSym}})));
|
2018-05-17 00:24:30 +02:00
|
|
|
cantFail(V.define(std::move(MU)));
|
2018-01-21 04:20:39 +01:00
|
|
|
|
|
|
|
SymbolNameSet Names({Foo, Bar, Baz});
|
|
|
|
|
2018-07-20 20:31:52 +02:00
|
|
|
auto SymbolFlags = V.lookupFlags(Names);
|
2018-01-21 04:20:39 +01:00
|
|
|
|
2018-01-25 02:43:00 +01:00
|
|
|
EXPECT_EQ(SymbolFlags.size(), 2U)
|
2018-01-21 04:20:39 +01:00
|
|
|
<< "Returned symbol flags contains unexpected results";
|
2018-01-25 02:43:00 +01:00
|
|
|
EXPECT_EQ(SymbolFlags.count(Foo), 1U) << "Missing lookupFlags result for Foo";
|
2018-07-11 05:09:36 +02:00
|
|
|
EXPECT_EQ(SymbolFlags[Foo], FooSym.getFlags())
|
|
|
|
<< "Incorrect flags returned for Foo";
|
2018-01-25 02:43:00 +01:00
|
|
|
EXPECT_EQ(SymbolFlags.count(Bar), 1U)
|
2018-01-21 04:20:39 +01:00
|
|
|
<< "Missing lookupFlags result for Bar";
|
2018-07-11 05:09:36 +02:00
|
|
|
EXPECT_EQ(SymbolFlags[Bar], BarSym.getFlags())
|
|
|
|
<< "Incorrect flags returned for Bar";
|
2018-01-21 04:20:39 +01:00
|
|
|
}
|
|
|
|
|
2018-07-11 05:09:36 +02:00
|
|
|
TEST_F(CoreAPIsStandardTest, TestBasicAliases) {
|
2018-06-26 03:22:29 +02:00
|
|
|
cantFail(V.define(absoluteSymbols({{Foo, FooSym}, {Bar, BarSym}})));
|
|
|
|
cantFail(V.define(symbolAliases({{Baz, {Foo, JITSymbolFlags::Exported}},
|
|
|
|
{Qux, {Bar, JITSymbolFlags::Weak}}})));
|
|
|
|
cantFail(V.define(absoluteSymbols({{Qux, QuxSym}})));
|
|
|
|
|
|
|
|
auto Result = lookup({&V}, {Baz, Qux});
|
|
|
|
EXPECT_TRUE(!!Result) << "Unexpected lookup failure";
|
|
|
|
EXPECT_EQ(Result->count(Baz), 1U) << "No result for \"baz\"";
|
|
|
|
EXPECT_EQ(Result->count(Qux), 1U) << "No result for \"qux\"";
|
|
|
|
EXPECT_EQ((*Result)[Baz].getAddress(), FooSym.getAddress())
|
|
|
|
<< "\"Baz\"'s address should match \"Foo\"'s";
|
|
|
|
EXPECT_EQ((*Result)[Qux].getAddress(), QuxSym.getAddress())
|
|
|
|
<< "The \"Qux\" alias should have been overriden";
|
|
|
|
}
|
|
|
|
|
2018-07-11 05:09:36 +02:00
|
|
|
TEST_F(CoreAPIsStandardTest, TestChainedAliases) {
|
2018-07-11 01:34:56 +02:00
|
|
|
cantFail(V.define(absoluteSymbols({{Foo, FooSym}})));
|
2018-07-11 05:09:36 +02:00
|
|
|
cantFail(V.define(symbolAliases(
|
|
|
|
{{Baz, {Bar, BazSym.getFlags()}}, {Bar, {Foo, BarSym.getFlags()}}})));
|
2018-07-11 01:34:56 +02:00
|
|
|
|
|
|
|
auto Result = lookup({&V}, {Bar, Baz});
|
|
|
|
EXPECT_TRUE(!!Result) << "Unexpected lookup failure";
|
|
|
|
EXPECT_EQ(Result->count(Bar), 1U) << "No result for \"bar\"";
|
|
|
|
EXPECT_EQ(Result->count(Baz), 1U) << "No result for \"baz\"";
|
|
|
|
EXPECT_EQ((*Result)[Bar].getAddress(), FooSym.getAddress())
|
|
|
|
<< "\"Bar\"'s address should match \"Foo\"'s";
|
|
|
|
EXPECT_EQ((*Result)[Baz].getAddress(), FooSym.getAddress())
|
|
|
|
<< "\"Baz\"'s address should match \"Foo\"'s";
|
|
|
|
}
|
|
|
|
|
2018-07-11 05:09:36 +02:00
|
|
|
TEST_F(CoreAPIsStandardTest, TestTrivialCircularDependency) {
|
2018-06-17 18:59:53 +02:00
|
|
|
Optional<MaterializationResponsibility> FooR;
|
|
|
|
auto FooMU = llvm::make_unique<SimpleMaterializationUnit>(
|
2018-07-11 05:09:36 +02:00
|
|
|
SymbolFlagsMap({{Foo, FooSym.getFlags()}}),
|
2018-06-17 18:59:53 +02:00
|
|
|
[&](MaterializationResponsibility R) { FooR.emplace(std::move(R)); });
|
|
|
|
|
|
|
|
cantFail(V.define(FooMU));
|
|
|
|
|
|
|
|
bool FooReady = false;
|
2018-07-20 22:20:45 +02:00
|
|
|
auto Q =
|
|
|
|
std::make_shared<AsynchronousSymbolQuery>(
|
|
|
|
SymbolNameSet({ Foo }),
|
|
|
|
[](Expected<AsynchronousSymbolQuery::ResolutionResult> R) {
|
|
|
|
cantFail(std::move(R));
|
|
|
|
},
|
|
|
|
[&](Error Err) {
|
|
|
|
cantFail(std::move(Err));
|
|
|
|
FooReady = true;
|
|
|
|
});
|
2018-06-17 18:59:53 +02:00
|
|
|
|
2018-07-20 22:20:45 +02:00
|
|
|
V.lookup(std::move(Q), { Foo });
|
2018-06-17 18:59:53 +02:00
|
|
|
|
2018-07-20 22:20:45 +02:00
|
|
|
FooR->addDependencies({{&V, {Foo}}});
|
2018-06-17 18:59:53 +02:00
|
|
|
FooR->resolve({{Foo, FooSym}});
|
|
|
|
FooR->finalize();
|
|
|
|
|
|
|
|
EXPECT_TRUE(FooReady)
|
|
|
|
<< "Self-dependency prevented symbol from being marked ready";
|
|
|
|
}
|
|
|
|
|
2018-07-11 05:09:36 +02:00
|
|
|
TEST_F(CoreAPIsStandardTest, TestCircularDependenceInOneVSO) {
|
|
|
|
// Test that a circular symbol dependency between three symbols in a VSO does
|
|
|
|
// not prevent any symbol from becoming 'ready' once all symbols are
|
|
|
|
// finalized.
|
2018-05-17 00:24:30 +02:00
|
|
|
|
2018-07-11 05:09:36 +02:00
|
|
|
// Create three MaterializationResponsibility objects: one for each of Foo,
|
|
|
|
// Bar and Baz. These are optional because MaterializationResponsibility
|
|
|
|
// does not have a default constructor).
|
2018-05-17 00:24:30 +02:00
|
|
|
Optional<MaterializationResponsibility> FooR;
|
|
|
|
Optional<MaterializationResponsibility> BarR;
|
|
|
|
Optional<MaterializationResponsibility> BazR;
|
|
|
|
|
|
|
|
// Create a MaterializationUnit for each symbol that moves the
|
|
|
|
// MaterializationResponsibility into one of the locals above.
|
|
|
|
auto FooMU = llvm::make_unique<SimpleMaterializationUnit>(
|
2018-07-11 05:09:36 +02:00
|
|
|
SymbolFlagsMap({{Foo, FooSym.getFlags()}}),
|
2018-05-17 00:24:30 +02:00
|
|
|
[&](MaterializationResponsibility R) { FooR.emplace(std::move(R)); });
|
|
|
|
|
|
|
|
auto BarMU = llvm::make_unique<SimpleMaterializationUnit>(
|
2018-07-11 05:09:36 +02:00
|
|
|
SymbolFlagsMap({{Bar, BarSym.getFlags()}}),
|
2018-05-17 00:24:30 +02:00
|
|
|
[&](MaterializationResponsibility R) { BarR.emplace(std::move(R)); });
|
|
|
|
|
|
|
|
auto BazMU = llvm::make_unique<SimpleMaterializationUnit>(
|
2018-07-11 05:09:36 +02:00
|
|
|
SymbolFlagsMap({{Baz, BazSym.getFlags()}}),
|
2018-05-17 00:24:30 +02:00
|
|
|
[&](MaterializationResponsibility R) { BazR.emplace(std::move(R)); });
|
|
|
|
|
|
|
|
// Define the symbols.
|
|
|
|
cantFail(V.define(FooMU));
|
|
|
|
cantFail(V.define(BarMU));
|
|
|
|
cantFail(V.define(BazMU));
|
|
|
|
|
|
|
|
// Query each of the symbols to trigger materialization.
|
|
|
|
bool FooResolved = false;
|
|
|
|
bool FooReady = false;
|
2018-07-20 22:20:45 +02:00
|
|
|
auto FooQ = std::make_shared<AsynchronousSymbolQuery>(
|
|
|
|
SymbolNameSet({Foo}),
|
|
|
|
[&](Expected<AsynchronousSymbolQuery::ResolutionResult> RR) {
|
|
|
|
cantFail(std::move(RR));
|
|
|
|
FooResolved = true;
|
|
|
|
},
|
|
|
|
[&](Error Err) {
|
|
|
|
cantFail(std::move(Err));
|
|
|
|
FooReady = true;
|
|
|
|
});
|
|
|
|
{
|
|
|
|
auto Unresolved = V.lookup(FooQ, {Foo});
|
|
|
|
EXPECT_TRUE(Unresolved.empty()) << "Failed to resolve \"Foo\"";
|
|
|
|
}
|
2018-05-17 00:24:30 +02:00
|
|
|
|
|
|
|
bool BarResolved = false;
|
|
|
|
bool BarReady = false;
|
2018-07-20 22:20:45 +02:00
|
|
|
auto BarQ = std::make_shared<AsynchronousSymbolQuery>(
|
|
|
|
SymbolNameSet({Bar}),
|
|
|
|
[&](Expected<AsynchronousSymbolQuery::ResolutionResult> RR) {
|
|
|
|
cantFail(std::move(RR));
|
|
|
|
BarResolved = true;
|
|
|
|
},
|
|
|
|
[&](Error Err) {
|
|
|
|
cantFail(std::move(Err));
|
|
|
|
BarReady = true;
|
|
|
|
});
|
|
|
|
{
|
|
|
|
auto Unresolved = V.lookup(BarQ, {Bar});
|
|
|
|
EXPECT_TRUE(Unresolved.empty()) << "Failed to resolve \"Bar\"";
|
|
|
|
}
|
2018-05-17 00:24:30 +02:00
|
|
|
|
|
|
|
bool BazResolved = false;
|
|
|
|
bool BazReady = false;
|
2018-07-20 22:20:45 +02:00
|
|
|
auto BazQ = std::make_shared<AsynchronousSymbolQuery>(
|
|
|
|
SymbolNameSet({Baz}),
|
|
|
|
[&](Expected<AsynchronousSymbolQuery::ResolutionResult> RR) {
|
|
|
|
cantFail(std::move(RR));
|
|
|
|
BazResolved = true;
|
|
|
|
},
|
|
|
|
[&](Error Err) {
|
|
|
|
cantFail(std::move(Err));
|
|
|
|
BazReady = true;
|
|
|
|
});
|
|
|
|
{
|
|
|
|
auto Unresolved = V.lookup(BazQ, {Baz});
|
|
|
|
EXPECT_TRUE(Unresolved.empty()) << "Failed to resolve \"Baz\"";
|
|
|
|
}
|
2018-05-17 00:24:30 +02:00
|
|
|
|
2018-06-14 17:32:59 +02:00
|
|
|
// Add a circular dependency: Foo -> Bar, Bar -> Baz, Baz -> Foo.
|
2018-05-17 00:24:30 +02:00
|
|
|
FooR->addDependencies({{&V, SymbolNameSet({Bar})}});
|
|
|
|
BarR->addDependencies({{&V, SymbolNameSet({Baz})}});
|
|
|
|
BazR->addDependencies({{&V, SymbolNameSet({Foo})}});
|
2018-06-14 17:32:59 +02:00
|
|
|
|
|
|
|
// Add self-dependencies for good measure. This tests that the implementation
|
|
|
|
// of addDependencies filters these out.
|
|
|
|
FooR->addDependencies({{&V, SymbolNameSet({Foo})}});
|
|
|
|
BarR->addDependencies({{&V, SymbolNameSet({Bar})}});
|
|
|
|
BazR->addDependencies({{&V, SymbolNameSet({Baz})}});
|
2018-05-17 00:24:30 +02:00
|
|
|
|
2018-07-11 05:09:36 +02:00
|
|
|
// Check that nothing has been resolved yet.
|
2018-05-17 00:24:30 +02:00
|
|
|
EXPECT_FALSE(FooResolved) << "\"Foo\" should not be resolved yet";
|
|
|
|
EXPECT_FALSE(BarResolved) << "\"Bar\" should not be resolved yet";
|
|
|
|
EXPECT_FALSE(BazResolved) << "\"Baz\" should not be resolved yet";
|
|
|
|
|
2018-07-11 05:09:36 +02:00
|
|
|
// Resolve the symbols (but do not finalized them).
|
2018-05-17 00:24:30 +02:00
|
|
|
FooR->resolve({{Foo, FooSym}});
|
|
|
|
BarR->resolve({{Bar, BarSym}});
|
|
|
|
BazR->resolve({{Baz, BazSym}});
|
|
|
|
|
2018-07-11 05:09:36 +02:00
|
|
|
// Verify that the symbols have been resolved, but are not ready yet.
|
2018-05-17 00:24:30 +02:00
|
|
|
EXPECT_TRUE(FooResolved) << "\"Foo\" should be resolved now";
|
|
|
|
EXPECT_TRUE(BarResolved) << "\"Bar\" should be resolved now";
|
|
|
|
EXPECT_TRUE(BazResolved) << "\"Baz\" should be resolved now";
|
|
|
|
|
|
|
|
EXPECT_FALSE(FooReady) << "\"Foo\" should not be ready yet";
|
|
|
|
EXPECT_FALSE(BarReady) << "\"Bar\" should not be ready yet";
|
|
|
|
EXPECT_FALSE(BazReady) << "\"Baz\" should not be ready yet";
|
|
|
|
|
2018-07-11 05:09:36 +02:00
|
|
|
// Finalize two of the symbols.
|
2018-05-17 00:24:30 +02:00
|
|
|
FooR->finalize();
|
|
|
|
BarR->finalize();
|
|
|
|
|
|
|
|
// Verify that nothing is ready until the circular dependence is resolved.
|
|
|
|
EXPECT_FALSE(FooReady) << "\"Foo\" still should not be ready";
|
|
|
|
EXPECT_FALSE(BarReady) << "\"Bar\" still should not be ready";
|
|
|
|
EXPECT_FALSE(BazReady) << "\"Baz\" still should not be ready";
|
|
|
|
|
2018-07-11 05:09:36 +02:00
|
|
|
// Finalize the last symbol.
|
2018-05-17 00:24:30 +02:00
|
|
|
BazR->finalize();
|
|
|
|
|
|
|
|
// Verify that everything becomes ready once the circular dependence resolved.
|
|
|
|
EXPECT_TRUE(FooReady) << "\"Foo\" should be ready now";
|
|
|
|
EXPECT_TRUE(BarReady) << "\"Bar\" should be ready now";
|
|
|
|
EXPECT_TRUE(BazReady) << "\"Baz\" should be ready now";
|
|
|
|
}
|
|
|
|
|
2018-07-11 05:09:36 +02:00
|
|
|
TEST_F(CoreAPIsStandardTest, DropMaterializerWhenEmpty) {
|
2018-04-12 20:35:08 +02:00
|
|
|
bool DestructorRun = false;
|
|
|
|
|
2018-07-11 05:09:36 +02:00
|
|
|
JITSymbolFlags WeakExported(JITSymbolFlags::Exported);
|
|
|
|
WeakExported |= JITSymbolFlags::Weak;
|
|
|
|
|
2018-04-12 20:35:08 +02:00
|
|
|
auto MU = llvm::make_unique<SimpleMaterializationUnit>(
|
2018-07-11 05:09:36 +02:00
|
|
|
SymbolFlagsMap({{Foo, WeakExported}, {Bar, WeakExported}}),
|
2018-04-16 20:05:24 +02:00
|
|
|
[](MaterializationResponsibility R) {
|
2018-04-12 20:35:08 +02:00
|
|
|
llvm_unreachable("Unexpected call to materialize");
|
|
|
|
},
|
2018-04-16 20:05:24 +02:00
|
|
|
[&](const VSO &V, SymbolStringPtr Name) {
|
2018-04-12 20:35:08 +02:00
|
|
|
EXPECT_TRUE(Name == Foo || Name == Bar)
|
|
|
|
<< "Discard of unexpected symbol?";
|
|
|
|
},
|
|
|
|
[&]() { DestructorRun = true; });
|
|
|
|
|
2018-05-17 00:24:30 +02:00
|
|
|
cantFail(V.define(MU));
|
2018-04-12 20:35:08 +02:00
|
|
|
|
2018-05-17 00:24:30 +02:00
|
|
|
cantFail(V.define(absoluteSymbols({{Foo, FooSym}})));
|
2018-04-12 20:35:08 +02:00
|
|
|
|
|
|
|
EXPECT_FALSE(DestructorRun)
|
|
|
|
<< "MaterializationUnit should not have been destroyed yet";
|
|
|
|
|
2018-05-17 00:24:30 +02:00
|
|
|
cantFail(V.define(absoluteSymbols({{Bar, BarSym}})));
|
2018-04-12 20:35:08 +02:00
|
|
|
|
|
|
|
EXPECT_TRUE(DestructorRun)
|
|
|
|
<< "MaterializationUnit should have been destroyed";
|
|
|
|
}
|
|
|
|
|
2018-07-11 05:09:36 +02:00
|
|
|
TEST_F(CoreAPIsStandardTest, AddAndMaterializeLazySymbol) {
|
2018-01-10 01:09:38 +01:00
|
|
|
bool FooMaterialized = false;
|
|
|
|
bool BarDiscarded = false;
|
|
|
|
|
2018-07-11 05:09:36 +02:00
|
|
|
JITSymbolFlags WeakExported(JITSymbolFlags::Exported);
|
|
|
|
WeakExported |= JITSymbolFlags::Weak;
|
2018-01-10 01:09:38 +01:00
|
|
|
|
2018-03-20 04:49:29 +01:00
|
|
|
auto MU = llvm::make_unique<SimpleMaterializationUnit>(
|
2018-07-11 05:09:36 +02:00
|
|
|
SymbolFlagsMap({{Foo, JITSymbolFlags::Exported}, {Bar, WeakExported}}),
|
2018-04-16 20:05:24 +02:00
|
|
|
[&](MaterializationResponsibility R) {
|
2018-03-20 04:49:29 +01:00
|
|
|
assert(BarDiscarded && "Bar should have been discarded by this point");
|
2018-07-11 05:09:36 +02:00
|
|
|
R.resolve(SymbolMap({{Foo, FooSym}}));
|
2018-04-16 20:05:24 +02:00
|
|
|
R.finalize();
|
2018-01-10 01:09:38 +01:00
|
|
|
FooMaterialized = true;
|
|
|
|
},
|
2018-04-16 20:05:24 +02:00
|
|
|
[&](const VSO &V, SymbolStringPtr Name) {
|
2018-01-10 01:09:38 +01:00
|
|
|
EXPECT_EQ(Name, Bar) << "Expected Name to be Bar";
|
|
|
|
BarDiscarded = true;
|
|
|
|
});
|
|
|
|
|
2018-05-17 00:24:30 +02:00
|
|
|
cantFail(V.define(MU));
|
2018-07-11 05:09:36 +02:00
|
|
|
cantFail(V.define(absoluteSymbols({{Bar, BarSym}})));
|
2018-01-10 01:09:38 +01:00
|
|
|
|
|
|
|
SymbolNameSet Names({Foo});
|
|
|
|
|
|
|
|
bool OnResolutionRun = false;
|
|
|
|
bool OnReadyRun = false;
|
|
|
|
|
2018-07-20 22:20:45 +02:00
|
|
|
auto OnResolution =
|
|
|
|
[&](Expected<AsynchronousSymbolQuery::ResolutionResult> Result) {
|
|
|
|
EXPECT_TRUE(!!Result) << "Resolution unexpectedly returned error";
|
|
|
|
auto I = Result->Symbols.find(Foo);
|
|
|
|
EXPECT_NE(I, Result->Symbols.end())
|
|
|
|
<< "Could not find symbol definition";
|
|
|
|
EXPECT_EQ(I->second.getAddress(), FooSym.getAddress())
|
|
|
|
<< "Resolution returned incorrect result";
|
|
|
|
OnResolutionRun = true;
|
|
|
|
};
|
2018-01-10 01:09:38 +01:00
|
|
|
|
|
|
|
auto OnReady = [&](Error Err) {
|
|
|
|
cantFail(std::move(Err));
|
|
|
|
OnReadyRun = true;
|
|
|
|
};
|
|
|
|
|
2018-07-20 22:20:45 +02:00
|
|
|
auto Q =
|
|
|
|
std::make_shared<AsynchronousSymbolQuery>(Names, OnResolution, OnReady);
|
2018-01-10 01:09:38 +01:00
|
|
|
|
2018-07-20 22:20:45 +02:00
|
|
|
auto Unresolved = V.lookup(std::move(Q), Names);
|
|
|
|
|
|
|
|
EXPECT_TRUE(Unresolved.empty()) << "Could not find Foo in dylib";
|
2018-01-10 01:09:38 +01:00
|
|
|
EXPECT_TRUE(FooMaterialized) << "Foo was not materialized";
|
|
|
|
EXPECT_TRUE(BarDiscarded) << "Bar was not discarded";
|
|
|
|
EXPECT_TRUE(OnResolutionRun) << "OnResolutionCallback was not run";
|
|
|
|
EXPECT_TRUE(OnReadyRun) << "OnReady was not run";
|
|
|
|
}
|
|
|
|
|
2018-07-11 05:09:36 +02:00
|
|
|
TEST_F(CoreAPIsStandardTest, DefineMaterializingSymbol) {
|
2018-05-17 00:24:30 +02:00
|
|
|
bool ExpectNoMoreMaterialization = false;
|
|
|
|
ES.setDispatchMaterialization(
|
|
|
|
[&](VSO &V, std::unique_ptr<MaterializationUnit> MU) {
|
|
|
|
if (ExpectNoMoreMaterialization)
|
|
|
|
ADD_FAILURE() << "Unexpected materialization";
|
|
|
|
MU->doMaterialize(V);
|
|
|
|
});
|
|
|
|
|
|
|
|
auto MU = llvm::make_unique<SimpleMaterializationUnit>(
|
|
|
|
SymbolFlagsMap({{Foo, FooSym.getFlags()}}),
|
|
|
|
[&](MaterializationResponsibility R) {
|
|
|
|
cantFail(
|
|
|
|
R.defineMaterializing(SymbolFlagsMap({{Bar, BarSym.getFlags()}})));
|
|
|
|
R.resolve(SymbolMap({{Foo, FooSym}, {Bar, BarSym}}));
|
|
|
|
R.finalize();
|
|
|
|
});
|
|
|
|
|
|
|
|
cantFail(V.define(MU));
|
2018-07-11 05:09:36 +02:00
|
|
|
cantFail(lookup({&V}, Foo));
|
2018-05-17 00:24:30 +02:00
|
|
|
|
2018-07-11 05:09:36 +02:00
|
|
|
// Assert that materialization is complete by now.
|
2018-05-17 00:24:30 +02:00
|
|
|
ExpectNoMoreMaterialization = true;
|
|
|
|
|
2018-07-11 05:09:36 +02:00
|
|
|
// Look up bar to verify that no further materialization happens.
|
|
|
|
auto BarResult = cantFail(lookup({&V}, Bar));
|
|
|
|
EXPECT_EQ(BarResult.getAddress(), BarSym.getAddress())
|
|
|
|
<< "Expected Bar == BarSym";
|
2018-05-17 00:24:30 +02:00
|
|
|
}
|
|
|
|
|
2018-07-11 05:09:36 +02:00
|
|
|
TEST_F(CoreAPIsStandardTest, FallbackDefinitionGeneratorTest) {
|
2018-06-12 22:43:18 +02:00
|
|
|
cantFail(V.define(absoluteSymbols({{Foo, FooSym}})));
|
|
|
|
|
|
|
|
V.setFallbackDefinitionGenerator([&](VSO &W, const SymbolNameSet &Names) {
|
|
|
|
cantFail(W.define(absoluteSymbols({{Bar, BarSym}})));
|
|
|
|
return SymbolNameSet({Bar});
|
|
|
|
});
|
|
|
|
|
|
|
|
auto Result = cantFail(lookup({&V}, {Foo, Bar}));
|
|
|
|
|
|
|
|
EXPECT_EQ(Result.count(Bar), 1U) << "Expected to find fallback def for 'bar'";
|
2018-07-11 05:09:36 +02:00
|
|
|
EXPECT_EQ(Result[Bar].getAddress(), BarSym.getAddress())
|
|
|
|
<< "Expected fallback def for Bar to be equal to BarSym";
|
2018-06-12 22:43:18 +02:00
|
|
|
}
|
|
|
|
|
2018-07-11 05:09:36 +02:00
|
|
|
TEST_F(CoreAPIsStandardTest, FailResolution) {
|
2018-04-12 20:35:08 +02:00
|
|
|
auto MU = llvm::make_unique<SimpleMaterializationUnit>(
|
2018-05-17 00:24:30 +02:00
|
|
|
SymbolFlagsMap(
|
|
|
|
{{Foo, JITSymbolFlags::Weak}, {Bar, JITSymbolFlags::Weak}}),
|
2018-05-17 22:48:58 +02:00
|
|
|
[&](MaterializationResponsibility R) { R.failMaterialization(); });
|
2018-04-12 20:35:08 +02:00
|
|
|
|
2018-05-17 00:24:30 +02:00
|
|
|
cantFail(V.define(MU));
|
2018-04-12 20:35:08 +02:00
|
|
|
|
2018-07-11 05:09:36 +02:00
|
|
|
SymbolNameSet Names({Foo, Bar});
|
|
|
|
auto Result = lookup({&V}, Names);
|
|
|
|
|
|
|
|
EXPECT_FALSE(!!Result) << "Expected failure";
|
|
|
|
if (!Result) {
|
|
|
|
handleAllErrors(Result.takeError(),
|
|
|
|
[&](FailedToMaterialize &F) {
|
|
|
|
EXPECT_EQ(F.getSymbols(), Names)
|
|
|
|
<< "Expected to fail on symbols in Names";
|
|
|
|
},
|
|
|
|
[](ErrorInfoBase &EIB) {
|
|
|
|
std::string ErrMsg;
|
|
|
|
{
|
|
|
|
raw_string_ostream ErrOut(ErrMsg);
|
|
|
|
EIB.log(ErrOut);
|
|
|
|
}
|
|
|
|
ADD_FAILURE()
|
|
|
|
<< "Expected a FailedToResolve error. Got:\n"
|
|
|
|
<< ErrMsg;
|
|
|
|
});
|
|
|
|
}
|
2018-04-12 20:35:08 +02:00
|
|
|
}
|
|
|
|
|
2018-07-11 05:09:36 +02:00
|
|
|
TEST_F(CoreAPIsStandardTest, TestLookupWithUnthreadedMaterialization) {
|
2018-03-20 04:49:29 +01:00
|
|
|
auto MU = llvm::make_unique<SimpleMaterializationUnit>(
|
2018-05-17 00:24:30 +02:00
|
|
|
SymbolFlagsMap({{Foo, JITSymbolFlags::Exported}}),
|
2018-04-16 20:05:24 +02:00
|
|
|
[&](MaterializationResponsibility R) {
|
|
|
|
R.resolve({{Foo, FooSym}});
|
|
|
|
R.finalize();
|
2018-03-14 05:18:04 +01:00
|
|
|
});
|
|
|
|
|
2018-05-17 00:24:30 +02:00
|
|
|
cantFail(V.define(MU));
|
2018-03-14 05:18:04 +01:00
|
|
|
|
2018-05-21 23:11:21 +02:00
|
|
|
auto FooLookupResult = cantFail(lookup({&V}, Foo));
|
2018-03-14 05:18:04 +01:00
|
|
|
|
|
|
|
EXPECT_EQ(FooLookupResult.getAddress(), FooSym.getAddress())
|
|
|
|
<< "lookup returned an incorrect address";
|
|
|
|
EXPECT_EQ(FooLookupResult.getFlags(), FooSym.getFlags())
|
|
|
|
<< "lookup returned incorrect flags";
|
|
|
|
}
|
|
|
|
|
2018-07-11 05:09:36 +02:00
|
|
|
TEST_F(CoreAPIsStandardTest, TestLookupWithThreadedMaterialization) {
|
2018-03-14 05:18:04 +01:00
|
|
|
#if LLVM_ENABLE_THREADS
|
|
|
|
|
2018-05-17 00:24:30 +02:00
|
|
|
std::thread MaterializationThread;
|
|
|
|
ES.setDispatchMaterialization(
|
|
|
|
[&](VSO &V, std::unique_ptr<MaterializationUnit> MU) {
|
|
|
|
auto SharedMU = std::shared_ptr<MaterializationUnit>(std::move(MU));
|
|
|
|
MaterializationThread =
|
|
|
|
std::thread([SharedMU, &V]() { SharedMU->doMaterialize(V); });
|
2018-03-14 05:18:04 +01:00
|
|
|
});
|
|
|
|
|
2018-05-17 00:24:30 +02:00
|
|
|
cantFail(V.define(absoluteSymbols({{Foo, FooSym}})));
|
2018-03-14 05:18:04 +01:00
|
|
|
|
2018-05-21 23:11:21 +02:00
|
|
|
auto FooLookupResult = cantFail(lookup({&V}, Foo));
|
2018-03-14 05:18:04 +01:00
|
|
|
|
|
|
|
EXPECT_EQ(FooLookupResult.getAddress(), FooSym.getAddress())
|
|
|
|
<< "lookup returned an incorrect address";
|
|
|
|
EXPECT_EQ(FooLookupResult.getFlags(), FooSym.getFlags())
|
|
|
|
<< "lookup returned incorrect flags";
|
2018-03-23 11:14:19 +01:00
|
|
|
MaterializationThread.join();
|
2018-03-14 05:18:04 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-07-11 05:09:36 +02:00
|
|
|
TEST_F(CoreAPIsStandardTest, TestGetRequestedSymbolsAndReplace) {
|
|
|
|
// Test that GetRequestedSymbols returns the set of symbols that currently
|
|
|
|
// have pending queries, and test that MaterializationResponsibility's
|
|
|
|
// replace method can be used to return definitions to the VSO in a new
|
|
|
|
// MaterializationUnit.
|
2018-05-31 21:29:03 +02:00
|
|
|
SymbolNameSet Names({Foo, Bar});
|
|
|
|
|
|
|
|
bool FooMaterialized = false;
|
|
|
|
bool BarMaterialized = false;
|
|
|
|
|
|
|
|
auto MU = llvm::make_unique<SimpleMaterializationUnit>(
|
|
|
|
SymbolFlagsMap({{Foo, FooSym.getFlags()}, {Bar, BarSym.getFlags()}}),
|
|
|
|
[&](MaterializationResponsibility R) {
|
|
|
|
auto Requested = R.getRequestedSymbols();
|
|
|
|
EXPECT_EQ(Requested.size(), 1U) << "Expected one symbol requested";
|
|
|
|
EXPECT_EQ(*Requested.begin(), Foo) << "Expected \"Foo\" requested";
|
|
|
|
|
|
|
|
auto NewMU = llvm::make_unique<SimpleMaterializationUnit>(
|
|
|
|
SymbolFlagsMap({{Bar, BarSym.getFlags()}}),
|
|
|
|
[&](MaterializationResponsibility R2) {
|
|
|
|
R2.resolve(SymbolMap({{Bar, BarSym}}));
|
|
|
|
R2.finalize();
|
|
|
|
BarMaterialized = true;
|
|
|
|
});
|
|
|
|
|
2018-07-09 22:54:36 +02:00
|
|
|
R.replace(std::move(NewMU));
|
2018-05-31 21:29:03 +02:00
|
|
|
|
|
|
|
R.resolve(SymbolMap({{Foo, FooSym}}));
|
|
|
|
R.finalize();
|
|
|
|
|
|
|
|
FooMaterialized = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
cantFail(V.define(MU));
|
|
|
|
|
|
|
|
EXPECT_FALSE(FooMaterialized) << "Foo should not be materialized yet";
|
|
|
|
EXPECT_FALSE(BarMaterialized) << "Bar should not be materialized yet";
|
|
|
|
|
|
|
|
auto FooSymResult = cantFail(lookup({&V}, Foo));
|
|
|
|
EXPECT_EQ(FooSymResult.getAddress(), FooSym.getAddress())
|
|
|
|
<< "Address mismatch for Foo";
|
|
|
|
|
|
|
|
EXPECT_TRUE(FooMaterialized) << "Foo should be materialized now";
|
|
|
|
EXPECT_FALSE(BarMaterialized) << "Bar still should not be materialized";
|
|
|
|
|
|
|
|
auto BarSymResult = cantFail(lookup({&V}, Bar));
|
|
|
|
EXPECT_EQ(BarSymResult.getAddress(), BarSym.getAddress())
|
|
|
|
<< "Address mismatch for Bar";
|
|
|
|
EXPECT_TRUE(BarMaterialized) << "Bar should be materialized now";
|
|
|
|
}
|
|
|
|
|
2018-07-11 05:09:36 +02:00
|
|
|
TEST_F(CoreAPIsStandardTest, TestMaterializationResponsibilityDelegation) {
|
2018-07-09 22:54:36 +02:00
|
|
|
auto MU = llvm::make_unique<SimpleMaterializationUnit>(
|
|
|
|
SymbolFlagsMap({{Foo, FooSym.getFlags()}, {Bar, BarSym.getFlags()}}),
|
|
|
|
[&](MaterializationResponsibility R) {
|
|
|
|
auto R2 = R.delegate({Bar});
|
|
|
|
|
|
|
|
R.resolve({{Foo, FooSym}});
|
|
|
|
R.finalize();
|
|
|
|
R2.resolve({{Bar, BarSym}});
|
|
|
|
R2.finalize();
|
|
|
|
});
|
|
|
|
|
|
|
|
cantFail(V.define(MU));
|
|
|
|
|
|
|
|
auto Result = lookup({&V}, {Foo, Bar});
|
|
|
|
|
|
|
|
EXPECT_TRUE(!!Result) << "Result should be a success value";
|
|
|
|
EXPECT_EQ(Result->count(Foo), 1U) << "\"Foo\" entry missing";
|
|
|
|
EXPECT_EQ(Result->count(Bar), 1U) << "\"Bar\" entry missing";
|
|
|
|
EXPECT_EQ((*Result)[Foo].getAddress(), FooSym.getAddress())
|
|
|
|
<< "Address mismatch for \"Foo\"";
|
|
|
|
EXPECT_EQ((*Result)[Bar].getAddress(), BarSym.getAddress())
|
|
|
|
<< "Address mismatch for \"Bar\"";
|
|
|
|
}
|
|
|
|
|
2018-07-11 05:09:36 +02:00
|
|
|
TEST_F(CoreAPIsStandardTest, TestMaterializeWeakSymbol) {
|
2018-06-14 23:16:29 +02:00
|
|
|
// Confirm that once a weak definition is selected for materialization it is
|
|
|
|
// treated as strong.
|
2018-07-11 05:09:36 +02:00
|
|
|
JITSymbolFlags WeakExported = JITSymbolFlags::Exported;
|
|
|
|
WeakExported &= JITSymbolFlags::Weak;
|
2018-06-14 23:16:29 +02:00
|
|
|
|
|
|
|
std::unique_ptr<MaterializationResponsibility> FooResponsibility;
|
|
|
|
auto MU = llvm::make_unique<SimpleMaterializationUnit>(
|
2018-07-11 05:09:36 +02:00
|
|
|
SymbolFlagsMap({{Foo, FooSym.getFlags()}}),
|
|
|
|
[&](MaterializationResponsibility R) {
|
2018-06-14 23:16:29 +02:00
|
|
|
FooResponsibility =
|
|
|
|
llvm::make_unique<MaterializationResponsibility>(std::move(R));
|
|
|
|
});
|
|
|
|
|
|
|
|
cantFail(V.define(MU));
|
2018-07-20 22:20:45 +02:00
|
|
|
auto Q = std::make_shared<AsynchronousSymbolQuery>(
|
|
|
|
SymbolNameSet({Foo}),
|
|
|
|
[](Expected<AsynchronousSymbolQuery::ResolutionResult> R) {
|
|
|
|
cantFail(std::move(R));
|
|
|
|
},
|
|
|
|
[](Error Err) { cantFail(std::move(Err)); });
|
|
|
|
V.lookup(std::move(Q), SymbolNameSet({Foo}));
|
2018-06-14 23:16:29 +02:00
|
|
|
|
|
|
|
auto MU2 = llvm::make_unique<SimpleMaterializationUnit>(
|
|
|
|
SymbolFlagsMap({{Foo, JITSymbolFlags::Exported}}),
|
|
|
|
[](MaterializationResponsibility R) {
|
|
|
|
llvm_unreachable("This unit should never be materialized");
|
|
|
|
});
|
|
|
|
|
|
|
|
auto Err = V.define(MU2);
|
|
|
|
EXPECT_TRUE(!!Err) << "Expected failure value";
|
|
|
|
EXPECT_TRUE(Err.isA<DuplicateDefinition>())
|
|
|
|
<< "Expected a duplicate definition error";
|
|
|
|
consumeError(std::move(Err));
|
|
|
|
|
|
|
|
FooResponsibility->resolve(SymbolMap({{Foo, FooSym}}));
|
|
|
|
FooResponsibility->finalize();
|
|
|
|
}
|
|
|
|
|
2018-01-10 01:09:38 +01:00
|
|
|
} // namespace
|