Re-apply "[llvm-jitlink] Don't demote unreferenced definitions in -harness mode"

This reapplies commit e137b55058 with
fixes for the broken test case: Non-global symbols should only be
skipped after checking that they're not referenced by the harness.
This commit is contained in:
Lang Hames 2020-08-13 12:25:05 -07:00
parent 5ef2287d36
commit f136e5ecfb
1 changed files with 4 additions and 9 deletions

View File

@ -187,7 +187,7 @@ static Error applyHarnessPromotions(Session &S, LinkGraph &G) {
// If this graph is part of the test then promote any symbols referenced by
// the harness to default scope, remove all symbols that clash with harness
// definitions, demote all other definitions.
// definitions.
std::vector<Symbol *> DefinitionsToRemove;
for (auto *Sym : G.defined_symbols()) {
@ -219,10 +219,6 @@ static Error applyHarnessPromotions(Session &S, LinkGraph &G) {
} else if (S.HarnessDefinitions.count(Sym->getName())) {
LLVM_DEBUG(dbgs() << " Externalizing " << Sym->getName() << "\n");
DefinitionsToRemove.push_back(Sym);
} else {
LLVM_DEBUG(dbgs() << " Demoting " << Sym->getName() << "\n");
Sym->setScope(Scope::Local);
Sym->setLive(false);
}
}
@ -521,7 +517,7 @@ Error LLVMJITLinkObjectLinkingLayer::add(JITDylib &JD,
return SymFlagsOrErr.takeError();
// Skip symbols not defined in this object file.
if (*SymFlagsOrErr & object::BasicSymbolRef::SF_Undefined)
if ((*SymFlagsOrErr & object::BasicSymbolRef::SF_Undefined))
continue;
auto Name = Sym.getName();
@ -551,10 +547,9 @@ Error LLVMJITLinkObjectLinkingLayer::add(JITDylib &JD,
*SymFlags &= ~JITSymbolFlags::Exported;
} else if (S.HarnessExternals.count(*Name)) {
*SymFlags |= JITSymbolFlags::Exported;
} else {
// Skip symbols that aren't in the HarnessExternals set.
} else if (S.HarnessDefinitions.count(*Name) ||
!(*SymFlagsOrErr & object::BasicSymbolRef::SF_Global))
continue;
}
auto InternedName = S.ES.intern(*Name);
SymbolFlags[InternedName] = std::move(*SymFlags);