diff --git a/llvm/include/llvm/ExecutionEngine/JITLink/COFF.h b/llvm/include/llvm/ExecutionEngine/JITLink/COFF.h --- a/llvm/include/llvm/ExecutionEngine/JITLink/COFF.h +++ b/llvm/include/llvm/ExecutionEngine/JITLink/COFF.h @@ -24,7 +24,8 @@ /// its contents. The caller is responsible for ensuring that the object buffer /// outlives the graph. Expected> -createLinkGraphFromCOFFObject(MemoryBufferRef ObjectBuffer); +createLinkGraphFromCOFFObject(MemoryBufferRef ObjectBuffer, + std::shared_ptr SSP); /// Link the given graph. /// diff --git a/llvm/include/llvm/ExecutionEngine/JITLink/COFF_x86_64.h b/llvm/include/llvm/ExecutionEngine/JITLink/COFF_x86_64.h --- a/llvm/include/llvm/ExecutionEngine/JITLink/COFF_x86_64.h +++ b/llvm/include/llvm/ExecutionEngine/JITLink/COFF_x86_64.h @@ -23,8 +23,8 @@ /// Note: The graph does not take ownership of the underlying buffer, nor copy /// its contents. The caller is responsible for ensuring that the object buffer /// outlives the graph. -Expected> -createLinkGraphFromCOFFObject_x86_64(MemoryBufferRef ObjectBuffer); +Expected> createLinkGraphFromCOFFObject_x86_64( + MemoryBufferRef ObjectBuffer, std::shared_ptr SSP); /// jit-link the given object buffer, which must be a COFF x86-64 object file. void link_COFF_x86_64(std::unique_ptr G, diff --git a/llvm/include/llvm/ExecutionEngine/JITLink/ELF.h b/llvm/include/llvm/ExecutionEngine/JITLink/ELF.h --- a/llvm/include/llvm/ExecutionEngine/JITLink/ELF.h +++ b/llvm/include/llvm/ExecutionEngine/JITLink/ELF.h @@ -24,7 +24,8 @@ /// its contents. The caller is responsible for ensuring that the object buffer /// outlives the graph. Expected> -createLinkGraphFromELFObject(MemoryBufferRef ObjectBuffer); +createLinkGraphFromELFObject(MemoryBufferRef ObjectBuffer, + std::shared_ptr SSP); /// Link the given graph. /// diff --git a/llvm/include/llvm/ExecutionEngine/JITLink/ELF_aarch32.h b/llvm/include/llvm/ExecutionEngine/JITLink/ELF_aarch32.h --- a/llvm/include/llvm/ExecutionEngine/JITLink/ELF_aarch32.h +++ b/llvm/include/llvm/ExecutionEngine/JITLink/ELF_aarch32.h @@ -24,8 +24,8 @@ /// Note: The graph does not take ownership of the underlying buffer, nor copy /// its contents. The caller is responsible for ensuring that the object buffer /// outlives the graph. -Expected> -createLinkGraphFromELFObject_aarch32(MemoryBufferRef ObjectBuffer); +Expected> createLinkGraphFromELFObject_aarch32( + MemoryBufferRef ObjectBuffer, std::shared_ptr SSP); /// jit-link the given object buffer, which must be an ELF arm/thumb object /// file. diff --git a/llvm/include/llvm/ExecutionEngine/JITLink/ELF_aarch64.h b/llvm/include/llvm/ExecutionEngine/JITLink/ELF_aarch64.h --- a/llvm/include/llvm/ExecutionEngine/JITLink/ELF_aarch64.h +++ b/llvm/include/llvm/ExecutionEngine/JITLink/ELF_aarch64.h @@ -25,8 +25,8 @@ /// Note: The graph does not take ownership of the underlying buffer, nor copy /// its contents. The caller is responsible for ensuring that the object buffer /// outlives the graph. -Expected> -createLinkGraphFromELFObject_aarch64(MemoryBufferRef ObjectBuffer); +Expected> createLinkGraphFromELFObject_aarch64( + MemoryBufferRef ObjectBuffer, std::shared_ptr SSP); /// jit-link the given object buffer, which must be a ELF aarch64 relocatable /// object file. diff --git a/llvm/include/llvm/ExecutionEngine/JITLink/ELF_i386.h b/llvm/include/llvm/ExecutionEngine/JITLink/ELF_i386.h --- a/llvm/include/llvm/ExecutionEngine/JITLink/ELF_i386.h +++ b/llvm/include/llvm/ExecutionEngine/JITLink/ELF_i386.h @@ -26,7 +26,8 @@ /// its contents. The caller is responsible for ensuring that the object buffer /// outlives the graph. Expected> -createLinkGraphFromELFObject_i386(MemoryBufferRef ObjectBuffer); +createLinkGraphFromELFObject_i386(MemoryBufferRef ObjectBuffer, + std::shared_ptr SSP); /// jit-link the given object buffer, which must be a ELF i386 relocatable /// object file. diff --git a/llvm/include/llvm/ExecutionEngine/JITLink/ELF_loongarch.h b/llvm/include/llvm/ExecutionEngine/JITLink/ELF_loongarch.h --- a/llvm/include/llvm/ExecutionEngine/JITLink/ELF_loongarch.h +++ b/llvm/include/llvm/ExecutionEngine/JITLink/ELF_loongarch.h @@ -25,8 +25,8 @@ /// Note: The graph does not take ownership of the underlying buffer, nor copy /// its contents. The caller is responsible for ensuring that the object buffer /// outlives the graph. -Expected> -createLinkGraphFromELFObject_loongarch(MemoryBufferRef ObjectBuffer); +Expected> createLinkGraphFromELFObject_loongarch( + MemoryBufferRef ObjectBuffer, std::shared_ptr SSP); /// jit-link the given object buffer, which must be an ELF loongarch object /// file. diff --git a/llvm/include/llvm/ExecutionEngine/JITLink/ELF_riscv.h b/llvm/include/llvm/ExecutionEngine/JITLink/ELF_riscv.h --- a/llvm/include/llvm/ExecutionEngine/JITLink/ELF_riscv.h +++ b/llvm/include/llvm/ExecutionEngine/JITLink/ELF_riscv.h @@ -26,7 +26,8 @@ /// its contents. The caller is responsible for ensuring that the object buffer /// outlives the graph. Expected> -createLinkGraphFromELFObject_riscv(MemoryBufferRef ObjectBuffer); +createLinkGraphFromELFObject_riscv(MemoryBufferRef ObjectBuffer, + std::shared_ptr SSP); /// jit-link the given object buffer, which must be a ELF riscv object file. void link_ELF_riscv(std::unique_ptr G, diff --git a/llvm/include/llvm/ExecutionEngine/JITLink/ELF_x86_64.h b/llvm/include/llvm/ExecutionEngine/JITLink/ELF_x86_64.h --- a/llvm/include/llvm/ExecutionEngine/JITLink/ELF_x86_64.h +++ b/llvm/include/llvm/ExecutionEngine/JITLink/ELF_x86_64.h @@ -24,7 +24,8 @@ /// its contents. The caller is responsible for ensuring that the object buffer /// outlives the graph. Expected> -createLinkGraphFromELFObject_x86_64(MemoryBufferRef ObjectBuffer); +createLinkGraphFromELFObject_x86_64(MemoryBufferRef ObjectBuffe, + std::shared_ptr SSP); /// jit-link the given object buffer, which must be a ELF x86-64 object file. void link_ELF_x86_64(std::unique_ptr G, diff --git a/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h b/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h --- a/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h +++ b/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h @@ -21,6 +21,7 @@ #include "llvm/ExecutionEngine/Orc/Shared/ExecutorAddress.h" #include "llvm/ExecutionEngine/Orc/Shared/ExecutorSymbolDef.h" #include "llvm/ExecutionEngine/Orc/Shared/MemoryFlags.h" +#include "llvm/ExecutionEngine/Orc/SymbolStringPool.h" #include "llvm/Support/Allocator.h" #include "llvm/Support/BinaryStreamReader.h" #include "llvm/Support/BinaryStreamWriter.h" @@ -413,10 +414,11 @@ friend class LinkGraph; private: - Symbol(Addressable &Base, orc::ExecutorAddrDiff Offset, StringRef Name, - orc::ExecutorAddrDiff Size, Linkage L, Scope S, bool IsLive, - bool IsCallable) - : Name(Name), Base(&Base), Offset(Offset), WeakRef(0), Size(Size) { + Symbol(Addressable &Base, orc::ExecutorAddrDiff Offset, + orc::SymbolStringPtr &&Name, orc::ExecutorAddrDiff Size, Linkage L, + Scope S, bool IsLive, bool IsCallable) + : Name(std::move(Name)), Base(&Base), Offset(Offset), WeakRef(0), + Size(Size) { assert(Offset <= MaxOffset && "Offset out of range"); setLinkage(L); setScope(S); @@ -425,27 +427,45 @@ setTargetFlags(TargetFlagsType{}); } + static Symbol &constructCommon(BumpPtrAllocator &Allocator, Block &Base, + orc::SymbolStringPtr &&Name, + orc::ExecutorAddrDiff Size, Scope S, + bool IsLive) { + assert(Name && "Common symbol name cannot be empty"); + assert(Base.isDefined() && + "Cannot create common symbol from undefined block"); + assert(static_cast(Base).getSize() == Size && + "Common symbol size should match underlying block size"); + auto *Sym = Allocator.Allocate(); + new (Sym) + Symbol(Base, 0, std::move(Name), Size, Linkage::Weak, S, IsLive, false); + return *Sym; + } + static Symbol &constructExternal(BumpPtrAllocator &Allocator, - Addressable &Base, StringRef Name, + Addressable &Base, + orc::SymbolStringPtr &&Name, orc::ExecutorAddrDiff Size, Linkage L, bool WeaklyReferenced) { assert(!Base.isDefined() && "Cannot create external symbol from defined block"); - assert(!Name.empty() && "External symbol name cannot be empty"); + assert(Name && "External symbol name cannot be empty"); auto *Sym = Allocator.Allocate(); - new (Sym) Symbol(Base, 0, Name, Size, L, Scope::Default, false, false); + new (Sym) + Symbol(Base, 0, std::move(Name), Size, L, Scope::Default, false, false); Sym->setWeaklyReferenced(WeaklyReferenced); return *Sym; } static Symbol &constructAbsolute(BumpPtrAllocator &Allocator, - Addressable &Base, StringRef Name, + Addressable &Base, + orc::SymbolStringPtr &&Name, orc::ExecutorAddrDiff Size, Linkage L, Scope S, bool IsLive) { assert(!Base.isDefined() && "Cannot create absolute symbol from a defined block"); auto *Sym = Allocator.Allocate(); - new (Sym) Symbol(Base, 0, Name, Size, L, S, IsLive, false); + new (Sym) Symbol(Base, 0, std::move(Name), Size, L, S, IsLive, false); return *Sym; } @@ -456,20 +476,22 @@ assert((Offset + Size) <= Base.getSize() && "Symbol extends past end of block"); auto *Sym = Allocator.Allocate(); - new (Sym) Symbol(Base, Offset, StringRef(), Size, Linkage::Strong, - Scope::Local, IsLive, IsCallable); + new (Sym) Symbol(Base, Offset, orc::SymbolStringPtr(nullptr), Size, + Linkage::Strong, Scope::Local, IsLive, IsCallable); return *Sym; } static Symbol &constructNamedDef(BumpPtrAllocator &Allocator, Block &Base, - orc::ExecutorAddrDiff Offset, StringRef Name, + orc::ExecutorAddrDiff Offset, + orc::SymbolStringPtr Name, orc::ExecutorAddrDiff Size, Linkage L, Scope S, bool IsLive, bool IsCallable) { assert((Offset + Size) <= Base.getSize() && "Symbol extends past end of block"); - assert(!Name.empty() && "Name cannot be empty"); + assert(Name && "Name cannot be empty"); auto *Sym = Allocator.Allocate(); - new (Sym) Symbol(Base, Offset, Name, Size, L, S, IsLive, IsCallable); + new (Sym) + Symbol(Base, Offset, std::move(Name), Size, L, S, IsLive, IsCallable); return *Sym; } @@ -486,18 +508,19 @@ Symbol &operator=(Symbol &&) = delete; /// Returns true if this symbol has a name. - bool hasName() const { return !Name.empty(); } + bool hasName() const { return Name != nullptr; } /// Returns the name of this symbol (empty if the symbol is anonymous). - StringRef getName() const { - assert((!Name.empty() || getScope() == Scope::Local) && + const orc::SymbolStringPtr &getName() const { + assert((Name || getScope() == Scope::Local) && "Anonymous symbol has non-local scope"); + return Name; } /// Rename this symbol. The client is responsible for updating scope and /// linkage if this name-change requires it. - void setName(StringRef Name) { this->Name = Name; } + void setName(orc::SymbolStringPtr &&Name) { this->Name = std::move(Name); } /// Returns true if this Symbol has content (potentially) defined within this /// object file (i.e. is anything but an external or absolute symbol). @@ -599,7 +622,7 @@ /// Set the linkage for this Symbol. void setLinkage(Linkage L) { - assert((L == Linkage::Strong || (!Base->isAbsolute() && !Name.empty())) && + assert((L == Linkage::Strong || (!Base->isAbsolute() && Name)) && "Linkage can only be applied to defined named symbols"); this->L = static_cast(L); } @@ -609,7 +632,7 @@ /// Set the visibility for this Symbol. void setScope(Scope S) { - assert((!Name.empty() || S == Scope::Local) && + assert((Name || S == Scope::Local) && "Can not set anonymous symbol to non-local scope"); assert((S != Scope::Local || Base->isDefined() || Base->isAbsolute()) && "Invalid visibility for symbol type"); @@ -668,8 +691,7 @@ static constexpr uint64_t MaxOffset = (1ULL << 59) - 1; - // FIXME: A char* or SymbolStringPtr may pack better. - StringRef Name; + orc::SymbolStringPtr Name; Addressable *Base = nullptr; uint64_t Offset : 57; uint64_t L : 1; @@ -984,16 +1006,18 @@ using GetEdgeKindNameFunction = const char *(*)(Edge::Kind); - LinkGraph(std::string Name, const Triple &TT, unsigned PointerSize, + LinkGraph(std::string Name, std::shared_ptr SSP, + const Triple &TT, unsigned PointerSize, support::endianness Endianness, GetEdgeKindNameFunction GetEdgeKindName) - : Name(std::move(Name)), TT(TT), PointerSize(PointerSize), + : Name(std::move(Name)), SSP(SSP), TT(TT), PointerSize(PointerSize), Endianness(Endianness), GetEdgeKindName(std::move(GetEdgeKindName)) {} LinkGraph(const LinkGraph &) = delete; LinkGraph &operator=(const LinkGraph &) = delete; LinkGraph(LinkGraph &&) = delete; LinkGraph &operator=(LinkGraph &&) = delete; + ~LinkGraph(); /// Returns the name of this graph (usually the name of the original /// underlying MemoryBuffer). @@ -1010,6 +1034,8 @@ const char *getEdgeKindName(Edge::Kind K) const { return GetEdgeKindName(K); } + std::shared_ptr getSymbolStringPool() { return SSP; } + /// Allocate a mutable buffer of the given size using the LinkGraph's /// allocator. MutableArrayRef allocateBuffer(size_t Size) { @@ -1170,6 +1196,10 @@ Block &splitBlock(Block &B, size_t SplitIndex, SplitBlockCache *Cache = nullptr); + // + orc::SymbolStringPtr intern(StringRef SymbolName) { + return SSP->intern(SymbolName); + } /// Add an external symbol. /// Some formats (e.g. ELF) allow Symbols to have sizes. For Symbols whose /// size is not known, you should substitute '0'. @@ -1178,7 +1208,8 @@ /// found or an error will be emitted. Externals that are weakly referenced /// are permitted to be undefined, in which case they are assigned an address /// of 0. - Symbol &addExternalSymbol(StringRef Name, orc::ExecutorAddrDiff Size, + Symbol &addExternalSymbol(orc::SymbolStringPtr &&Name, + orc::ExecutorAddrDiff Size, bool IsWeaklyReferenced) { assert(llvm::count_if(ExternalSymbols, [&](const Symbol *Sym) { @@ -1186,14 +1217,20 @@ }) == 0 && "Duplicate external symbol"); auto &Sym = Symbol::constructExternal( - Allocator, createAddressable(orc::ExecutorAddr(), false), Name, Size, - Linkage::Strong, IsWeaklyReferenced); + Allocator, createAddressable(orc::ExecutorAddr(), false), + std::move(Name), Size, Linkage::Strong, IsWeaklyReferenced); ExternalSymbols.insert(&Sym); return Sym; } + Symbol &addExternalSymbol(StringRef Name, orc::ExecutorAddrDiff Size, + bool IsWeaklyReferenced) { + return addExternalSymbol(SSP->intern(Name), Size, IsWeaklyReferenced); + } + /// Add an absolute symbol. - Symbol &addAbsoluteSymbol(StringRef Name, orc::ExecutorAddr Address, + Symbol &addAbsoluteSymbol(orc::SymbolStringPtr Name, + orc::ExecutorAddr Address, orc::ExecutorAddrDiff Size, Linkage L, Scope S, bool IsLive) { assert((S == Scope::Local || llvm::count_if(AbsoluteSymbols, @@ -1202,11 +1239,18 @@ }) == 0) && "Duplicate absolute symbol"); auto &Sym = Symbol::constructAbsolute(Allocator, createAddressable(Address), - Name, Size, L, S, IsLive); + std::move(Name), Size, L, S, IsLive); AbsoluteSymbols.insert(&Sym); return Sym; } + Symbol &addAbsoluteSymbol(StringRef Name, orc::ExecutorAddr Address, + orc::ExecutorAddrDiff Size, Linkage L, Scope S, + bool IsLive) { + + return addAbsoluteSymbol(SSP->intern(Name), Address, Size, L, S, IsLive); + } + /// Add an anonymous symbol. Symbol &addAnonymousSymbol(Block &Content, orc::ExecutorAddrDiff Offset, orc::ExecutorAddrDiff Size, bool IsCallable, @@ -1221,13 +1265,22 @@ Symbol &addDefinedSymbol(Block &Content, orc::ExecutorAddrDiff Offset, StringRef Name, orc::ExecutorAddrDiff Size, Linkage L, Scope S, bool IsCallable, bool IsLive) { + return addDefinedSymbol(Content, Offset, SSP->intern(Name), Size, L, S, + IsCallable, IsLive); + } + + Symbol &addDefinedSymbol(Block &Content, orc::ExecutorAddrDiff Offset, + orc::SymbolStringPtr Name, + orc::ExecutorAddrDiff Size, Linkage L, Scope S, + bool IsCallable, bool IsLive) { assert((S == Scope::Local || llvm::count_if(defined_symbols(), [&](const Symbol *Sym) { return Sym->getName() == Name; }) == 0) && "Duplicate defined symbol"); - auto &Sym = Symbol::constructNamedDef(Allocator, Content, Offset, Name, - Size, L, S, IsLive, IsCallable); + auto &Sym = + Symbol::constructNamedDef(Allocator, Content, Offset, std::move(Name), + Size, L, S, IsLive, IsCallable); Content.getSection().addSymbol(Sym); return Sym; } @@ -1506,6 +1559,7 @@ BumpPtrAllocator Allocator; std::string Name; + std::shared_ptr SSP; Triple TT; unsigned PointerSize; support::endianness Endianness; @@ -1733,7 +1787,8 @@ raw_ostream &operator<<(raw_ostream &OS, const SymbolLookupFlags &LF); /// A map of symbol names to resolved addresses. -using AsyncLookupResult = DenseMap; +using AsyncLookupResult = + DenseMap; /// A function object to call with a resolved symbol map (See AsyncLookupResult) /// or an error if resolution failed. @@ -1766,7 +1821,7 @@ /// Holds context for a single jitLink invocation. class JITLinkContext { public: - using LookupMap = DenseMap; + using LookupMap = DenseMap; /// Create a JITLinkContext. JITLinkContext(const JITLinkDylib *JD) : JD(JD) {} @@ -1875,7 +1930,8 @@ /// its contents. The caller is responsible for ensuring that the object buffer /// outlives the graph. Expected> -createLinkGraphFromObject(MemoryBufferRef ObjectBuffer); +createLinkGraphFromObject(MemoryBufferRef ObjectBuffer, + std::shared_ptr SSP); /// Link the given graph. void link(std::unique_ptr G, std::unique_ptr Ctx); diff --git a/llvm/include/llvm/ExecutionEngine/JITLink/MachO.h b/llvm/include/llvm/ExecutionEngine/JITLink/MachO.h --- a/llvm/include/llvm/ExecutionEngine/JITLink/MachO.h +++ b/llvm/include/llvm/ExecutionEngine/JITLink/MachO.h @@ -24,7 +24,8 @@ /// its contents. The caller is responsible for ensuring that the object buffer /// outlives the graph. Expected> -createLinkGraphFromMachOObject(MemoryBufferRef ObjectBuffer); +createLinkGraphFromMachOObject(MemoryBufferRef ObjectBuffer, + std::shared_ptr SSP); /// jit-link the given ObjBuffer, which must be a MachO object file. /// diff --git a/llvm/include/llvm/ExecutionEngine/JITLink/MachO_arm64.h b/llvm/include/llvm/ExecutionEngine/JITLink/MachO_arm64.h --- a/llvm/include/llvm/ExecutionEngine/JITLink/MachO_arm64.h +++ b/llvm/include/llvm/ExecutionEngine/JITLink/MachO_arm64.h @@ -23,8 +23,8 @@ /// Note: The graph does not take ownership of the underlying buffer, nor copy /// its contents. The caller is responsible for ensuring that the object buffer /// outlives the graph. -Expected> -createLinkGraphFromMachOObject_arm64(MemoryBufferRef ObjectBuffer); +Expected> createLinkGraphFromMachOObject_arm64( + MemoryBufferRef ObjectBuffer, std::shared_ptr SSP); /// jit-link the given object buffer, which must be a MachO arm64 object file. /// diff --git a/llvm/include/llvm/ExecutionEngine/JITLink/MachO_x86_64.h b/llvm/include/llvm/ExecutionEngine/JITLink/MachO_x86_64.h --- a/llvm/include/llvm/ExecutionEngine/JITLink/MachO_x86_64.h +++ b/llvm/include/llvm/ExecutionEngine/JITLink/MachO_x86_64.h @@ -23,8 +23,8 @@ /// Note: The graph does not take ownership of the underlying buffer, nor copy /// its contents. The caller is responsible for ensuring that the object buffer /// outlives the graph. -Expected> -createLinkGraphFromMachOObject_x86_64(MemoryBufferRef ObjectBuffer); +Expected> createLinkGraphFromMachOObject_x86_64( + MemoryBufferRef ObjectBuffer, std::shared_ptr SSP); /// jit-link the given LinkGraph. /// diff --git a/llvm/include/llvm/ExecutionEngine/JITLink/TableManager.h b/llvm/include/llvm/ExecutionEngine/JITLink/TableManager.h --- a/llvm/include/llvm/ExecutionEngine/JITLink/TableManager.h +++ b/llvm/include/llvm/ExecutionEngine/JITLink/TableManager.h @@ -39,7 +39,7 @@ auto &Entry = impl().createEntry(G, Target); DEBUG_WITH_TYPE("jitlink", { dbgs() << " Created " << impl().getSectionName() << " entry for " - << Target.getName() << ": " << Entry << "\n"; + << *Target.getName() << ": " << Entry << "\n"; }); EntryI = Entries.insert(std::make_pair(Target.getName(), &Entry)).first; } @@ -54,7 +54,7 @@ private: TableManagerImplT &impl() { return static_cast(*this); } - DenseMap Entries; + DenseMap Entries; }; } // namespace jitlink diff --git a/llvm/include/llvm/ExecutionEngine/Orc/Layer.h b/llvm/include/llvm/ExecutionEngine/Orc/Layer.h --- a/llvm/include/llvm/ExecutionEngine/Orc/Layer.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/Layer.h @@ -166,7 +166,7 @@ virtual void emit(std::unique_ptr R, std::unique_ptr O) = 0; -private: +protected: ExecutionSession &ES; }; diff --git a/llvm/lib/ExecutionEngine/JITLink/COFF.cpp b/llvm/lib/ExecutionEngine/JITLink/COFF.cpp --- a/llvm/lib/ExecutionEngine/JITLink/COFF.cpp +++ b/llvm/lib/ExecutionEngine/JITLink/COFF.cpp @@ -43,7 +43,8 @@ } Expected> -createLinkGraphFromCOFFObject(MemoryBufferRef ObjectBuffer) { +createLinkGraphFromCOFFObject(MemoryBufferRef ObjectBuffer, + std::shared_ptr SSP) { StringRef Data = ObjectBuffer.getBuffer(); // Check magic @@ -111,7 +112,7 @@ switch (Machine) { case COFF::IMAGE_FILE_MACHINE_AMD64: - return createLinkGraphFromCOFFObject_x86_64(ObjectBuffer); + return createLinkGraphFromCOFFObject_x86_64(ObjectBuffer, SSP); default: return make_error( "Unsupported target machine architecture in COFF object " + diff --git a/llvm/lib/ExecutionEngine/JITLink/COFFLinkGraphBuilder.h b/llvm/lib/ExecutionEngine/JITLink/COFFLinkGraphBuilder.h --- a/llvm/lib/ExecutionEngine/JITLink/COFFLinkGraphBuilder.h +++ b/llvm/lib/ExecutionEngine/JITLink/COFFLinkGraphBuilder.h @@ -39,7 +39,8 @@ using COFFSymbolIndex = int32_t; COFFLinkGraphBuilder(const object::COFFObjectFile &Obj, Triple TT, - LinkGraph::GetEdgeKindNameFunction GetEdgeKindName); + LinkGraph::GetEdgeKindNameFunction GetEdgeKindName, + std::shared_ptr SSP); LinkGraph &getGraph() const { return *G; } @@ -134,20 +135,21 @@ Section &getCommonSection(); - Symbol *createExternalSymbol(COFFSymbolIndex SymIndex, StringRef SymbolName, + Symbol *createExternalSymbol(COFFSymbolIndex SymIndex, + orc::SymbolStringPtr SymbolName, object::COFFSymbolRef Symbol, const object::coff_section *Section); - Expected createAliasSymbol(StringRef SymbolName, Linkage L, Scope S, - Symbol &Target); + Expected createAliasSymbol(orc::SymbolStringPtr SymbolName, + Linkage L, Scope S, Symbol &Target); Expected createDefinedSymbol(COFFSymbolIndex SymIndex, - StringRef SymbolName, + orc::SymbolStringPtr SymbolName, object::COFFSymbolRef Symbol, const object::coff_section *Section); Expected createCOMDATExportRequest( COFFSymbolIndex SymIndex, object::COFFSymbolRef Symbol, const object::coff_aux_section_definition *Definition); Expected exportCOMDATSymbol(COFFSymbolIndex SymIndex, - StringRef SymbolName, + orc::SymbolStringPtr SymbolName, object::COFFSymbolRef Symbol); Error handleDirectiveSection(StringRef Str); @@ -177,8 +179,8 @@ std::vector GraphSymbols; DenseMap AlternateNames; - DenseMap ExternalSymbols; - DenseMap DefinedSymbols; + DenseMap ExternalSymbols; + DenseMap DefinedSymbols; }; template diff --git a/llvm/lib/ExecutionEngine/JITLink/COFFLinkGraphBuilder.cpp b/llvm/lib/ExecutionEngine/JITLink/COFFLinkGraphBuilder.cpp --- a/llvm/lib/ExecutionEngine/JITLink/COFFLinkGraphBuilder.cpp +++ b/llvm/lib/ExecutionEngine/JITLink/COFFLinkGraphBuilder.cpp @@ -11,6 +11,8 @@ //===----------------------------------------------------------------------===// #include "COFFLinkGraphBuilder.h" +#include + #define DEBUG_TYPE "jitlink" static const char *CommonSectionName = "__common"; @@ -25,9 +27,10 @@ COFFLinkGraphBuilder::COFFLinkGraphBuilder( const object::COFFObjectFile &Obj, Triple TT, - LinkGraph::GetEdgeKindNameFunction GetEdgeKindName) + LinkGraph::GetEdgeKindNameFunction GetEdgeKindName, + std::shared_ptr SSP) : Obj(Obj), - G(std::make_unique(Obj.getFileName().str(), + G(std::make_unique(Obj.getFileName().str(), SSP, createTripleWithCOFFFormat(TT), getPointerSize(Obj), getEndianness(Obj), std::move(GetEdgeKindName))) { @@ -219,18 +222,19 @@ " (" + toString(SecOrErr.takeError()) + ")"); Sec = *SecOrErr; } + auto InternedSymbolName = G->intern(std::move(SymbolName)); // Create jitlink symbol jitlink::Symbol *GSym = nullptr; if (Sym->isFileRecord()) LLVM_DEBUG({ dbgs() << " " << SymIndex << ": Skipping FileRecord symbol \"" - << SymbolName << "\" in " + << *InternedSymbolName << "\" in " << getCOFFSectionName(SectionIndex, Sec, *Sym) << " (index: " << SectionIndex << ") \n"; }); else if (Sym->isUndefined()) { - GSym = createExternalSymbol(SymIndex, SymbolName, *Sym, Sec); + GSym = createExternalSymbol(SymIndex, InternedSymbolName, *Sym, Sec); } else if (Sym->isWeakExternal()) { auto *WeakExternal = Sym->getAux(); COFFSymbolIndex TagIndex = WeakExternal->TagIndex; @@ -239,7 +243,7 @@ {SymIndex, TagIndex, Characteristics, SymbolName}); } else { Expected NewGSym = - createDefinedSymbol(SymIndex, SymbolName, *Sym, Sec); + createDefinedSymbol(SymIndex, InternedSymbolName, *Sym, Sec); if (!NewGSym) return NewGSym.takeError(); GSym = *NewGSym; @@ -247,7 +251,7 @@ LLVM_DEBUG({ dbgs() << " " << SymIndex << ": Creating defined graph symbol for COFF symbol \"" - << SymbolName << "\" in " + << *InternedSymbolName << "\" in " << getCOFFSectionName(SectionIndex, Sec, *Sym) << " (index: " << SectionIndex << ") \n"; dbgs() << " " << *GSym << "\n"; @@ -290,10 +294,13 @@ break; } case COFF_OPT_incl: { - auto DataCopy = G->allocateContent(S); - StringRef StrCopy(DataCopy.data(), DataCopy.size()); - ExternalSymbols[StrCopy] = &G->addExternalSymbol(StrCopy, 0, false); - ExternalSymbols[StrCopy]->setLive(true); + auto internedName = G->intern(std::move(S)); + // todo: wyles revisit this need to rethink the sinking of the name i + // guess... urgh... + auto ptrCpy = internedName; + auto symbol = &G->addExternalSymbol(std::move(internedName), 0, false); + symbol->setLive(true); + ExternalSymbols[ptrCpy] = symbol; break; } case COFF_OPT_export: @@ -325,8 +332,8 @@ ? Scope::Default : Scope::Local; - auto NewSymbol = - createAliasSymbol(WeakExternal.SymbolName, Linkage::Weak, S, *Target); + auto NewSymbol = createAliasSymbol(G->intern(WeakExternal.SymbolName), + Linkage::Weak, S, *Target); if (!NewSymbol) return NewSymbol.takeError(); setGraphSymbol(AliasSymbol->getSectionNumber(), WeakExternal.Alias, @@ -347,37 +354,47 @@ } Error COFFLinkGraphBuilder::handleAlternateNames() { - for (auto &KeyValue : AlternateNames) - if (DefinedSymbols.count(KeyValue.second) && - ExternalSymbols.count(KeyValue.first)) { - auto *Target = DefinedSymbols[KeyValue.second]; - auto *Alias = ExternalSymbols[KeyValue.first]; + for (auto &KeyValue : AlternateNames) { + // TODO: wyles comes back and turn the alternateNames into a map of + // symbolstringptr + auto DefinedSymbolName = G->intern(KeyValue.second); + auto ExternalSymbolsName = G->intern(KeyValue.first); + if (DefinedSymbols.count(DefinedSymbolName) && + ExternalSymbols.count(ExternalSymbolsName)) { + auto *Target = DefinedSymbols[DefinedSymbolName]; + auto *Alias = ExternalSymbols[ExternalSymbolsName]; G->makeDefined(*Alias, Target->getBlock(), Target->getOffset(), Target->getSize(), Linkage::Weak, Scope::Local, false); } + } return Error::success(); } Symbol *COFFLinkGraphBuilder::createExternalSymbol( - COFFSymbolIndex SymIndex, StringRef SymbolName, + COFFSymbolIndex SymIndex, orc::SymbolStringPtr SymbolName, object::COFFSymbolRef Symbol, const object::coff_section *Section) { - if (!ExternalSymbols.count(SymbolName)) - ExternalSymbols[SymbolName] = - &G->addExternalSymbol(SymbolName, Symbol.getValue(), false); + llvm::jitlink::Symbol *sym = nullptr; + if (!ExternalSymbols.count(SymbolName)) { + sym = + &G->addExternalSymbol(std::move(SymbolName), Symbol.getValue(), false); + ExternalSymbols[sym->getName()] = sym; + } else { + sym = ExternalSymbols[SymbolName]; + } LLVM_DEBUG({ dbgs() << " " << SymIndex << ": Creating external graph symbol for COFF symbol \"" - << SymbolName << "\" in " + << *sym->getName() << "\" in " << getCOFFSectionName(Symbol.getSectionNumber(), Section, Symbol) << " (index: " << Symbol.getSectionNumber() << ") \n"; }); - return ExternalSymbols[SymbolName]; + return sym; } -Expected COFFLinkGraphBuilder::createAliasSymbol(StringRef SymbolName, - Linkage L, Scope S, - Symbol &Target) { +Expected +COFFLinkGraphBuilder::createAliasSymbol(orc::SymbolStringPtr SymbolName, + Linkage L, Scope S, Symbol &Target) { if (!Target.isDefined()) { // FIXME: Support this when there's a way to handle this. return make_error("Weak external symbol with external " @@ -453,8 +470,9 @@ } Expected COFFLinkGraphBuilder::createDefinedSymbol( - COFFSymbolIndex SymIndex, StringRef SymbolName, + COFFSymbolIndex SymIndex, orc::SymbolStringPtr SymbolName, object::COFFSymbolRef Symbol, const object::coff_section *Section) { + if (Symbol.isCommon()) { // FIXME: correct alignment return &G->addDefinedSymbol( @@ -463,6 +481,7 @@ 0, SymbolName, Symbol.getValue(), Linkage::Strong, Scope::Default, false, false); } + if (Symbol.isAbsolute()) return &G->addAbsoluteSymbol(SymbolName, orc::ExecutorAddr(Symbol.getValue()), 0, @@ -479,7 +498,7 @@ dbgs() << " " << SymIndex << ": Skipping graph symbol since section was not created for " "COFF symbol \"" - << SymbolName << "\" in section " << Symbol.getSectionNumber() + << *SymbolName << "\" in section " << Symbol.getSectionNumber() << "\n"; }); return nullptr; @@ -596,7 +615,7 @@ // Process the second symbol of COMDAT sequence. Expected COFFLinkGraphBuilder::exportCOMDATSymbol(COFFSymbolIndex SymIndex, - StringRef SymbolName, + orc::SymbolStringPtr SymbolName, object::COFFSymbolRef Symbol) { Block *B = getGraphBlock(Symbol.getSectionNumber()); auto &PendingComdatExport = PendingComdatExports[Symbol.getSectionNumber()]; @@ -609,8 +628,9 @@ false); LLVM_DEBUG({ dbgs() << " " << SymIndex - << ": Exporting COMDAT graph symbol for COFF symbol \"" << SymbolName - << "\" in section " << Symbol.getSectionNumber() << "\n"; + << ": Exporting COMDAT graph symbol for COFF symbol \"" + << *SymbolName << "\" in section " << Symbol.getSectionNumber() + << "\n"; dbgs() << " " << *GSym << "\n"; }); setGraphSymbol(Symbol.getSectionNumber(), PendingComdatExport->SymbolIndex, diff --git a/llvm/lib/ExecutionEngine/JITLink/COFF_x86_64.cpp b/llvm/lib/ExecutionEngine/JITLink/COFF_x86_64.cpp --- a/llvm/lib/ExecutionEngine/JITLink/COFF_x86_64.cpp +++ b/llvm/lib/ExecutionEngine/JITLink/COFF_x86_64.cpp @@ -148,6 +148,7 @@ SectionIdx = getObject().getNumberOfSections() + 1; else SectionIdx = COFFSymbol.getSectionNumber(); + auto *AbsSym = &getGraph().addAbsoluteSymbol( "secidx", orc::ExecutorAddr(SectionIdx), 2, Linkage::Strong, Scope::Local, false); @@ -181,12 +182,18 @@ } public: - COFFLinkGraphBuilder_x86_64(const object::COFFObjectFile &Obj, const Triple T) - : COFFLinkGraphBuilder(Obj, std::move(T), getCOFFX86RelocationKindName) {} + COFFLinkGraphBuilder_x86_64(const object::COFFObjectFile &Obj, const Triple T, + std::shared_ptr SSP) + : COFFLinkGraphBuilder(Obj, std::move(T), getCOFFX86RelocationKindName, + SSP) {} }; class COFFLinkGraphLowering_x86_64 { public: + COFFLinkGraphLowering_x86_64(std::shared_ptr SSP) + : SSP(SSP) { + imageBaseName = SSP->intern("__ImageBase"); + } // Lowers COFF x86_64 specific edges to generic x86_64 edges. Error lowerCOFFRelocationEdges(LinkGraph &G, JITLinkContext &Ctx) { for (auto *B : G.blocks()) { @@ -228,8 +235,7 @@ } private: - static StringRef getImageBaseSymbolName() { return "__ImageBase"; } - + orc::SymbolStringPtr getImageBaseSymbolName() { return this->imageBaseName; } orc::ExecutorAddr getSectionStart(Section &Sec) { if (!SectionStartCache.count(&Sec)) { SectionRange Range(Sec); @@ -269,12 +275,13 @@ DenseMap
SectionStartCache; orc::ExecutorAddr ImageBase; + std::shared_ptr SSP; + orc::SymbolStringPtr imageBaseName = nullptr; }; Error lowerEdges_COFF_x86_64(LinkGraph &G, JITLinkContext *Ctx) { LLVM_DEBUG(dbgs() << "Lowering COFF x86_64 edges:\n"); - COFFLinkGraphLowering_x86_64 GraphLowering; - + COFFLinkGraphLowering_x86_64 GraphLowering(G.getSymbolStringPool()); if (auto Err = GraphLowering.lowerCOFFRelocationEdges(G, *Ctx)) return Err; @@ -303,8 +310,8 @@ } } -Expected> -createLinkGraphFromCOFFObject_x86_64(MemoryBufferRef ObjectBuffer) { +Expected> createLinkGraphFromCOFFObject_x86_64( + MemoryBufferRef ObjectBuffer, std::shared_ptr SSP) { LLVM_DEBUG({ dbgs() << "Building jitlink graph for new input " << ObjectBuffer.getBufferIdentifier() << "...\n"; @@ -314,7 +321,7 @@ if (!COFFObj) return COFFObj.takeError(); - return COFFLinkGraphBuilder_x86_64(**COFFObj, (*COFFObj)->makeTriple()) + return COFFLinkGraphBuilder_x86_64(**COFFObj, (*COFFObj)->makeTriple(), SSP) .buildGraph(); } diff --git a/llvm/lib/ExecutionEngine/JITLink/EHFrameSupport.cpp b/llvm/lib/ExecutionEngine/JITLink/EHFrameSupport.cpp --- a/llvm/lib/ExecutionEngine/JITLink/EHFrameSupport.cpp +++ b/llvm/lib/ExecutionEngine/JITLink/EHFrameSupport.cpp @@ -385,7 +385,7 @@ dbgs() << " WARNING: Not adding keep-alive edge to FDE at " << RecordAddress << ", which points to " << ((*PCBegin)->isExternal() ? "external" : "absolute") - << " symbol \"" << (*PCBegin)->getName() + << " symbol \"" << *(*PCBegin)->getName() << "\" -- FDE must be kept alive manually or it will be " << "dead stripped.\n"; }); @@ -538,7 +538,7 @@ << (BlockToFix.getAddress() + PointerFieldOffset) << " to " << FieldName << " at " << EdgeI->second.Target->getAddress(); if (EdgeI->second.Target->hasName()) - dbgs() << " (" << EdgeI->second.Target->getName() << ")"; + dbgs() << " (" << *EdgeI->second.Target->getName() << ")"; dbgs() << "\n"; }); if (auto Err = skipEncodedPointer(PointerEncoding, RecordReader)) @@ -600,7 +600,7 @@ << (BlockToFix.getAddress() + PointerFieldOffset) << " to " << FieldName << " at " << TargetSym->getAddress(); if (TargetSym->hasName()) - dbgs() << " (" << TargetSym->getName() << ")"; + dbgs() << " (" << *TargetSym->getName() << ")"; dbgs() << "\n"; }); diff --git a/llvm/lib/ExecutionEngine/JITLink/ELF.cpp b/llvm/lib/ExecutionEngine/JITLink/ELF.cpp --- a/llvm/lib/ExecutionEngine/JITLink/ELF.cpp +++ b/llvm/lib/ExecutionEngine/JITLink/ELF.cpp @@ -55,7 +55,8 @@ } Expected> -createLinkGraphFromELFObject(MemoryBufferRef ObjectBuffer) { +createLinkGraphFromELFObject(MemoryBufferRef ObjectBuffer, + std::shared_ptr SSP) { StringRef Buffer = ObjectBuffer.getBuffer(); if (Buffer.size() < ELF::EI_MAG3 + 1) return make_error("Truncated ELF buffer"); @@ -69,17 +70,17 @@ switch (*TargetMachineArch) { case ELF::EM_AARCH64: - return createLinkGraphFromELFObject_aarch64(ObjectBuffer); + return createLinkGraphFromELFObject_aarch64(ObjectBuffer, SSP); case ELF::EM_ARM: - return createLinkGraphFromELFObject_aarch32(ObjectBuffer); + return createLinkGraphFromELFObject_aarch32(ObjectBuffer, SSP); case ELF::EM_LOONGARCH: - return createLinkGraphFromELFObject_loongarch(ObjectBuffer); + return createLinkGraphFromELFObject_loongarch(ObjectBuffer, SSP); case ELF::EM_RISCV: - return createLinkGraphFromELFObject_riscv(ObjectBuffer); + return createLinkGraphFromELFObject_riscv(ObjectBuffer, SSP); case ELF::EM_X86_64: - return createLinkGraphFromELFObject_x86_64(ObjectBuffer); + return createLinkGraphFromELFObject_x86_64(ObjectBuffer, SSP); case ELF::EM_386: - return createLinkGraphFromELFObject_i386(ObjectBuffer); + return createLinkGraphFromELFObject_i386(ObjectBuffer, SSP); default: return make_error( "Unsupported target machine architecture in ELF object " + diff --git a/llvm/lib/ExecutionEngine/JITLink/ELFLinkGraphBuilder.h b/llvm/lib/ExecutionEngine/JITLink/ELFLinkGraphBuilder.h --- a/llvm/lib/ExecutionEngine/JITLink/ELFLinkGraphBuilder.h +++ b/llvm/lib/ExecutionEngine/JITLink/ELFLinkGraphBuilder.h @@ -60,7 +60,8 @@ public: ELFLinkGraphBuilder(const object::ELFFile &Obj, Triple TT, StringRef FileName, - LinkGraph::GetEdgeKindNameFunction GetEdgeKindName); + LinkGraph::GetEdgeKindNameFunction GetEdgeKindName, + std::shared_ptr SSP); /// Debug sections are included in the graph by default. Use /// setProcessDebugSections(false) to ignore them if debug info is not @@ -196,9 +197,10 @@ template ELFLinkGraphBuilder::ELFLinkGraphBuilder( const ELFFile &Obj, Triple TT, StringRef FileName, - LinkGraph::GetEdgeKindNameFunction GetEdgeKindName) + LinkGraph::GetEdgeKindNameFunction GetEdgeKindName, + std::shared_ptr SSP) : ELFLinkGraphBuilderBase(std::make_unique( - FileName.str(), Triple(std::move(TT)), ELFT::Is64Bits ? 8 : 4, + FileName.str(), SSP, Triple(std::move(TT)), ELFT::Is64Bits ? 8 : 4, support::endianness(ELFT::TargetEndianness), std::move(GetEdgeKindName))), Obj(Obj) { diff --git a/llvm/lib/ExecutionEngine/JITLink/ELF_aarch32.cpp b/llvm/lib/ExecutionEngine/JITLink/ELF_aarch32.cpp --- a/llvm/lib/ExecutionEngine/JITLink/ELF_aarch32.cpp +++ b/llvm/lib/ExecutionEngine/JITLink/ELF_aarch32.cpp @@ -187,9 +187,10 @@ public: ELFLinkGraphBuilder_aarch32(StringRef FileName, const llvm::object::ELFFile &Obj, Triple TT, - aarch32::ArmConfig ArmCfg) + aarch32::ArmConfig ArmCfg, + std::shared_ptr SSP) : ELFLinkGraphBuilder(Obj, std::move(TT), FileName, - getELFAArch32EdgeKindName), + getELFAArch32EdgeKindName, SSP), ArmCfg(std::move(ArmCfg)) {} }; @@ -202,8 +203,8 @@ return Error::success(); } -Expected> -createLinkGraphFromELFObject_aarch32(MemoryBufferRef ObjectBuffer) { +Expected> createLinkGraphFromELFObject_aarch32( + MemoryBufferRef ObjectBuffer, std::shared_ptr SSP) { LLVM_DEBUG({ dbgs() << "Building jitlink graph for new input " << ObjectBuffer.getBufferIdentifier() << "...\n"; @@ -245,14 +246,14 @@ case Triple::thumb: { auto &ELFFile = cast>(**ELFObj).getELFFile(); return ELFLinkGraphBuilder_aarch32( - (*ELFObj)->getFileName(), ELFFile, TT, ArmCfg) + (*ELFObj)->getFileName(), ELFFile, TT, ArmCfg, SSP) .buildGraph(); } case Triple::armeb: case Triple::thumbeb: { auto &ELFFile = cast>(**ELFObj).getELFFile(); return ELFLinkGraphBuilder_aarch32((*ELFObj)->getFileName(), - ELFFile, TT, ArmCfg) + ELFFile, TT, ArmCfg, SSP) .buildGraph(); } default: diff --git a/llvm/lib/ExecutionEngine/JITLink/ELF_aarch64.cpp b/llvm/lib/ExecutionEngine/JITLink/ELF_aarch64.cpp --- a/llvm/lib/ExecutionEngine/JITLink/ELF_aarch64.cpp +++ b/llvm/lib/ExecutionEngine/JITLink/ELF_aarch64.cpp @@ -391,9 +391,10 @@ public: ELFLinkGraphBuilder_aarch64(StringRef FileName, - const object::ELFFile &Obj, Triple TT) + const object::ELFFile &Obj, Triple TT, + std::shared_ptr SSP) : ELFLinkGraphBuilder(Obj, std::move(TT), FileName, - aarch64::getEdgeKindName) {} + aarch64::getEdgeKindName, SSP) {} }; // TLS Info Builder. @@ -530,8 +531,8 @@ namespace llvm { namespace jitlink { -Expected> -createLinkGraphFromELFObject_aarch64(MemoryBufferRef ObjectBuffer) { +Expected> createLinkGraphFromELFObject_aarch64( + MemoryBufferRef ObjectBuffer, std::shared_ptr SSP) { LLVM_DEBUG({ dbgs() << "Building jitlink graph for new input " << ObjectBuffer.getBufferIdentifier() << "...\n"; @@ -545,9 +546,9 @@ "Only AArch64 (little endian) is supported for now"); auto &ELFObjFile = cast>(**ELFObj); - return ELFLinkGraphBuilder_aarch64((*ELFObj)->getFileName(), - ELFObjFile.getELFFile(), - (*ELFObj)->makeTriple()) + return ELFLinkGraphBuilder_aarch64( + (*ELFObj)->getFileName(), ELFObjFile.getELFFile(), + (*ELFObj)->makeTriple(), SSP) .buildGraph(); } diff --git a/llvm/lib/ExecutionEngine/JITLink/ELF_i386.cpp b/llvm/lib/ExecutionEngine/JITLink/ELF_i386.cpp --- a/llvm/lib/ExecutionEngine/JITLink/ELF_i386.cpp +++ b/llvm/lib/ExecutionEngine/JITLink/ELF_i386.cpp @@ -56,7 +56,8 @@ auto DefineExternalGOTSymbolIfPresent = createDefineExternalSectionStartAndEndSymbolsPass( [&](LinkGraph &LG, Symbol &Sym) -> SectionRangeSymbolDesc { - if (Sym.getName() == ELFGOTSymbolName) + if (Sym.getName() != nullptr && + *Sym.getName() == ELFGOTSymbolName) if (auto *GOTSection = G.findSectionByName( i386::GOTTableManager::getSectionName())) { GOTSymbol = &Sym; @@ -82,7 +83,7 @@ // Check for an existing defined symbol. for (auto *Sym : GOTSection->symbols()) - if (Sym->getName() == ELFGOTSymbolName) { + if (Sym->getName() != nullptr && *Sym->getName() == ELFGOTSymbolName) { GOTSymbol = Sym; return Error::success(); } @@ -210,13 +211,15 @@ public: ELFLinkGraphBuilder_i386(StringRef FileName, const object::ELFFile &Obj, - Triple TT) + Triple TT, + std::shared_ptr SSP) : ELFLinkGraphBuilder(Obj, std::move(TT), FileName, - i386::getEdgeKindName) {} + i386::getEdgeKindName, SSP) {} }; Expected> -createLinkGraphFromELFObject_i386(MemoryBufferRef ObjectBuffer) { +createLinkGraphFromELFObject_i386(MemoryBufferRef ObjectBuffer, + std::shared_ptr SSP) { LLVM_DEBUG({ dbgs() << "Building jitlink graph for new input " << ObjectBuffer.getBufferIdentifier() << "...\n"; @@ -232,7 +235,7 @@ auto &ELFObjFile = cast>(**ELFObj); return ELFLinkGraphBuilder_i386((*ELFObj)->getFileName(), ELFObjFile.getELFFile(), - (*ELFObj)->makeTriple()) + (*ELFObj)->makeTriple(), SSP) .buildGraph(); } diff --git a/llvm/lib/ExecutionEngine/JITLink/ELF_loongarch.cpp b/llvm/lib/ExecutionEngine/JITLink/ELF_loongarch.cpp --- a/llvm/lib/ExecutionEngine/JITLink/ELF_loongarch.cpp +++ b/llvm/lib/ExecutionEngine/JITLink/ELF_loongarch.cpp @@ -129,9 +129,10 @@ public: ELFLinkGraphBuilder_loongarch(StringRef FileName, - const object::ELFFile &Obj, Triple TT) + const object::ELFFile &Obj, Triple TT, + std::shared_ptr SSP) : ELFLinkGraphBuilder(Obj, std::move(TT), FileName, - loongarch::getEdgeKindName) {} + loongarch::getEdgeKindName, SSP) {} }; Error buildTables_ELF_loongarch(LinkGraph &G) { @@ -148,8 +149,8 @@ namespace llvm { namespace jitlink { -Expected> -createLinkGraphFromELFObject_loongarch(MemoryBufferRef ObjectBuffer) { +Expected> createLinkGraphFromELFObject_loongarch( + MemoryBufferRef ObjectBuffer, std::shared_ptr SSP) { LLVM_DEBUG({ dbgs() << "Building jitlink graph for new input " << ObjectBuffer.getBufferIdentifier() << "...\n"; @@ -163,7 +164,7 @@ auto &ELFObjFile = cast>(**ELFObj); return ELFLinkGraphBuilder_loongarch( (*ELFObj)->getFileName(), ELFObjFile.getELFFile(), - (*ELFObj)->makeTriple()) + (*ELFObj)->makeTriple(), SSP) .buildGraph(); } @@ -172,7 +173,7 @@ auto &ELFObjFile = cast>(**ELFObj); return ELFLinkGraphBuilder_loongarch( (*ELFObj)->getFileName(), ELFObjFile.getELFFile(), - (*ELFObj)->makeTriple()) + (*ELFObj)->makeTriple(), SSP) .buildGraph(); } diff --git a/llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp b/llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp --- a/llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp +++ b/llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp @@ -606,13 +606,15 @@ public: ELFLinkGraphBuilder_riscv(StringRef FileName, - const object::ELFFile &Obj, Triple TT) + const object::ELFFile &Obj, Triple TT, + std::shared_ptr SSP) : ELFLinkGraphBuilder(Obj, std::move(TT), FileName, - riscv::getEdgeKindName) {} + riscv::getEdgeKindName, SSP) {} }; Expected> -createLinkGraphFromELFObject_riscv(MemoryBufferRef ObjectBuffer) { +createLinkGraphFromELFObject_riscv(MemoryBufferRef ObjectBuffer, + std::shared_ptr SSP) { LLVM_DEBUG({ dbgs() << "Building jitlink graph for new input " << ObjectBuffer.getBufferIdentifier() << "...\n"; @@ -626,7 +628,7 @@ auto &ELFObjFile = cast>(**ELFObj); return ELFLinkGraphBuilder_riscv( (*ELFObj)->getFileName(), ELFObjFile.getELFFile(), - (*ELFObj)->makeTriple()) + (*ELFObj)->makeTriple(), SSP) .buildGraph(); } else { assert((*ELFObj)->getArch() == Triple::riscv32 && @@ -634,7 +636,7 @@ auto &ELFObjFile = cast>(**ELFObj); return ELFLinkGraphBuilder_riscv( (*ELFObj)->getFileName(), ELFObjFile.getELFFile(), - (*ELFObj)->makeTriple()) + (*ELFObj)->makeTriple(), SSP) .buildGraph(); } } diff --git a/llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp b/llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp --- a/llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp +++ b/llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp @@ -273,9 +273,10 @@ public: ELFLinkGraphBuilder_x86_64(StringRef FileName, - const object::ELFFile &Obj) + const object::ELFFile &Obj, + std::shared_ptr SSP) : ELFLinkGraphBuilder(Obj, Triple("x86_64-unknown-linux"), FileName, - x86_64::getEdgeKindName) {} + x86_64::getEdgeKindName, SSP) {} }; class ELFJITLinker_x86_64 : public JITLinker { @@ -292,12 +293,12 @@ private: Symbol *GOTSymbol = nullptr; - Error getOrCreateGOTSymbol(LinkGraph &G) { auto DefineExternalGOTSymbolIfPresent = createDefineExternalSectionStartAndEndSymbolsPass( [&](LinkGraph &LG, Symbol &Sym) -> SectionRangeSymbolDesc { - if (Sym.getName() == ELFGOTSymbolName) + if (Sym.getName() != nullptr && + *Sym.getName() == ELFGOTSymbolName) if (auto *GOTSection = G.findSectionByName( x86_64::GOTTableManager::getSectionName())) { GOTSymbol = &Sym; @@ -323,7 +324,7 @@ // Check for an existing defined symbol. for (auto *Sym : GOTSection->symbols()) - if (Sym->getName() == ELFGOTSymbolName) { + if (Sym->getName() != nullptr && *Sym->getName() == ELFGOTSymbolName) { GOTSymbol = Sym; return Error::success(); } @@ -348,8 +349,8 @@ } }; -Expected> -createLinkGraphFromELFObject_x86_64(MemoryBufferRef ObjectBuffer) { +Expected> createLinkGraphFromELFObject_x86_64( + MemoryBufferRef ObjectBuffer, std::shared_ptr SSP) { LLVM_DEBUG({ dbgs() << "Building jitlink graph for new input " << ObjectBuffer.getBufferIdentifier() << "...\n"; @@ -361,7 +362,7 @@ auto &ELFObjFile = cast>(**ELFObj); return ELFLinkGraphBuilder_x86_64((*ELFObj)->getFileName(), - ELFObjFile.getELFFile()) + ELFObjFile.getELFFile(), SSP) .buildGraph(); } @@ -370,7 +371,7 @@ constexpr StringRef StartSymbolPrefix = "__start"; constexpr StringRef EndSymbolPrefix = "__end"; - auto SymName = Sym.getName(); + auto SymName = *Sym.getName(); if (SymName.startswith(StartSymbolPrefix)) { if (auto *Sec = G.findSectionByName(SymName.drop_front(StartSymbolPrefix.size()))) diff --git a/llvm/lib/ExecutionEngine/JITLink/JITLink.cpp b/llvm/lib/ExecutionEngine/JITLink/JITLink.cpp --- a/llvm/lib/ExecutionEngine/JITLink/JITLink.cpp +++ b/llvm/lib/ExecutionEngine/JITLink/JITLink.cpp @@ -120,7 +120,7 @@ << ", linkage: " << formatv("{0:6}", getLinkageName(Sym.getLinkage())) << ", scope: " << formatv("{0:8}", getScopeName(Sym.getScope())) << ", " << (Sym.isLive() ? "live" : "dead") << " - " - << (Sym.hasName() ? Sym.getName() : ""); + << (Sym.hasName() ? *Sym.getName() : ""); return OS; } @@ -132,7 +132,7 @@ auto &TargetSym = E.getTarget(); if (TargetSym.hasName()) - OS << TargetSym.getName(); + OS << *TargetSym.getName(); else { auto &TargetBlock = TargetSym.getBlock(); auto &TargetSec = TargetBlock.getSection(); @@ -162,6 +162,15 @@ B->~Block(); } +LinkGraph::~LinkGraph() { + for (auto *Sym : ExternalSymbols) { + Sym->~Symbol(); + } + for (auto *Sym : AbsoluteSymbols) { + Sym->~Symbol(); + } +} + Block &LinkGraph::splitBlock(Block &B, size_t SplitIndex, SplitBlockCache *Cache) { @@ -310,7 +319,7 @@ OS << formatv("-{0:x8}", -E.getAddend()); OS << ", kind = " << getEdgeKindName(E.getKind()) << ", target = "; if (E.getTarget().hasName()) - OS << E.getTarget().getName(); + OS << *E.getTarget().getName(); else OS << "addressable@" << formatv("{0:x16}", E.getTarget().getAddress()) << "+" @@ -380,7 +389,7 @@ ErrStream << "In graph " << G.getName() << ", section " << Sec.getName() << ": relocation target "; if (E.getTarget().hasName()) { - ErrStream << "\"" << E.getTarget().getName() << "\""; + ErrStream << "\"" << *E.getTarget().getName() << "\""; } else ErrStream << E.getTarget().getBlock().getSection().getName() << " + " << formatv("{0:x}", E.getOffset()); @@ -397,7 +406,7 @@ BestSymbolForBlock = Sym; if (BestSymbolForBlock) - ErrStream << BestSymbolForBlock->getName() << ", "; + ErrStream << *BestSymbolForBlock->getName() << ", "; else ErrStream << " @ "; @@ -417,15 +426,16 @@ } Expected> -createLinkGraphFromObject(MemoryBufferRef ObjectBuffer) { +createLinkGraphFromObject(MemoryBufferRef ObjectBuffer, + std::shared_ptr SSP) { auto Magic = identify_magic(ObjectBuffer.getBuffer()); switch (Magic) { case file_magic::macho_object: - return createLinkGraphFromMachOObject(ObjectBuffer); + return createLinkGraphFromMachOObject(ObjectBuffer, SSP); case file_magic::elf_relocatable: - return createLinkGraphFromELFObject(ObjectBuffer); + return createLinkGraphFromELFObject(ObjectBuffer, SSP); case file_magic::coff_object: - return createLinkGraphFromCOFFObject(ObjectBuffer); + return createLinkGraphFromCOFFObject(ObjectBuffer, SSP); default: return make_error("Unsupported file format"); }; diff --git a/llvm/lib/ExecutionEngine/JITLink/JITLinkGeneric.cpp b/llvm/lib/ExecutionEngine/JITLink/JITLinkGeneric.cpp --- a/llvm/lib/ExecutionEngine/JITLink/JITLinkGeneric.cpp +++ b/llvm/lib/ExecutionEngine/JITLink/JITLinkGeneric.cpp @@ -200,8 +200,7 @@ for (auto *Sym : G->external_symbols()) { assert(!Sym->getAddress() && "External has already been assigned an address"); - assert(Sym->getName() != StringRef() && Sym->getName() != "" && - "Externals must be named"); + assert(Sym->getName() && "Externals must be named"); SymbolLookupFlags LookupFlags = Sym->isWeaklyReferenced() ? SymbolLookupFlags::WeaklyReferencedSymbol : SymbolLookupFlags::RequiredSymbol; @@ -231,7 +230,7 @@ LLVM_DEBUG({ dbgs() << "Externals after applying lookup result:\n"; for (auto *Sym : G->external_symbols()) { - dbgs() << " " << Sym->getName() << ": " + dbgs() << " " << *Sym->getName() << ": " << formatv("{0:x16}", Sym->getAddress().getValue()); switch (Sym->getLinkage()) { case Linkage::Strong: diff --git a/llvm/lib/ExecutionEngine/JITLink/JITLinkMemoryManager.cpp b/llvm/lib/ExecutionEngine/JITLink/JITLinkMemoryManager.cpp --- a/llvm/lib/ExecutionEngine/JITLink/JITLinkMemoryManager.cpp +++ b/llvm/lib/ExecutionEngine/JITLink/JITLinkMemoryManager.cpp @@ -156,7 +156,8 @@ "__--X.finalize", "__R-X.finalize", "__-WX.finalize", "__RWX.finalize"}; auto G = - std::make_unique("", Triple(), 0, support::native, nullptr); + std::make_unique("", std::shared_ptr(), + Triple(), 0, support::native, nullptr); orc::AllocGroupSmallMap ContentBlocks; orc::ExecutorAddr NextAddr(0x100000); diff --git a/llvm/lib/ExecutionEngine/JITLink/MachO.cpp b/llvm/lib/ExecutionEngine/JITLink/MachO.cpp --- a/llvm/lib/ExecutionEngine/JITLink/MachO.cpp +++ b/llvm/lib/ExecutionEngine/JITLink/MachO.cpp @@ -27,7 +27,8 @@ namespace jitlink { Expected> -createLinkGraphFromMachOObject(MemoryBufferRef ObjectBuffer) { +createLinkGraphFromMachOObject(MemoryBufferRef ObjectBuffer, + std::shared_ptr SSP) { StringRef Data = ObjectBuffer.getBuffer(); if (Data.size() < 4) return make_error("Truncated MachO buffer \"" + @@ -63,9 +64,9 @@ switch (CPUType) { case MachO::CPU_TYPE_ARM64: - return createLinkGraphFromMachOObject_arm64(ObjectBuffer); + return createLinkGraphFromMachOObject_arm64(ObjectBuffer, SSP); case MachO::CPU_TYPE_X86_64: - return createLinkGraphFromMachOObject_x86_64(ObjectBuffer); + return createLinkGraphFromMachOObject_x86_64(ObjectBuffer, SSP); } return make_error("MachO-64 CPU type not valid"); } else diff --git a/llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.h b/llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.h --- a/llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.h +++ b/llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.h @@ -35,8 +35,6 @@ struct NormalizedSymbol { friend class MachOLinkGraphBuilder; - - private: NormalizedSymbol(std::optional Name, uint64_t Value, uint8_t Type, uint8_t Sect, uint16_t Desc, Linkage L, Scope S) @@ -45,6 +43,7 @@ assert((!Name || !Name->empty()) && "Name must be none or non-empty"); } + private: public: NormalizedSymbol(const NormalizedSymbol &) = delete; NormalizedSymbol &operator=(const NormalizedSymbol &) = delete; @@ -84,7 +83,8 @@ using SectionParserFunction = std::function; MachOLinkGraphBuilder(const object::MachOObjectFile &Obj, Triple TT, - LinkGraph::GetEdgeKindNameFunction GetEdgeKindName); + LinkGraph::GetEdgeKindNameFunction GetEdgeKindName, + std::shared_ptr SSP); LinkGraph &getGraph() const { return *G; } diff --git a/llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.cpp b/llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.cpp --- a/llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.cpp +++ b/llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.cpp @@ -48,11 +48,13 @@ MachOLinkGraphBuilder::MachOLinkGraphBuilder( const object::MachOObjectFile &Obj, Triple TT, - LinkGraph::GetEdgeKindNameFunction GetEdgeKindName) + LinkGraph::GetEdgeKindNameFunction GetEdgeKindName, + std::shared_ptr SSP) : Obj(Obj), - G(std::make_unique( - std::string(Obj.getFileName()), std::move(TT), getPointerSize(Obj), - getEndianness(Obj), std::move(GetEdgeKindName))) { + G(std::make_unique(std::string(Obj.getFileName()), SSP, + std::move(TT), getPointerSize(Obj), + getEndianness(Obj), + std::move(GetEdgeKindName))) { auto &MachHeader = Obj.getHeader64(); SubsectionsViaSymbols = MachHeader.flags & MachO::MH_SUBSECTIONS_VIA_SYMBOLS; } @@ -315,9 +317,8 @@ } } - IndexToSymbol[SymbolIndex] = - &createNormalizedSymbol(*Name, Value, Type, Sect, Desc, - getLinkage(Desc), getScope(*Name, Type)); + IndexToSymbol[SymbolIndex] = &createNormalizedSymbol( + Name, Value, Type, Sect, Desc, getLinkage(Desc), getScope(*Name, Type)); } return Error::success(); @@ -583,7 +584,7 @@ if (!NSym.Name) dbgs() << ""; else - dbgs() << NSym.Name; + dbgs() << *NSym.Name; if (IsText) dbgs() << " [text]"; if (IsNoDeadStrip) @@ -722,7 +723,7 @@ LLVM_DEBUG({ dbgs() << " Adding symbol for c-string block " << B.getRange() << ": " - << (Sym.hasName() ? Sym.getName() : "") + << (Sym.hasName() ? *Sym.getName() : "") << " at offset " << formatv("{0:x}", Sym.getOffset()) << "\n"; }); @@ -820,7 +821,7 @@ LLVM_DEBUG({ dbgs() << " Updating compact unwind record at " << formatv("{0:x16}", CURec.getAddress()) << " to point to " - << (E.getTarget().hasName() ? E.getTarget().getName() + << (E.getTarget().hasName() ? *E.getTarget().getName() : StringRef()) << " (at " << formatv("{0:x16}", E.getTarget().getAddress()) << ")\n"; @@ -830,7 +831,7 @@ return make_error( "Error adding keep-alive edge for compact unwind record at " + formatv("{0:x}", CURec.getAddress()) + ": target " + - E.getTarget().getName() + " is an external symbol"); + *E.getTarget().getName() + " is an external symbol"); auto &TgtBlock = E.getTarget().getBlock(); auto &CURecSym = G.addAnonymousSymbol(CURec, 0, CURecordSize, false, false); diff --git a/llvm/lib/ExecutionEngine/JITLink/MachO_arm64.cpp b/llvm/lib/ExecutionEngine/JITLink/MachO_arm64.cpp --- a/llvm/lib/ExecutionEngine/JITLink/MachO_arm64.cpp +++ b/llvm/lib/ExecutionEngine/JITLink/MachO_arm64.cpp @@ -25,9 +25,10 @@ class MachOLinkGraphBuilder_arm64 : public MachOLinkGraphBuilder { public: - MachOLinkGraphBuilder_arm64(const object::MachOObjectFile &Obj) + MachOLinkGraphBuilder_arm64(const object::MachOObjectFile &Obj, + std::shared_ptr SSP) : MachOLinkGraphBuilder(Obj, Triple("arm64-apple-darwin"), - aarch64::getEdgeKindName), + aarch64::getEdgeKindName, SSP), NumSymbols(Obj.getSymtabLoadCommand().nsyms) {} private: @@ -536,12 +537,12 @@ uint64_t NullValue = 0; }; -Expected> -createLinkGraphFromMachOObject_arm64(MemoryBufferRef ObjectBuffer) { +Expected> createLinkGraphFromMachOObject_arm64( + MemoryBufferRef ObjectBuffer, std::shared_ptr SSP) { auto MachOObj = object::ObjectFile::createMachOObjectFile(ObjectBuffer); if (!MachOObj) return MachOObj.takeError(); - return MachOLinkGraphBuilder_arm64(**MachOObj).buildGraph(); + return MachOLinkGraphBuilder_arm64(**MachOObj, SSP).buildGraph(); } void link_MachO_arm64(std::unique_ptr G, diff --git a/llvm/lib/ExecutionEngine/JITLink/MachO_x86_64.cpp b/llvm/lib/ExecutionEngine/JITLink/MachO_x86_64.cpp --- a/llvm/lib/ExecutionEngine/JITLink/MachO_x86_64.cpp +++ b/llvm/lib/ExecutionEngine/JITLink/MachO_x86_64.cpp @@ -25,9 +25,10 @@ class MachOLinkGraphBuilder_x86_64 : public MachOLinkGraphBuilder { public: - MachOLinkGraphBuilder_x86_64(const object::MachOObjectFile &Obj) + MachOLinkGraphBuilder_x86_64(const object::MachOObjectFile &Obj, + std::shared_ptr SSP) : MachOLinkGraphBuilder(Obj, Triple("x86_64-apple-darwin"), - x86_64::getEdgeKindName) {} + x86_64::getEdgeKindName, SSP) {} private: enum MachONormalizedRelocationType : unsigned { @@ -461,12 +462,12 @@ } }; -Expected> -createLinkGraphFromMachOObject_x86_64(MemoryBufferRef ObjectBuffer) { +Expected> createLinkGraphFromMachOObject_x86_64( + MemoryBufferRef ObjectBuffer, std::shared_ptr SSP) { auto MachOObj = object::ObjectFile::createMachOObjectFile(ObjectBuffer); if (!MachOObj) return MachOObj.takeError(); - return MachOLinkGraphBuilder_x86_64(**MachOObj).buildGraph(); + return MachOLinkGraphBuilder_x86_64(**MachOObj, SSP).buildGraph(); } void link_MachO_x86_64(std::unique_ptr G, diff --git a/llvm/lib/ExecutionEngine/JITLink/PerGraphGOTAndPLTStubsBuilder.h b/llvm/lib/ExecutionEngine/JITLink/PerGraphGOTAndPLTStubsBuilder.h --- a/llvm/lib/ExecutionEngine/JITLink/PerGraphGOTAndPLTStubsBuilder.h +++ b/llvm/lib/ExecutionEngine/JITLink/PerGraphGOTAndPLTStubsBuilder.h @@ -76,7 +76,7 @@ if (GOTEntryI == GOTEntries.end()) { auto &GOTEntry = impl().createGOTEntry(Target); LLVM_DEBUG({ - dbgs() << " Created GOT entry for " << Target.getName() << ": " + dbgs() << " Created GOT entry for " << *Target.getName() << ": " << GOTEntry << "\n"; }); GOTEntryI = @@ -97,7 +97,7 @@ if (StubI == PLTStubs.end()) { auto &StubSymbol = impl().createPLTStub(Target); LLVM_DEBUG({ - dbgs() << " Created PLT stub for " << Target.getName() << ": " + dbgs() << " Created PLT stub for " << *Target.getName() << ": " << StubSymbol << "\n"; }); StubI = @@ -114,8 +114,8 @@ private: BuilderImplT &impl() { return static_cast(*this); } - DenseMap GOTEntries; - DenseMap PLTStubs; + DenseMap GOTEntries; + DenseMap PLTStubs; }; } // end namespace jitlink diff --git a/llvm/lib/ExecutionEngine/Orc/COFFPlatform.cpp b/llvm/lib/ExecutionEngine/Orc/COFFPlatform.cpp --- a/llvm/lib/ExecutionEngine/Orc/COFFPlatform.cpp +++ b/llvm/lib/ExecutionEngine/Orc/COFFPlatform.cpp @@ -67,8 +67,8 @@ } auto G = std::make_unique( - "", TT, PointerSize, Endianness, - jitlink::getGenericEdgeKindName); + "", CP.getExecutionSession().getSymbolStringPool(), TT, + PointerSize, Endianness, jitlink::getGenericEdgeKindName); auto &HeaderSection = G->createSection("__header", MemProt::Read); auto &HeaderBlock = createHeaderBlock(*G, HeaderSection); @@ -794,7 +794,7 @@ jitlink::LinkGraph &G, MaterializationResponsibility &MR, bool IsBootstraping) { auto I = llvm::find_if(G.defined_symbols(), [this](jitlink::Symbol *Sym) { - return Sym->getName() == *CP.COFFHeaderStartSymbol; + return *Sym->getName() == *CP.COFFHeaderStartSymbol; }); assert(I != G.defined_symbols().end() && "Missing COFF header start symbol"); diff --git a/llvm/lib/ExecutionEngine/Orc/ELFNixPlatform.cpp b/llvm/lib/ExecutionEngine/Orc/ELFNixPlatform.cpp --- a/llvm/lib/ExecutionEngine/Orc/ELFNixPlatform.cpp +++ b/llvm/lib/ExecutionEngine/Orc/ELFNixPlatform.cpp @@ -60,8 +60,8 @@ // void *__dso_handle = &__dso_handle; auto G = std::make_unique( - "", TT, PointerSize, Endianness, - jitlink::getGenericEdgeKindName); + "", ENP.getExecutionSession().getSymbolStringPool(), TT, + PointerSize, Endianness, jitlink::getGenericEdgeKindName); auto &DSOHandleSection = G->createSection(".data.__dso_handle", MemProt::Read); auto &DSOHandleBlock = G->createContentBlock( @@ -688,7 +688,7 @@ Config.PostAllocationPasses.push_back([this, &JD = MR.getTargetJITDylib()]( jitlink::LinkGraph &G) -> Error { auto I = llvm::find_if(G.defined_symbols(), [this](jitlink::Symbol *Sym) { - return Sym->getName() == *MP.DSOHandleSymbol; + return Sym->getName() == MP.DSOHandleSymbol; }); assert(I != G.defined_symbols().end() && "Missing DSO handle symbol"); { @@ -836,12 +836,17 @@ Error ELFNixPlatform::ELFNixPlatformPlugin::fixTLVSectionsAndEdges( jitlink::LinkGraph &G, JITDylib &JD) { - + auto TLSGetAddrSymbolName = G.intern("__tls_get_addr"); + auto TLSDescResolveSymbolName = G.intern("__tlsdesc_resolver"); for (auto *Sym : G.external_symbols()) { - if (Sym->getName() == "__tls_get_addr") { - Sym->setName("___orc_rt_elfnix_tls_get_addr"); - } else if (Sym->getName() == "__tlsdesc_resolver") { - Sym->setName("___orc_rt_elfnix_tlsdesc_resolver"); + if (Sym->getName() == TLSGetAddrSymbolName) { + auto TLSGetAddr = + MP.getExecutionSession().intern("___orc_rt_elfnix_tls_get_addr"); + Sym->setName(std::move(TLSGetAddr)); + } else if (Sym->getName() == TLSDescResolveSymbolName) { + auto TLSGetAddr = + MP.getExecutionSession().intern("___orc_rt_elfnix_tlsdesc_resolver"); + Sym->setName(std::move(TLSGetAddr)); } } diff --git a/llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp b/llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp --- a/llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp +++ b/llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp @@ -10,6 +10,7 @@ #include "llvm/ExecutionEngine/JITLink/x86_64.h" #include "llvm/ExecutionEngine/Orc/Layer.h" #include "llvm/ExecutionEngine/Orc/ObjectFileInterface.h" +#include "llvm/ExecutionEngine/Orc/SymbolStringPool.h" #include "llvm/IR/Constants.h" #include "llvm/IR/Function.h" #include "llvm/IR/GlobalVariable.h" @@ -561,8 +562,8 @@ return Endianness.takeError(); auto G = std::make_unique( - "", TT, *PointerSize, *Endianness, - jitlink::getGenericEdgeKindName); + "", ES.getSymbolStringPool(), TT, *PointerSize, + *Endianness, jitlink::getGenericEdgeKindName); jitlink::Section &Sec = G->createSection(getSectionName(), MemProt::Read | MemProt::Exec); @@ -574,9 +575,8 @@ // Create __imp_ symbol jitlink::Symbol &Ptr = jitlink::x86_64::createAnonymousPointer(*G, Sec, &Target); - auto NameCopy = G->allocateContent(Twine(getImpPrefix()) + *KV.first); - StringRef NameCopyRef = StringRef(NameCopy.data(), NameCopy.size()); - Ptr.setName(NameCopyRef); + auto name = getImpPrefix() + *KV.first; + Ptr.setName(G->intern(name.getSingleStringRef())); Ptr.setLinkage(jitlink::Linkage::Strong); Ptr.setScope(jitlink::Scope::Default); diff --git a/llvm/lib/ExecutionEngine/Orc/IndirectionUtils.cpp b/llvm/lib/ExecutionEngine/Orc/IndirectionUtils.cpp --- a/llvm/lib/ExecutionEngine/Orc/IndirectionUtils.cpp +++ b/llvm/lib/ExecutionEngine/Orc/IndirectionUtils.cpp @@ -416,7 +416,7 @@ auto SymSize = Sym.getSize() ? Sym.getSize() : B.getSize() - Sym.getOffset(); auto Content = ArrayRef(SymStartInBlock, SymSize); - LLVM_DEBUG(dbgs() << "Adding self-relocations to " << Sym.getName() << "\n"); + LLVM_DEBUG(dbgs() << "Adding self-relocations to " << *Sym.getName() << "\n"); SmallDenseSet ExistingRelocations; for (auto &E : B.edges()) { diff --git a/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp b/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp --- a/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp +++ b/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp @@ -75,9 +75,9 @@ llvm_unreachable("Unrecognized architecture"); } - return std::make_unique(std::move(Name), TT, PointerSize, - Endianness, - jitlink::getGenericEdgeKindName); + return std::make_unique( + std::move(Name), MOP.getExecutionSession().getSymbolStringPool(), TT, + PointerSize, Endianness, jitlink::getGenericEdgeKindName); } // Generates a MachO header. @@ -817,14 +817,14 @@ for (auto *Sym : G.defined_symbols()) { for (auto &RTSym : RuntimeSymbols) { - if (Sym->hasName() && Sym->getName() == RTSym.first) { + if (Sym->hasName() && *Sym->getName() == RTSym.first) { if (*RTSym.second) return make_error( "Duplicate " + RTSym.first + " detected during MachOPlatform bootstrap", inconvertibleErrorCode()); - if (Sym->getName() == *MP.MachOHeaderStartSymbol) + if (Sym->getName() == MP.MachOHeaderStartSymbol) RegisterMachOHeader = true; *RTSym.second = Sym->getAddress(); @@ -860,7 +860,7 @@ Error MachOPlatform::MachOPlatformPlugin::associateJITDylibHeaderSymbol( jitlink::LinkGraph &G, MaterializationResponsibility &MR) { auto I = llvm::find_if(G.defined_symbols(), [this](jitlink::Symbol *Sym) { - return Sym->getName() == *MP.MachOHeaderStartSymbol; + return Sym->getName() == MP.MachOHeaderStartSymbol; }); assert(I != G.defined_symbols().end() && "Missing MachO header start symbol"); @@ -997,11 +997,13 @@ Error MachOPlatform::MachOPlatformPlugin::fixTLVSectionsAndEdges( jitlink::LinkGraph &G, JITDylib &JD) { - + auto TLVBootStrapSymbolName = G.intern("__tlv_bootstrap"); // Rename external references to __tlv_bootstrap to ___orc_rt_tlv_get_addr. for (auto *Sym : G.external_symbols()) - if (Sym->getName() == "__tlv_bootstrap") { - Sym->setName("___orc_rt_macho_tlv_get_addr"); + if (Sym->getName() == TLVBootStrapSymbolName) { + auto TLSGetADDR = + MP.getExecutionSession().intern("___orc_rt_macho_tlv_get_addr"); + Sym->setName(std::move(TLSGetADDR)); break; } diff --git a/llvm/lib/ExecutionEngine/Orc/ObjectFileInterface.cpp b/llvm/lib/ExecutionEngine/Orc/ObjectFileInterface.cpp --- a/llvm/lib/ExecutionEngine/Orc/ObjectFileInterface.cpp +++ b/llvm/lib/ExecutionEngine/Orc/ObjectFileInterface.cpp @@ -133,7 +133,7 @@ if (Sym.getBinding() == ELF::STB_GNU_UNIQUE) *SymFlags |= JITSymbolFlags::Weak; - I.SymbolFlags[ES.intern(*Name)] = std::move(*SymFlags); + I.SymbolFlags[ES.intern(std::move(*Name))] = std::move(*SymFlags); } SymbolStringPtr InitSymbol; diff --git a/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp b/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp --- a/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp +++ b/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp @@ -99,8 +99,7 @@ continue; assert(Sym->hasName() && "Anonymous non-local symbol?"); - LGI.SymbolFlags[ES.intern(Sym->getName())] = - getJITSymbolFlagsForSymbol(*Sym); + LGI.SymbolFlags[Sym->getName()] = getJITSymbolFlagsForSymbol(*Sym); } if (hasInitializerSection(G)) @@ -123,7 +122,7 @@ void discard(const JITDylib &JD, const SymbolStringPtr &Name) override { for (auto *Sym : G->defined_symbols()) - if (Sym->getName() == *Name) { + if (Sym->getName() == Name) { assert(Sym->getLinkage() == Linkage::Weak && "Discarding non-weak definition"); G->makeExternal(*Sym); @@ -195,7 +194,7 @@ LookupFlags = orc::SymbolLookupFlags::WeaklyReferencedSymbol; break; } - LookupSet.add(ES.intern(KV.first), LookupFlags); + LookupSet.add(KV.first, LookupFlags); } // OnResolve -- De-intern the symbols and pass the result to the linker. @@ -206,7 +205,7 @@ else { AsyncLookupResult LR; for (auto &KV : *Result) - LR[*KV.first] = KV.second; + LR[KV.first] = KV.second; LookupContinuation->run(std::move(LR)); } }; @@ -225,7 +224,6 @@ } Error notifyResolved(LinkGraph &G) override { - auto &ES = Layer.getExecutionSession(); SymbolFlagsMap ExtraSymbolsToClaim; bool AutoClaim = Layer.AutoClaimObjectSymbols; @@ -233,27 +231,25 @@ SymbolMap InternedResult; for (auto *Sym : G.defined_symbols()) if (Sym->hasName() && Sym->getScope() != Scope::Local) { - auto InternedName = ES.intern(Sym->getName()); auto Ptr = getJITSymbolPtrForSymbol(*Sym, G.getTargetTriple()); auto Flags = getJITSymbolFlagsForSymbol(*Sym); - InternedResult[InternedName] = {Ptr, Flags}; - if (AutoClaim && !MR->getSymbols().count(InternedName)) { - assert(!ExtraSymbolsToClaim.count(InternedName) && + InternedResult[Sym->getName()] = {Ptr, Flags}; + if (AutoClaim && !MR->getSymbols().count(Sym->getName())) { + assert(!ExtraSymbolsToClaim.count(Sym->getName()) && "Duplicate symbol to claim?"); - ExtraSymbolsToClaim[InternedName] = Flags; + ExtraSymbolsToClaim[Sym->getName()] = Flags; } } for (auto *Sym : G.absolute_symbols()) if (Sym->hasName() && Sym->getScope() != Scope::Local) { - auto InternedName = ES.intern(Sym->getName()); auto Ptr = getJITSymbolPtrForSymbol(*Sym, G.getTargetTriple()); auto Flags = getJITSymbolFlagsForSymbol(*Sym); - InternedResult[InternedName] = {Ptr, Flags}; - if (AutoClaim && !MR->getSymbols().count(InternedName)) { - assert(!ExtraSymbolsToClaim.count(InternedName) && + InternedResult[Sym->getName()] = {Ptr, Flags}; + if (AutoClaim && !MR->getSymbols().count(Sym->getName())) { + assert(!ExtraSymbolsToClaim.count(Sym->getName()) && "Duplicate symbol to claim?"); - ExtraSymbolsToClaim[InternedName] = Flags; + ExtraSymbolsToClaim[Sym->getName()] = Flags; } } @@ -362,7 +358,7 @@ public: BlockDependenciesMap(ExecutionSession &ES, DenseMap> BlockDeps) - : ES(ES), BlockDeps(std::move(BlockDeps)) {} + : BlockDeps(std::move(BlockDeps)) {} const BlockSymbolDependencies &operator[](const Block &B) { // Check the cache first. @@ -393,7 +389,7 @@ if (I != NameCache.end()) return I->second; - return NameCache.insert(std::make_pair(&Sym, ES.intern(Sym.getName()))) + return NameCache.insert(std::make_pair(&Sym, Sym.getName())) .first->second; } @@ -420,7 +416,6 @@ .first->second; } - ExecutionSession &ES; DenseMap> BlockDeps; DenseMap NameCache; DenseMap BlockImmediateDepsCache; @@ -428,19 +423,16 @@ }; Error claimOrExternalizeWeakAndCommonSymbols(LinkGraph &G) { - auto &ES = Layer.getExecutionSession(); - SymbolFlagsMap NewSymbolsToClaim; std::vector> NameToSym; auto ProcessSymbol = [&](Symbol *Sym) { if (Sym->hasName() && Sym->getLinkage() == Linkage::Weak && Sym->getScope() != Scope::Local) { - auto Name = ES.intern(Sym->getName()); - if (!MR->getSymbols().count(ES.intern(Sym->getName()))) { - NewSymbolsToClaim[Name] = + if (!MR->getSymbols().count(Sym->getName())) { + NewSymbolsToClaim[Sym->getName()] = getJITSymbolFlagsForSymbol(*Sym) | JITSymbolFlags::Weak; - NameToSym.push_back(std::make_pair(std::move(Name), Sym)); + NameToSym.push_back(std::make_pair(Sym->getName(), Sym)); } } }; @@ -469,15 +461,13 @@ } Error markResponsibilitySymbolsLive(LinkGraph &G) const { - auto &ES = Layer.getExecutionSession(); for (auto *Sym : G.defined_symbols()) - if (Sym->hasName() && MR->getSymbols().count(ES.intern(Sym->getName()))) + if (Sym->hasName() && MR->getSymbols().count(Sym->getName())) Sym->setLive(true); return Error::success(); } Error computeNamedSymbolDependencies(LinkGraph &G) { - auto &ES = MR->getTargetJITDylib().getExecutionSession(); auto BlockDeps = computeBlockNonLocalDeps(G); // Compute dependencies for symbols defined in the JITLink graph. @@ -493,7 +483,7 @@ if (SymDeps.External.empty() && SymDeps.Internal.empty()) continue; - auto SymName = ES.intern(Sym->getName()); + auto SymName = Sym->getName(); if (!SymDeps.External.empty()) ExternalNamedSymbolDeps[SymName] = SymDeps.External; if (!SymDeps.Internal.empty()) @@ -668,7 +658,7 @@ auto Ctx = std::make_unique( *this, std::move(R), std::move(O)); - if (auto G = createLinkGraphFromObject(ObjBuffer)) { + if (auto G = createLinkGraphFromObject(ObjBuffer, ES.getSymbolStringPool())) { Ctx->notifyMaterializing(**G); link(std::move(*G), std::move(Ctx)); } else { diff --git a/llvm/tools/llvm-jitlink/llvm-jitlink-coff.cpp b/llvm/tools/llvm-jitlink/llvm-jitlink-coff.cpp --- a/llvm/tools/llvm-jitlink/llvm-jitlink-coff.cpp +++ b/llvm/tools/llvm-jitlink/llvm-jitlink-coff.cpp @@ -117,7 +117,7 @@ // then add it to the GOT entry info table. if (Sym->getSize() != 0) { if (auto TS = getCOFFGOTTarget(G, Sym->getBlock())) - FileInfo.GOTEntryInfos[TS->getName()] = { + FileInfo.GOTEntryInfos[*TS->getName()] = { Sym->getSymbolContent(), Sym->getAddress().getValue()}; else return TS.takeError(); @@ -129,8 +129,8 @@ inconvertibleErrorCode()); if (auto TS = getCOFFStubTarget(G, Sym->getBlock())) - FileInfo.StubInfos[TS->getName()] = {Sym->getSymbolContent(), - Sym->getAddress().getValue()}; + FileInfo.StubInfos[*TS->getName()] = {Sym->getSymbolContent(), + Sym->getAddress().getValue()}; else return TS.takeError(); SectionContainsContent = true; @@ -138,12 +138,12 @@ if (Sym->hasName()) { if (Sym->isSymbolZeroFill()) { - S.SymbolInfos[Sym->getName()] = {Sym->getSize(), - Sym->getAddress().getValue()}; + S.SymbolInfos[*Sym->getName()] = {Sym->getSize(), + Sym->getAddress().getValue()}; SectionContainsZeroFill = true; } else { - S.SymbolInfos[Sym->getName()] = {Sym->getSymbolContent(), - Sym->getAddress().getValue()}; + S.SymbolInfos[*Sym->getName()] = {Sym->getSymbolContent(), + Sym->getAddress().getValue()}; SectionContainsContent = true; } } diff --git a/llvm/tools/llvm-jitlink/llvm-jitlink-elf.cpp b/llvm/tools/llvm-jitlink/llvm-jitlink-elf.cpp --- a/llvm/tools/llvm-jitlink/llvm-jitlink-elf.cpp +++ b/llvm/tools/llvm-jitlink/llvm-jitlink-elf.cpp @@ -119,7 +119,7 @@ // then add it to the GOT entry info table. if (Sym->getSize() != 0) { if (auto TS = getELFGOTTarget(G, Sym->getBlock())) - FileInfo.GOTEntryInfos[TS->getName()] = { + FileInfo.GOTEntryInfos[*TS->getName()] = { Sym->getSymbolContent(), Sym->getAddress().getValue()}; else return TS.takeError(); @@ -131,8 +131,8 @@ inconvertibleErrorCode()); if (auto TS = getELFStubTarget(G, Sym->getBlock())) - FileInfo.StubInfos[TS->getName()] = {Sym->getSymbolContent(), - Sym->getAddress().getValue()}; + FileInfo.StubInfos[*TS->getName()] = {Sym->getSymbolContent(), + Sym->getAddress().getValue()}; else return TS.takeError(); SectionContainsContent = true; @@ -140,12 +140,12 @@ if (Sym->hasName()) { if (Sym->isSymbolZeroFill()) { - S.SymbolInfos[Sym->getName()] = {Sym->getSize(), - Sym->getAddress().getValue()}; + S.SymbolInfos[*Sym->getName()] = {Sym->getSize(), + Sym->getAddress().getValue()}; SectionContainsZeroFill = true; } else { - S.SymbolInfos[Sym->getName()] = {Sym->getSymbolContent(), - Sym->getAddress().getValue()}; + S.SymbolInfos[*Sym->getName()] = {Sym->getSymbolContent(), + Sym->getAddress().getValue()}; SectionContainsContent = true; } } diff --git a/llvm/tools/llvm-jitlink/llvm-jitlink-macho.cpp b/llvm/tools/llvm-jitlink/llvm-jitlink-macho.cpp --- a/llvm/tools/llvm-jitlink/llvm-jitlink-macho.cpp +++ b/llvm/tools/llvm-jitlink/llvm-jitlink-macho.cpp @@ -117,7 +117,7 @@ inconvertibleErrorCode()); if (auto TS = getMachOGOTTarget(G, Sym->getBlock())) - FileInfo.GOTEntryInfos[TS->getName()] = { + FileInfo.GOTEntryInfos[*TS->getName()] = { Sym->getSymbolContent(), Sym->getAddress().getValue()}; else return TS.takeError(); @@ -128,19 +128,19 @@ inconvertibleErrorCode()); if (auto TS = getMachOStubTarget(G, Sym->getBlock())) - FileInfo.StubInfos[TS->getName()] = {Sym->getSymbolContent(), - Sym->getAddress().getValue()}; + FileInfo.StubInfos[*TS->getName()] = {Sym->getSymbolContent(), + Sym->getAddress().getValue()}; else return TS.takeError(); SectionContainsContent = true; } else if (Sym->hasName()) { if (Sym->isSymbolZeroFill()) { - S.SymbolInfos[Sym->getName()] = {Sym->getSize(), - Sym->getAddress().getValue()}; + S.SymbolInfos[*Sym->getName()] = {Sym->getSize(), + Sym->getAddress().getValue()}; SectionContainsZeroFill = true; } else { - S.SymbolInfos[Sym->getName()] = {Sym->getSymbolContent(), - Sym->getAddress().getValue()}; + S.SymbolInfos[*Sym->getName()] = {Sym->getSymbolContent(), + Sym->getAddress().getValue()}; SectionContainsContent = true; } } diff --git a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp --- a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp +++ b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp @@ -355,29 +355,29 @@ continue; if (Sym->getLinkage() == Linkage::Weak) { - if (!S.CanonicalWeakDefs.count(Sym->getName()) || - S.CanonicalWeakDefs[Sym->getName()] != G.getName()) { + if (!S.CanonicalWeakDefs.count(*Sym->getName()) || + S.CanonicalWeakDefs[*Sym->getName()] != G.getName()) { LLVM_DEBUG({ - dbgs() << " Externalizing weak symbol " << Sym->getName() << "\n"; + dbgs() << " Externalizing weak symbol " << *Sym->getName() << "\n"; }); DefinitionsToRemove.push_back(Sym); } else { LLVM_DEBUG({ - dbgs() << " Making weak symbol " << Sym->getName() << " strong\n"; + dbgs() << " Making weak symbol " << *Sym->getName() << " strong\n"; }); - if (S.HarnessExternals.count(Sym->getName())) + if (S.HarnessExternals.count(*Sym->getName())) Sym->setScope(Scope::Default); else Sym->setScope(Scope::Hidden); Sym->setLinkage(Linkage::Strong); } - } else if (S.HarnessExternals.count(Sym->getName())) { - LLVM_DEBUG(dbgs() << " Promoting " << Sym->getName() << "\n"); + } else if (S.HarnessExternals.count(*Sym->getName())) { + LLVM_DEBUG(dbgs() << " Promoting " << *Sym->getName() << "\n"); Sym->setScope(Scope::Default); Sym->setLive(true); continue; - } else if (S.HarnessDefinitions.count(Sym->getName())) { - LLVM_DEBUG(dbgs() << " Externalizing " << Sym->getName() << "\n"); + } else if (S.HarnessDefinitions.count(*Sym->getName())) { + LLVM_DEBUG(dbgs() << " Externalizing " << *Sym->getName() << "\n"); DefinitionsToRemove.push_back(Sym); } } diff --git a/llvm/unittests/ExecutionEngine/JITLink/EHFrameSupportTests.cpp b/llvm/unittests/ExecutionEngine/JITLink/EHFrameSupportTests.cpp --- a/llvm/unittests/ExecutionEngine/JITLink/EHFrameSupportTests.cpp +++ b/llvm/unittests/ExecutionEngine/JITLink/EHFrameSupportTests.cpp @@ -210,7 +210,7 @@ ASSERT_TRUE(!!CFIBI.getPCBeginEdge()); auto &PCBeginTarget = CFIBI.getPCBeginEdge()->getTarget(); ASSERT_TRUE(PCBeginTarget.hasName()); - Targets.insert(PCBeginTarget.getName()); + Targets.insert(*PCBeginTarget.getName()); // If the FDE points at CIEs[0] (the CIE without a personality) then it // should not have an LSDA. If it points to CIEs[1] then it should have @@ -235,7 +235,7 @@ // Make '_a' external. for (auto *Sym : G->defined_symbols()) - if (Sym->hasName() && Sym->getName() == "_a") { + if (Sym->hasName() && *Sym->getName() == "_a") { G->makeExternal(*Sym); break; } diff --git a/llvm/unittests/ExecutionEngine/JITLink/LinkGraphTests.cpp b/llvm/unittests/ExecutionEngine/JITLink/LinkGraphTests.cpp --- a/llvm/unittests/ExecutionEngine/JITLink/LinkGraphTests.cpp +++ b/llvm/unittests/ExecutionEngine/JITLink/LinkGraphTests.cpp @@ -9,6 +9,7 @@ #include "llvm/ADT/STLExtras.h" #include "llvm/ExecutionEngine/JITLink/JITLink.h" #include "llvm/ExecutionEngine/Orc/ObjectFileInterface.h" +#include "llvm/ExecutionEngine/Orc/SymbolStringPool.h" #include "llvm/Support/Endian.h" #include "llvm/Support/Memory.h" @@ -61,7 +62,8 @@ TEST(LinkGraphTest, Construction) { // Check that LinkGraph construction works as expected. - LinkGraph G("foo", Triple("x86_64-apple-darwin"), 8, support::little, + LinkGraph G("foo", std::make_shared(), + Triple("x86_64-apple-darwin"), 8, support::little, getGenericEdgeKindName); EXPECT_EQ(G.getName(), "foo"); EXPECT_EQ(G.getTargetTriple().str(), "x86_64-apple-darwin"); @@ -75,7 +77,8 @@ TEST(LinkGraphTest, AddressAccess) { // Check that we can get addresses for blocks, symbols, and edges. - LinkGraph G("foo", Triple("x86_64-apple-darwin"), 8, support::little, + LinkGraph G("foo", std::make_shared(), + Triple("x86_64-apple-darwin"), 8, support::little, getGenericEdgeKindName); auto &Sec1 = @@ -94,7 +97,8 @@ TEST(LinkGraphTest, SectionEmpty) { // Check that Section::empty behaves as expected. - LinkGraph G("foo", Triple("x86_64-apple-darwin"), 8, support::little, + LinkGraph G("foo", std::make_shared(), + Triple("x86_64-apple-darwin"), 8, support::little, getGenericEdgeKindName); auto &Sec1 = G.createSection("__data.1", orc::MemProt::Read | orc::MemProt::Write); @@ -112,7 +116,8 @@ TEST(LinkGraphTest, BlockAndSymbolIteration) { // Check that we can iterate over blocks within Sections and across sections. - LinkGraph G("foo", Triple("x86_64-apple-darwin"), 8, support::little, + LinkGraph G("foo", std::make_shared(), + Triple("x86_64-apple-darwin"), 8, support::little, getGenericEdgeKindName); auto &Sec1 = G.createSection("__data.1", orc::MemProt::Read | orc::MemProt::Write); @@ -165,7 +170,8 @@ TEST(LinkGraphTest, ContentAccessAndUpdate) { // Check that we can make a defined symbol external. - LinkGraph G("foo", Triple("x86_64-apple-darwin"), 8, support::little, + LinkGraph G("foo", std::make_shared(), + Triple("x86_64-apple-darwin"), 8, support::little, getGenericEdgeKindName); auto &Sec = G.createSection("__data", orc::MemProt::Read | orc::MemProt::Write); @@ -245,7 +251,8 @@ TEST(LinkGraphTest, MakeExternal) { // Check that we can make defined and absolute symbols external. - LinkGraph G("foo", Triple("x86_64-apple-darwin"), 8, support::little, + LinkGraph G("foo", std::make_shared(), + Triple("x86_64-apple-darwin"), 8, support::little, getGenericEdgeKindName); auto &Sec = G.createSection("__data", orc::MemProt::Read | orc::MemProt::Write); @@ -315,7 +322,8 @@ TEST(LinkGraphTest, MakeAbsolute) { // Check that we can make defined and external symbols absolute. - LinkGraph G("foo", Triple("x86_64-apple-darwin"), 8, support::little, + LinkGraph G("foo", std::make_shared(), + Triple("x86_64-apple-darwin"), 8, support::little, getGenericEdgeKindName); auto &Sec = G.createSection("__data", orc::MemProt::Read | orc::MemProt::Write); @@ -384,7 +392,8 @@ TEST(LinkGraphTest, MakeDefined) { // Check that we can make an external symbol defined. - LinkGraph G("foo", Triple("x86_64-apple-darwin"), 8, support::little, + LinkGraph G("foo", std::make_shared(), + Triple("x86_64-apple-darwin"), 8, support::little, getGenericEdgeKindName); auto &Sec = G.createSection("__data", orc::MemProt::Read | orc::MemProt::Write); @@ -432,7 +441,8 @@ TEST(LinkGraphTest, TransferDefinedSymbol) { // Check that we can transfer a defined symbol from one block to another. - LinkGraph G("foo", Triple("x86_64-apple-darwin"), 8, support::little, + LinkGraph G("foo", std::make_shared(), + Triple("x86_64-apple-darwin"), 8, support::little, getGenericEdgeKindName); auto &Sec = G.createSection("__data", orc::MemProt::Read | orc::MemProt::Write); @@ -467,7 +477,8 @@ TEST(LinkGraphTest, TransferDefinedSymbolAcrossSections) { // Check that we can transfer a defined symbol from an existing block in one // section to another. - LinkGraph G("foo", Triple("x86_64-apple-darwin"), 8, support::little, + LinkGraph G("foo", std::make_shared(), + Triple("x86_64-apple-darwin"), 8, support::little, getGenericEdgeKindName); auto &Sec1 = G.createSection("__data.1", orc::MemProt::Read | orc::MemProt::Write); @@ -501,7 +512,8 @@ TEST(LinkGraphTest, TransferBlock) { // Check that we can transfer a block (and all associated symbols) from one // section to another. - LinkGraph G("foo", Triple("x86_64-apple-darwin"), 8, support::little, + LinkGraph G("foo", std::make_shared(), + Triple("x86_64-apple-darwin"), 8, support::little, getGenericEdgeKindName); auto &Sec1 = G.createSection("__data.1", orc::MemProt::Read | orc::MemProt::Write); @@ -549,7 +561,8 @@ TEST(LinkGraphTest, MergeSections) { // Check that we can transfer a block (and all associated symbols) from one // section to another. - LinkGraph G("foo", Triple("x86_64-apple-darwin"), 8, support::little, + LinkGraph G("foo", std::make_shared(), + Triple("x86_64-apple-darwin"), 8, support::little, getGenericEdgeKindName); auto &Sec1 = G.createSection("__data.1", orc::MemProt::Read | orc::MemProt::Write); @@ -635,7 +648,8 @@ TEST(LinkGraphTest, SplitBlock) { // Check that the LinkGraph::splitBlock test works as expected. - LinkGraph G("foo", Triple("x86_64-apple-darwin"), 8, support::little, + LinkGraph G("foo", std::make_shared(), + Triple("x86_64-apple-darwin"), 8, support::little, getGenericEdgeKindName); auto &Sec = G.createSection("__data", orc::MemProt::Read | orc::MemProt::Write); @@ -731,7 +745,8 @@ } TEST(LinkGraphTest, GraphAllocationMethods) { - LinkGraph G("foo", Triple("x86_64-apple-darwin"), 8, support::little, + LinkGraph G("foo", std::make_shared(), + Triple("x86_64-apple-darwin"), 8, support::little, getGenericEdgeKindName); // Test allocation of sized, uninitialized buffer. @@ -752,7 +767,8 @@ TEST(LinkGraphTest, IsCStringBlockTest) { // Check that the LinkGraph::splitBlock test works as expected. - LinkGraph G("foo", Triple("x86_64-apple-darwin"), 8, support::little, + LinkGraph G("foo", std::make_shared(), + Triple("x86_64-apple-darwin"), 8, support::little, getGenericEdgeKindName); auto &Sec = G.createSection("__data", orc::MemProt::Read | orc::MemProt::Write); @@ -777,7 +793,8 @@ TEST(LinkGraphTest, BasicLayoutHonorsNoAlloc) { // Check that BasicLayout honors NoAlloc. - LinkGraph G("foo", Triple("x86_64-apple-darwin"), 8, support::little, + LinkGraph G("foo", std::make_shared(), + Triple("x86_64-apple-darwin"), 8, support::little, getGenericEdgeKindName); // Create a regular section and block. diff --git a/llvm/unittests/ExecutionEngine/Orc/ObjectLinkingLayerTest.cpp b/llvm/unittests/ExecutionEngine/Orc/ObjectLinkingLayerTest.cpp --- a/llvm/unittests/ExecutionEngine/Orc/ObjectLinkingLayerTest.cpp +++ b/llvm/unittests/ExecutionEngine/Orc/ObjectLinkingLayerTest.cpp @@ -39,9 +39,10 @@ }; TEST_F(ObjectLinkingLayerTest, AddLinkGraph) { - auto G = - std::make_unique("foo", Triple("x86_64-apple-darwin"), 8, - support::little, x86_64::getEdgeKindName); + auto G = std::make_unique( + "foo", std::make_shared(), + Triple("x86_64-apple-darwin"), 8, support::little, + x86_64::getEdgeKindName); auto &Sec1 = G->createSection("__data", MemProt::Read | MemProt::Write); auto &B1 = G->createContentBlock(Sec1, BlockContent, @@ -104,9 +105,10 @@ ObjLinkingLayer.addPlugin(std::make_unique()); - auto G = - std::make_unique("foo", Triple("x86_64-apple-darwin"), 8, - support::little, x86_64::getEdgeKindName); + auto G = std::make_unique( + "foo", std::make_shared(), + Triple("x86_64-apple-darwin"), 8, support::little, + x86_64::getEdgeKindName); auto &DataSec = G->createSection("__data", MemProt::Read | MemProt::Write); auto &DataBlock = G->createContentBlock(DataSec, BlockContent, @@ -158,9 +160,10 @@ ObjLinkingLayer.addPlugin(std::make_unique()); - auto G = - std::make_unique("foo", Triple("x86_64-apple-darwin"), 8, - support::little, x86_64::getEdgeKindName); + auto G = std::make_unique( + "foo", std::make_shared(), + Triple("x86_64-apple-darwin"), 8, support::little, + x86_64::getEdgeKindName); auto &DataSec = G->createSection("__data", MemProt::Read | MemProt::Write); auto &DataBlock = G->createContentBlock(DataSec, BlockContent,