diff options
Diffstat (limited to 'llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp')
-rw-r--r-- | llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp | 56 |
1 files changed, 22 insertions, 34 deletions
diff --git a/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp b/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp index 5ddb35cbafd5..2b11c472e812 100644 --- a/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp +++ b/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp @@ -7,9 +7,9 @@ //===----------------------------------------------------------------------===// #include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h" -#include "llvm/ADT/Optional.h" #include "llvm/ExecutionEngine/JITLink/EHFrameSupport.h" #include "llvm/ExecutionEngine/Orc/DebugObjectManagerPlugin.h" +#include "llvm/ExecutionEngine/Orc/ObjectFileInterface.h" #include "llvm/Support/MemoryBuffer.h" #include <string> #include <vector> @@ -58,35 +58,12 @@ private: LGI.SymbolFlags[ES.intern(Sym->getName())] = Flags; } - if ((G.getTargetTriple().isOSBinFormatMachO() && hasMachOInitSection(G)) || - (G.getTargetTriple().isOSBinFormatELF() && hasELFInitSection(G))) + if (hasInitializerSection(G)) LGI.InitSymbol = makeInitSymbol(ES, G); return LGI; } - static bool hasMachOInitSection(LinkGraph &G) { - for (auto &Sec : G.sections()) - if (Sec.getName() == "__DATA,__obj_selrefs" || - Sec.getName() == "__DATA,__objc_classlist" || - Sec.getName() == "__TEXT,__swift5_protos" || - Sec.getName() == "__TEXT,__swift5_proto" || - Sec.getName() == "__TEXT,__swift5_types" || - Sec.getName() == "__DATA,__mod_init_func") - return true; - return false; - } - - static bool hasELFInitSection(LinkGraph &G) { - for (auto &Sec : G.sections()) { - auto SecName = Sec.getName(); - if (SecName.consume_front(".init_array") && - (SecName.empty() || SecName[0] == '.')) - return true; - } - return false; - } - static SymbolStringPtr makeInitSymbol(ExecutionSession &ES, LinkGraph &G) { std::string InitSymString; raw_string_ostream(InitSymString) @@ -218,6 +195,8 @@ public: Flags |= JITSymbolFlags::Callable; if (Sym->getScope() == Scope::Default) Flags |= JITSymbolFlags::Exported; + if (Sym->getLinkage() == Linkage::Weak) + Flags |= JITSymbolFlags::Weak; InternedResult[InternedName] = JITEvaluatedSymbol(Sym->getAddress().getValue(), Flags); @@ -447,9 +426,15 @@ private: // 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)) + // Walk the list of symbols that we just tried to claim. Symbols that we're + // responsible for are marked live. Symbols that we're not responsible for + // are turned into external references. + for (auto &KV : NameToSym) { + if (MR->getSymbols().count(KV.first)) + KV.second->setLive(true); + else G.makeExternal(*KV.second); + } return Error::success(); } @@ -537,7 +522,8 @@ private: for (auto *B : G.blocks()) { auto &BI = BlockInfos[B]; for (auto &E : B->edges()) { - if (E.getTarget().getScope() == Scope::Local) { + if (E.getTarget().getScope() == Scope::Local && + !E.getTarget().isAbsolute()) { auto &TgtB = E.getTarget().getBlock(); if (&TgtB != B) { BI.Dependencies.insert(&TgtB); @@ -694,12 +680,12 @@ Error ObjectLinkingLayer::notifyEmitted(MaterializationResponsibility &MR, [&](ResourceKey K) { Allocs[K].push_back(std::move(FA)); }); } -Error ObjectLinkingLayer::handleRemoveResources(ResourceKey K) { +Error ObjectLinkingLayer::handleRemoveResources(JITDylib &JD, ResourceKey K) { { Error Err = Error::success(); for (auto &P : Plugins) - Err = joinErrors(std::move(Err), P->notifyRemovingResources(K)); + Err = joinErrors(std::move(Err), P->notifyRemovingResources(JD, K)); if (Err) return Err; } @@ -719,7 +705,8 @@ Error ObjectLinkingLayer::handleRemoveResources(ResourceKey K) { return MemMgr.deallocate(std::move(AllocsToRemove)); } -void ObjectLinkingLayer::handleTransferResources(ResourceKey DstKey, +void ObjectLinkingLayer::handleTransferResources(JITDylib &JD, + ResourceKey DstKey, ResourceKey SrcKey) { auto I = Allocs.find(SrcKey); if (I != Allocs.end()) { @@ -735,7 +722,7 @@ void ObjectLinkingLayer::handleTransferResources(ResourceKey DstKey, } for (auto &P : Plugins) - P->notifyTransferringResources(DstKey, SrcKey); + P->notifyTransferringResources(JD, DstKey, SrcKey); } EHFrameRegistrationPlugin::EHFrameRegistrationPlugin( @@ -787,7 +774,8 @@ Error EHFrameRegistrationPlugin::notifyFailed( return Error::success(); } -Error EHFrameRegistrationPlugin::notifyRemovingResources(ResourceKey K) { +Error EHFrameRegistrationPlugin::notifyRemovingResources(JITDylib &JD, + ResourceKey K) { std::vector<ExecutorAddrRange> RangesToRemove; ES.runSessionLocked([&] { @@ -811,7 +799,7 @@ Error EHFrameRegistrationPlugin::notifyRemovingResources(ResourceKey K) { } void EHFrameRegistrationPlugin::notifyTransferringResources( - ResourceKey DstKey, ResourceKey SrcKey) { + JITDylib &JD, ResourceKey DstKey, ResourceKey SrcKey) { auto SI = EHFrameRanges.find(SrcKey); if (SI == EHFrameRanges.end()) return; |