[llvm] Move a lot of symbol code to use the symbol string pool (PR #115796)

via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 11 17:15:50 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-risc-v

Author: Jared Wyles (jaredwy)

<details>
<summary>Changes</summary>

Largely just feeding the Symbol pool through various points it needs to go. This is a first phase to get it in, going to dig in and start to use the pool in further patches.

---

Patch is 154.89 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/115796.diff


67 Files Affected:

- (modified) .gitignore (+2) 
- (modified) llvm/include/llvm/ExecutionEngine/JITLink/COFF.h (+2-1) 
- (modified) llvm/include/llvm/ExecutionEngine/JITLink/COFF_x86_64.h (+2-2) 
- (modified) llvm/include/llvm/ExecutionEngine/JITLink/ELF.h (+2-1) 
- (modified) llvm/include/llvm/ExecutionEngine/JITLink/ELF_aarch32.h (+2-2) 
- (modified) llvm/include/llvm/ExecutionEngine/JITLink/ELF_aarch64.h (+2-2) 
- (modified) llvm/include/llvm/ExecutionEngine/JITLink/ELF_i386.h (+2-1) 
- (modified) llvm/include/llvm/ExecutionEngine/JITLink/ELF_loongarch.h (+2-2) 
- (modified) llvm/include/llvm/ExecutionEngine/JITLink/ELF_ppc64.h (+4-3) 
- (modified) llvm/include/llvm/ExecutionEngine/JITLink/ELF_riscv.h (+2-1) 
- (modified) llvm/include/llvm/ExecutionEngine/JITLink/ELF_x86_64.h (+2-1) 
- (modified) llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h (+111-52) 
- (modified) llvm/include/llvm/ExecutionEngine/JITLink/MachO.h (+2-1) 
- (modified) llvm/include/llvm/ExecutionEngine/JITLink/MachO_arm64.h (+2-2) 
- (modified) llvm/include/llvm/ExecutionEngine/JITLink/MachO_x86_64.h (+2-2) 
- (modified) llvm/include/llvm/ExecutionEngine/JITLink/TableManager.h (+2-2) 
- (modified) llvm/include/llvm/ExecutionEngine/Orc/Core.h (+2-2) 
- (modified) llvm/include/llvm/ExecutionEngine/RuntimeDyldChecker.h (+2-1) 
- (modified) llvm/lib/ExecutionEngine/JITLink/COFF.cpp (+3-2) 
- (modified) llvm/lib/ExecutionEngine/JITLink/COFFLinkGraphBuilder.cpp (+50-35) 
- (modified) llvm/lib/ExecutionEngine/JITLink/COFFLinkGraphBuilder.h (+11-9) 
- (modified) llvm/lib/ExecutionEngine/JITLink/COFF_x86_64.cpp (+17-10) 
- (modified) llvm/lib/ExecutionEngine/JITLink/DefineExternalSectionStartAndEndSymbols.h (+9-9) 
- (modified) llvm/lib/ExecutionEngine/JITLink/EHFrameSupport.cpp (+3-3) 
- (modified) llvm/lib/ExecutionEngine/JITLink/ELF.cpp (+11-10) 
- (modified) llvm/lib/ExecutionEngine/JITLink/ELFLinkGraphBuilder.h (+8-6) 
- (modified) llvm/lib/ExecutionEngine/JITLink/ELF_aarch32.cpp (+8-7) 
- (modified) llvm/lib/ExecutionEngine/JITLink/ELF_aarch64.cpp (+17-11) 
- (modified) llvm/lib/ExecutionEngine/JITLink/ELF_i386.cpp (+9-5) 
- (modified) llvm/lib/ExecutionEngine/JITLink/ELF_loongarch.cpp (+10-8) 
- (modified) llvm/lib/ExecutionEngine/JITLink/ELF_ppc64.cpp (+20-15) 
- (modified) llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp (+8-6) 
- (modified) llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp (+9-8) 
- (modified) llvm/lib/ExecutionEngine/JITLink/JITLink.cpp (+25-12) 
- (modified) llvm/lib/ExecutionEngine/JITLink/JITLinkGeneric.cpp (+2-3) 
- (modified) llvm/lib/ExecutionEngine/JITLink/JITLinkMemoryManager.cpp (+3-2) 
- (modified) llvm/lib/ExecutionEngine/JITLink/MachO.cpp (+4-3) 
- (modified) llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.cpp (+11-10) 
- (modified) llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.h (+3-4) 
- (modified) llvm/lib/ExecutionEngine/JITLink/MachO_arm64.cpp (+6-5) 
- (modified) llvm/lib/ExecutionEngine/JITLink/MachO_x86_64.cpp (+5-4) 
- (modified) llvm/lib/ExecutionEngine/JITLink/PerGraphGOTAndPLTStubsBuilder.h (+4-4) 
- (modified) llvm/lib/ExecutionEngine/JITLink/aarch32.cpp (+4-4) 
- (modified) llvm/lib/ExecutionEngine/Orc/COFFPlatform.cpp (+3-3) 
- (modified) llvm/lib/ExecutionEngine/Orc/Debugging/DebuggerSupportPlugin.cpp (+2-2) 
- (modified) llvm/lib/ExecutionEngine/Orc/Debugging/PerfSupportPlugin.cpp (+2-2) 
- (modified) llvm/lib/ExecutionEngine/Orc/Debugging/VTuneSupportPlugin.cpp (+1-1) 
- (modified) llvm/lib/ExecutionEngine/Orc/ELFNixPlatform.cpp (+18-13) 
- (modified) llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp (+5-5) 
- (modified) llvm/lib/ExecutionEngine/Orc/IndirectionUtils.cpp (+1-1) 
- (modified) llvm/lib/ExecutionEngine/Orc/JITLinkRedirectableSymbolManager.cpp (+5-5) 
- (modified) llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp (+17-15) 
- (modified) llvm/lib/ExecutionEngine/Orc/ObjectFileInterface.cpp (+1-1) 
- (modified) llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp (+20-37) 
- (modified) llvm/lib/ExecutionEngine/Orc/SectCreate.cpp (+1) 
- (modified) llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp (+1) 
- (modified) llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h (+1) 
- (modified) llvm/tools/llvm-jitlink/llvm-jitlink.cpp (+27-23) 
- (modified) llvm/tools/llvm-jitlink/llvm-jitlink.h (+3-4) 
- (modified) llvm/unittests/ExecutionEngine/JITLink/AArch32ErrorTests.cpp (+6-4) 
- (modified) llvm/unittests/ExecutionEngine/JITLink/EHFrameSupportTests.cpp (+6-4) 
- (modified) llvm/unittests/ExecutionEngine/JITLink/JITLinkTestUtils.cpp (+4-3) 
- (modified) llvm/unittests/ExecutionEngine/JITLink/LinkGraphTests.cpp (+32-17) 
- (modified) llvm/unittests/ExecutionEngine/JITLink/MachOLinkGraphTests.cpp (+4-2) 
- (modified) llvm/unittests/ExecutionEngine/JITLink/MemoryManagerErrorTests.cpp (+4-3) 
- (modified) llvm/unittests/ExecutionEngine/JITLink/StubsTests.cpp (+11-6) 
- (modified) llvm/unittests/ExecutionEngine/Orc/ObjectLinkingLayerTest.cpp (+29-22) 


``````````diff
diff --git a/.gitignore b/.gitignore
index 0e7c6c79001338..a84268a7f68632 100644
--- a/.gitignore
+++ b/.gitignore
@@ -59,6 +59,8 @@ autoconf/autom4te.cache
 # VS2017 and VSCode config files.
 .vscode
 .vs
+#zed config files
+.zed
 # pythonenv for github Codespaces
 pythonenv*
 # clangd index. (".clangd" is a config file now, thus trailing slash)
diff --git a/llvm/include/llvm/ExecutionEngine/JITLink/COFF.h b/llvm/include/llvm/ExecutionEngine/JITLink/COFF.h
index 87d3648d37e8ba..33b661933ace83 100644
--- a/llvm/include/llvm/ExecutionEngine/JITLink/COFF.h
+++ b/llvm/include/llvm/ExecutionEngine/JITLink/COFF.h
@@ -24,7 +24,8 @@ namespace jitlink {
 /// its contents. The caller is responsible for ensuring that the object buffer
 /// outlives the graph.
 Expected<std::unique_ptr<LinkGraph>>
-createLinkGraphFromCOFFObject(MemoryBufferRef ObjectBuffer);
+createLinkGraphFromCOFFObject(MemoryBufferRef ObjectBuffer,
+                              std::shared_ptr<orc::SymbolStringPool> 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
index fff32d6d960933..2072ae9dfdbe70 100644
--- a/llvm/include/llvm/ExecutionEngine/JITLink/COFF_x86_64.h
+++ b/llvm/include/llvm/ExecutionEngine/JITLink/COFF_x86_64.h
@@ -23,8 +23,8 @@ namespace jitlink {
 /// 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<std::unique_ptr<LinkGraph>>
-createLinkGraphFromCOFFObject_x86_64(MemoryBufferRef ObjectBuffer);
+Expected<std::unique_ptr<LinkGraph>> createLinkGraphFromCOFFObject_x86_64(
+    MemoryBufferRef ObjectBuffer, std::shared_ptr<orc::SymbolStringPool> SSP);
 
 /// jit-link the given object buffer, which must be a COFF x86-64 object file.
 void link_COFF_x86_64(std::unique_ptr<LinkGraph> G,
diff --git a/llvm/include/llvm/ExecutionEngine/JITLink/ELF.h b/llvm/include/llvm/ExecutionEngine/JITLink/ELF.h
index 038591f9add055..3decba65f380cb 100644
--- a/llvm/include/llvm/ExecutionEngine/JITLink/ELF.h
+++ b/llvm/include/llvm/ExecutionEngine/JITLink/ELF.h
@@ -24,7 +24,8 @@ namespace jitlink {
 /// its contents. The caller is responsible for ensuring that the object buffer
 /// outlives the graph.
 Expected<std::unique_ptr<LinkGraph>>
-createLinkGraphFromELFObject(MemoryBufferRef ObjectBuffer);
+createLinkGraphFromELFObject(MemoryBufferRef ObjectBuffer,
+                             std::shared_ptr<orc::SymbolStringPool> 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
index 25d1c3aac2c26e..b865414e520c29 100644
--- a/llvm/include/llvm/ExecutionEngine/JITLink/ELF_aarch32.h
+++ b/llvm/include/llvm/ExecutionEngine/JITLink/ELF_aarch32.h
@@ -24,8 +24,8 @@ namespace jitlink {
 /// 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<std::unique_ptr<LinkGraph>>
-createLinkGraphFromELFObject_aarch32(MemoryBufferRef ObjectBuffer);
+Expected<std::unique_ptr<LinkGraph>> createLinkGraphFromELFObject_aarch32(
+    MemoryBufferRef ObjectBuffer, std::shared_ptr<orc::SymbolStringPool> 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
index 50eb598139ea0b..45a7a0100593f3 100644
--- a/llvm/include/llvm/ExecutionEngine/JITLink/ELF_aarch64.h
+++ b/llvm/include/llvm/ExecutionEngine/JITLink/ELF_aarch64.h
@@ -25,8 +25,8 @@ namespace jitlink {
 /// 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<std::unique_ptr<LinkGraph>>
-createLinkGraphFromELFObject_aarch64(MemoryBufferRef ObjectBuffer);
+Expected<std::unique_ptr<LinkGraph>> createLinkGraphFromELFObject_aarch64(
+    MemoryBufferRef ObjectBuffer, std::shared_ptr<orc::SymbolStringPool> 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
index 44ebd969946113..0752f214d9d582 100644
--- a/llvm/include/llvm/ExecutionEngine/JITLink/ELF_i386.h
+++ b/llvm/include/llvm/ExecutionEngine/JITLink/ELF_i386.h
@@ -26,7 +26,8 @@ namespace jitlink {
 /// its contents. The caller is responsible for ensuring that the object buffer
 /// outlives the graph.
 Expected<std::unique_ptr<LinkGraph>>
-createLinkGraphFromELFObject_i386(MemoryBufferRef ObjectBuffer);
+createLinkGraphFromELFObject_i386(MemoryBufferRef ObjectBuffer,
+                                  std::shared_ptr<orc::SymbolStringPool> 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
index 4d7655c4b988b7..7e5d0f1f918521 100644
--- a/llvm/include/llvm/ExecutionEngine/JITLink/ELF_loongarch.h
+++ b/llvm/include/llvm/ExecutionEngine/JITLink/ELF_loongarch.h
@@ -25,8 +25,8 @@ namespace jitlink {
 /// 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<std::unique_ptr<LinkGraph>>
-createLinkGraphFromELFObject_loongarch(MemoryBufferRef ObjectBuffer);
+Expected<std::unique_ptr<LinkGraph>> createLinkGraphFromELFObject_loongarch(
+    MemoryBufferRef ObjectBuffer, std::shared_ptr<orc::SymbolStringPool> SSP);
 
 /// jit-link the given object buffer, which must be an ELF loongarch object
 /// file.
diff --git a/llvm/include/llvm/ExecutionEngine/JITLink/ELF_ppc64.h b/llvm/include/llvm/ExecutionEngine/JITLink/ELF_ppc64.h
index 8db986a4a9fa15..c5049a54cdf1d5 100644
--- a/llvm/include/llvm/ExecutionEngine/JITLink/ELF_ppc64.h
+++ b/llvm/include/llvm/ExecutionEngine/JITLink/ELF_ppc64.h
@@ -25,15 +25,16 @@ namespace llvm::jitlink {
 ///
 /// WARNING: The big-endian backend has not been tested yet.
 Expected<std::unique_ptr<LinkGraph>>
-createLinkGraphFromELFObject_ppc64(MemoryBufferRef ObjectBuffer);
+createLinkGraphFromELFObject_ppc64(MemoryBufferRef ObjectBuffer,
+                                   std::shared_ptr<orc::SymbolStringPool> SSP);
 
 /// Create a LinkGraph from an ELF/ppc64le relocatable object.
 ///
 /// 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<std::unique_ptr<LinkGraph>>
-createLinkGraphFromELFObject_ppc64le(MemoryBufferRef ObjectBuffer);
+Expected<std::unique_ptr<LinkGraph>> createLinkGraphFromELFObject_ppc64le(
+    MemoryBufferRef ObjectBuffer, std::shared_ptr<orc::SymbolStringPool> SSP);
 
 /// jit-link the given object buffer, which must be a ELF ppc64le object file.
 ///
diff --git a/llvm/include/llvm/ExecutionEngine/JITLink/ELF_riscv.h b/llvm/include/llvm/ExecutionEngine/JITLink/ELF_riscv.h
index a0e573baca066f..d00b5c2868baf6 100644
--- a/llvm/include/llvm/ExecutionEngine/JITLink/ELF_riscv.h
+++ b/llvm/include/llvm/ExecutionEngine/JITLink/ELF_riscv.h
@@ -26,7 +26,8 @@ namespace jitlink {
 /// its contents. The caller is responsible for ensuring that the object buffer
 /// outlives the graph.
 Expected<std::unique_ptr<LinkGraph>>
-createLinkGraphFromELFObject_riscv(MemoryBufferRef ObjectBuffer);
+createLinkGraphFromELFObject_riscv(MemoryBufferRef ObjectBuffer,
+                                   std::shared_ptr<orc::SymbolStringPool> SSP);
 
 /// jit-link the given object buffer, which must be a ELF riscv object file.
 void link_ELF_riscv(std::unique_ptr<LinkGraph> G,
diff --git a/llvm/include/llvm/ExecutionEngine/JITLink/ELF_x86_64.h b/llvm/include/llvm/ExecutionEngine/JITLink/ELF_x86_64.h
index fbe5765438d240..140dad7b82e002 100644
--- a/llvm/include/llvm/ExecutionEngine/JITLink/ELF_x86_64.h
+++ b/llvm/include/llvm/ExecutionEngine/JITLink/ELF_x86_64.h
@@ -24,7 +24,8 @@ namespace jitlink {
 /// its contents. The caller is responsible for ensuring that the object buffer
 /// outlives the graph.
 Expected<std::unique_ptr<LinkGraph>>
-createLinkGraphFromELFObject_x86_64(MemoryBufferRef ObjectBuffer);
+createLinkGraphFromELFObject_x86_64(MemoryBufferRef ObjectBuffe,
+                                    std::shared_ptr<orc::SymbolStringPool> SSP);
 
 /// jit-link the given object buffer, which must be a ELF x86-64 object file.
 void link_ELF_x86_64(std::unique_ptr<LinkGraph> G,
diff --git a/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h b/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h
index 9844214c537a06..7d74b622108f9c 100644
--- a/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h
+++ b/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h
@@ -23,6 +23,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"
@@ -35,6 +36,7 @@
 #include "llvm/TargetParser/Triple.h"
 #include <optional>
 
+#include <cstring>
 #include <map>
 #include <string>
 #include <system_error>
@@ -422,10 +424,11 @@ class Symbol {
   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);
@@ -434,27 +437,45 @@ class Symbol {
     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<Block &>(Base).getSize() == Size &&
+           "Common symbol size should match underlying block size");
+    auto *Sym = Allocator.Allocate<Symbol>();
+    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<Symbol>();
-    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<Symbol>();
-    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;
   }
 
@@ -465,20 +486,22 @@ class Symbol {
     assert((Offset + Size) <= Base.getSize() &&
            "Symbol extends past end of block");
     auto *Sym = Allocator.Allocate<Symbol>();
-    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<Symbol>();
-    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;
   }
 
@@ -495,18 +518,19 @@ class Symbol {
   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(const orc::SymbolStringPtr Name) { this->Name = Name; }
 
   /// Returns true if this Symbol has content (potentially) defined within this
   /// object file (i.e. is anything but an external or absolute symbol).
@@ -613,7 +637,7 @@ class Symbol {
 
   /// 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<uint8_t>(L);
   }
@@ -623,7 +647,7 @@ class Symbol {
 
   /// 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");
@@ -675,8 +699,7 @@ class Symbol {
 
   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;
@@ -1001,22 +1024,23 @@ class LinkGraph {
 
   using GetEdgeKindNameFunction = const char *(*)(Edge::Kind);
 
-  LinkGraph(std::string Name, const Triple &TT, SubtargetFeatures Features,
-            unsigned PointerSize, llvm::endianness Endianness,
+  LinkGraph(std::string Name, std::shared_ptr<orc::SymbolStringPool> SSP,
+            const Triple &TT, SubtargetFeatures Features, unsigned PointerSize,
+            llvm::endianness Endianness,
             GetEdgeKindNameFunction GetEdgeKindName)
-      : Name(std::move(Name)), TT(TT), Features(std::move(Features)),
+      : Name(std::move(Name)), SSP(SSP), TT(TT), Features(std::move(Features)),
         PointerSize(PointerSize), Endianness(Endianness),
         GetEdgeKindName(std::move(GetEdgeKindName)) {}
 
-  LinkGraph(std::string Name, const Triple &TT, unsigned PointerSize,
-            llvm::endianness Endianness,
+  LinkGraph(std::string Name, std::shared_ptr<orc::SymbolStringPool> SSP,
+            const Triple &TT, unsigned PointerSize, llvm::endianness Endianness,
             GetEdgeKindNameFunction GetEdgeKindName)
-      : LinkGraph(std::move(Name), TT, SubtargetFeatures(), PointerSize,
+      : LinkGraph(std::move(Name), SSP, TT, SubtargetFeatures(), PointerSize,
                   Endianness, GetEdgeKindName) {}
 
-  LinkGraph(std::string Name, const Triple &TT,
-            GetEdgeKindNameFunction GetEdgeKindName)
-      : LinkGraph(std::move(Name), TT, SubtargetFeatures(),
+  LinkGraph(std::string Name, std::shared_ptr<orc::SymbolStringPool> SSP,
+            const Triple &TT, GetEdgeKindNameFunction GetEdgeKindName)
+      : LinkGraph(std::move(Name), SSP, TT, SubtargetFeatures(),
                   Triple::getArchPointerBitWidth(TT.getArch()) / 8,
                   TT.isLittleEndian() ? endianness::little : endianness::big,
                   GetEdgeKindName) {
@@ -1028,6 +1052,7 @@ class LinkGraph {
   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).
@@ -1047,6 +1072,8 @@ class LinkGraph {
 
   const char *getEdgeKindName(Edge::Kind K) const { return GetEdgeKindName(K); }
 
+  std::shared_ptr<orc::SymbolStringPool> getSymbolStringPool() { return SSP; }
+
   /// Allocate a mutable buffer of the given size using the LinkGraph's
   /// allocator.
   MutableArrayRef<char> allocateBuffer(size_t Size) {
@@ -1260,6 +1287,10 @@ class LinkGraph {
     return splitBlockImpl(std::move(Blocks), Cache);
   }
 
+  //
+  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'.
@@ -1268,18 +1299,25 @@ class LinkGraph {
   /// 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(!ExternalSymbols.contains(Name) && "Duplicate external symbol");
+    assert(!ExternalSymbols.contains(*Name) && "Duplicate external symbol");
     auto &Sym = Symbol::constructExternal(
-        Allocator, createAddressable(orc::ExecutorAddr(), false), Name, Size,
-        Linkage::Strong, IsWeaklyReferenced);
-    ExternalSymbols.insert({Sym.getName(), &Sym});
+        Allocator, createAddressable(orc::ExecutorAddr(), false),
+        std::move(Name), Size, Linkage::Strong, IsWeaklyReferenced);
+    ExternalSymbols.insert({*Sym.getName(), &Sym});
     return Sym;
   }
 
+  Symbol &addExternalSymbol(StringRef Name, orc::ExecutorAddrDiff Size,
+                            bool IsWeaklyReferenced) {
+    return addExternalSymbol(SSP->intern(Name), Size, IsWeaklyReferenced);
+  }
+
   /// Add an absolute symbol.
-  Symbol &addAbsoluteSym...
[truncated]

``````````

</details>


https://github.com/llvm/llvm-project/pull/115796


More information about the llvm-commits mailing list