Skip to content

Commit e3c8408

Browse files
committed
[llvm-jitlink] Apply symbol scope modifiers explicitly for -hidden-lx.
We had been abusing the setOverrideObjectFlagsWithResponsibilityFlags method to do this. Handling it explicitly ensures that flags are only modified on the intended files, and not accedintally modified elsewhere.
1 parent fd5d1cb commit e3c8408

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

llvm/tools/llvm-jitlink/llvm-jitlink.cpp

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,23 @@ bool lazyLinkingRequested() {
427427
return false;
428428
}
429429

430+
static Error applyLibraryLinkModifiers(Session &S, LinkGraph &G) {
431+
// If there are hidden archives and this graph is an archive
432+
// member then apply hidden modifier.
433+
if (!S.HiddenArchives.empty()) {
434+
StringRef ObjName(G.getName());
435+
if (ObjName.ends_with(')')) {
436+
auto LibName = ObjName.split('(').first;
437+
if (S.HiddenArchives.count(LibName)) {
438+
for (auto *Sym : G.defined_symbols())
439+
Sym->setScope(std::max(Sym->getScope(), Scope::Hidden));
440+
}
441+
}
442+
}
443+
444+
return Error::success();
445+
}
446+
430447
static Error applyHarnessPromotions(Session &S, LinkGraph &G) {
431448
std::lock_guard<std::mutex> Lock(S.M);
432449

@@ -1328,6 +1345,8 @@ void Session::modifyPassConfig(LinkGraph &G, PassConfiguration &PassConfig) {
13281345
++ActiveLinks;
13291346
return Error::success();
13301347
});
1348+
PassConfig.PrePrunePasses.push_back(
1349+
[this](LinkGraph &G) { return applyLibraryLinkModifiers(*this, G); });
13311350
PassConfig.PrePrunePasses.push_back(
13321351
[this](LinkGraph &G) { return applyHarnessPromotions(*this, G); });
13331352

@@ -2182,11 +2201,6 @@ static Error addLibraries(Session &S,
21822201
LibraryLoadQueue.push_back(std::move(LL));
21832202
}
21842203

2185-
// If there are any load-<modified> options then turn on flag overrides
2186-
// to avoid flag mismatch errors.
2187-
if (!LibrariesHidden.empty() || !LoadHidden.empty())
2188-
S.ObjLayer.setOverrideObjectFlagsWithResponsibilityFlags(true);
2189-
21902204
// Sort library loads by position in the argument list.
21912205
llvm::sort(LibraryLoadQueue,
21922206
[](const LibraryLoad &LHS, const LibraryLoad &RHS) {
@@ -2204,6 +2218,7 @@ static Error addLibraries(Session &S,
22042218
break;
22052219
case LibraryLoad::Hidden:
22062220
GetObjFileInterface = getObjectFileInterfaceHidden;
2221+
S.HiddenArchives.insert(Path);
22072222
break;
22082223
}
22092224

llvm/tools/llvm-jitlink/llvm-jitlink.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ struct Session {
136136
StringSet<> HarnessDefinitions;
137137
DenseMap<StringRef, StringRef> CanonicalWeakDefs;
138138

139+
StringSet<> HiddenArchives;
140+
139141
std::optional<Regex> ShowGraphsRegex;
140142

141143
private:

0 commit comments

Comments
 (0)