mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-02-01 05:01:59 +01:00
[ORC] Attempt to auto-claim responsibility for weak defs in ObjectLinkingLayer.
Compilers may insert new definitions during compilation, E.g. EH personality function pointers, or named constant pool entries. This commit causes ObjectLinkingLayer to attempt to claim responsibility for all weak definitions in objects as they're linked. This is always safe (first claimant for each symbol is granted responsibility, subsequent claims are rejected without error) and prevents compiler-injected symbols from being dead-stripped (which they will be if they remain unclaimed by anyone). This change was motivated by errors seen by an out-of-tree client while testing eh-frame support in JITLink ELF/x86-64: IR containing exceptions didn't define DW.ref.__gxx_personality_v0 (since it's added by CodeGen), and this caused DW.ref.__gxx_personality_v0 to be dead-stripped leading to linker failures. No test case yet: We won't have a way to test in-tree until we enable JITLink for lli on Linux.
This commit is contained in:
parent
8bc0e661cd
commit
4a5753f9a7
@ -214,8 +214,9 @@ public:
|
||||
Error modifyPassConfig(const Triple &TT, PassConfiguration &Config) override {
|
||||
// Add passes to mark duplicate defs as should-discard, and to walk the
|
||||
// link graph to build the symbol dependence graph.
|
||||
Config.PrePrunePasses.push_back(
|
||||
[this](LinkGraph &G) { return externalizeWeakAndCommonSymbols(G); });
|
||||
Config.PrePrunePasses.push_back([this](LinkGraph &G) {
|
||||
return claimOrExternalizeWeakAndCommonSymbols(G);
|
||||
});
|
||||
|
||||
Layer.modifyPassConfig(*MR, TT, Config);
|
||||
|
||||
@ -233,19 +234,38 @@ private:
|
||||
using LocalSymbolNamedDependenciesMap =
|
||||
DenseMap<const Symbol *, LocalSymbolNamedDependencies>;
|
||||
|
||||
Error externalizeWeakAndCommonSymbols(LinkGraph &G) {
|
||||
Error claimOrExternalizeWeakAndCommonSymbols(LinkGraph &G) {
|
||||
auto &ES = Layer.getExecutionSession();
|
||||
for (auto *Sym : G.defined_symbols())
|
||||
if (Sym->hasName() && Sym->getLinkage() == Linkage::Weak) {
|
||||
if (!MR->getSymbols().count(ES.intern(Sym->getName())))
|
||||
G.makeExternal(*Sym);
|
||||
}
|
||||
|
||||
for (auto *Sym : G.absolute_symbols())
|
||||
SymbolFlagsMap NewSymbolsToClaim;
|
||||
std::vector<std::pair<SymbolStringPtr, Symbol *>> NameToSym;
|
||||
|
||||
auto ProcessSymbol = [&](Symbol *Sym) {
|
||||
if (Sym->hasName() && Sym->getLinkage() == Linkage::Weak) {
|
||||
if (!MR->getSymbols().count(ES.intern(Sym->getName())))
|
||||
G.makeExternal(*Sym);
|
||||
auto Name = ES.intern(Sym->getName());
|
||||
if (!MR->getSymbols().count(ES.intern(Sym->getName()))) {
|
||||
JITSymbolFlags SF = JITSymbolFlags::Weak;
|
||||
if (Sym->getScope() == Scope::Default)
|
||||
SF |= JITSymbolFlags::Exported;
|
||||
NewSymbolsToClaim[Name] = SF;
|
||||
NameToSym.push_back(std::make_pair(std::move(Name), Sym));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
for (auto *Sym : G.defined_symbols())
|
||||
ProcessSymbol(Sym);
|
||||
for (auto *Sym : G.absolute_symbols())
|
||||
ProcessSymbol(Sym);
|
||||
|
||||
// Attempt to claim all weak defs that we're not already responsible for.
|
||||
// This cannot fail -- any clashes will just result in rejection of our
|
||||
// claim, at which point we'll externalize that symbol.
|
||||
cantFail(MR->defineMaterializing(std::move(NewSymbolsToClaim)));
|
||||
|
||||
for (auto &KV : NameToSym)
|
||||
if (!MR->getSymbols().count(KV.first))
|
||||
G.makeExternal(*KV.second);
|
||||
|
||||
return Error::success();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user