Skip to content

Commit 158a600

Browse files
committed
[llvm-jitlink] Wait for reachable files to link before running checks.
ORC dependence tracking is fine-grained (i.e. per-symbol), however when running -check mode we want to wait for all links triggered by the entry point lookup to complete, regardless of whether the code / data in them is actually reachable from the entry point. This simplifies test-cases, since authors don't need to reason about per-symbol dependencies to know that additional files will be linked (if referenced transitively in any way from the test-case). The new Session::waitForFilesLinkedFromEntryPointFile utility does _not_ wait for lazily linked (-lazy) files. This will be used to fix buildbot errors caused by edca1d9.
1 parent 5712e29 commit 158a600

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

Diff for: llvm/tools/llvm-jitlink/llvm-jitlink.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -1230,6 +1230,11 @@ void Session::modifyPassConfig(LinkGraph &G, PassConfiguration &PassConfig) {
12301230
return Error::success();
12311231
});
12321232

1233+
PassConfig.PrePrunePasses.push_back([this](LinkGraph &G) {
1234+
std::lock_guard<std::mutex> Lock(M);
1235+
++ActiveLinks;
1236+
return Error::success();
1237+
});
12331238
PassConfig.PrePrunePasses.push_back(
12341239
[this](LinkGraph &G) { return applyHarnessPromotions(*this, G); });
12351240

@@ -1242,6 +1247,13 @@ void Session::modifyPassConfig(LinkGraph &G, PassConfiguration &PassConfig) {
12421247

12431248
if (AddSelfRelocations)
12441249
PassConfig.PostPrunePasses.push_back(addSelfRelocations);
1250+
1251+
PassConfig.PostFixupPasses.push_back([this](LinkGraph &G) {
1252+
std::lock_guard<std::mutex> Lock(M);
1253+
if (--ActiveLinks == 0)
1254+
ActiveLinksCV.notify_all();
1255+
return Error::success();
1256+
});
12451257
}
12461258

12471259
Expected<JITDylib *> Session::getOrLoadDynamicLibrary(StringRef LibPath) {
@@ -2314,6 +2326,8 @@ static Error runChecks(Session &S, Triple TT, SubtargetFeatures Features) {
23142326
if (CheckFiles.empty())
23152327
return Error::success();
23162328

2329+
S.waitForFilesLinkedFromEntryPointFile();
2330+
23172331
LLVM_DEBUG(dbgs() << "Running checks...\n");
23182332

23192333
auto IsSymbolValid = [&S](StringRef Symbol) {

Diff for: llvm/tools/llvm-jitlink/llvm-jitlink.h

+13
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@ struct Session {
6161
void modifyPassConfig(jitlink::LinkGraph &G,
6262
jitlink::PassConfiguration &PassConfig);
6363

64+
/// For -check: wait for all files that are referenced (transitively) from
65+
/// the entry point *file* to be linked. (ORC's usual dependence tracking is
66+
/// to fine-grained here: a lookup of the main symbol will return as soon as
67+
/// all reachable symbols have been linked, but testcases may want to
68+
/// inspect side-effects in unreachable symbols)..
69+
void waitForFilesLinkedFromEntryPointFile() {
70+
std::unique_lock<std::mutex> Lock(M);
71+
return ActiveLinksCV.wait(Lock, [this]() { return ActiveLinks == 0; });
72+
}
73+
6474
using MemoryRegionInfo = RuntimeDyldChecker::MemoryRegionInfo;
6575

6676
struct FileInfo {
@@ -110,6 +120,9 @@ struct Session {
110120

111121
DynLibJDMap DynLibJDs;
112122

123+
std::mutex M;
124+
std::condition_variable ActiveLinksCV;
125+
size_t ActiveLinks = 0;
113126
SymbolInfoMap SymbolInfos;
114127
FileInfoMap FileInfos;
115128

0 commit comments

Comments
 (0)