[lld] e049a87 - [lld-macho] Avoid using bump-alloc in TrieBuider

Jez Ng via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 14 14:23:01 PDT 2022


Author: Vy Nguyen
Date: 2022-03-14T17:22:53-04:00
New Revision: e049a87f04cff8e81b4177097a6b2fdf37c7b148

URL: https://github.com/llvm/llvm-project/commit/e049a87f04cff8e81b4177097a6b2fdf37c7b148
DIFF: https://github.com/llvm/llvm-project/commit/e049a87f04cff8e81b4177097a6b2fdf37c7b148.diff

LOG: [lld-macho] Avoid using bump-alloc in TrieBuider

The code can be used in multi-threads and the allocator is not thread safe.

fixes PR/54378

Reviewed By: int3, #lld-macho

Differential Revision: https://reviews.llvm.org/D121638

Added: 
    

Modified: 
    lld/MachO/ExportTrie.cpp
    lld/MachO/ExportTrie.h

Removed: 
    


################################################################################
diff  --git a/lld/MachO/ExportTrie.cpp b/lld/MachO/ExportTrie.cpp
index 372690a20df67..1c11f4a32e0a8 100644
--- a/lld/MachO/ExportTrie.cpp
+++ b/lld/MachO/ExportTrie.cpp
@@ -145,8 +145,13 @@ void TrieNode::writeTo(uint8_t *buf) const {
   }
 }
 
+TrieNode::~TrieNode() {
+  for (TrieNode *node : nodes)
+    delete node;
+}
+
 TrieNode *TrieBuilder::makeNode() {
-  auto *node = make<TrieNode>();
+  auto *node = new TrieNode();
   nodes.emplace_back(node);
   return node;
 }

diff  --git a/lld/MachO/ExportTrie.h b/lld/MachO/ExportTrie.h
index a43f4f2cce98b..0675d8257a2a6 100644
--- a/lld/MachO/ExportTrie.h
+++ b/lld/MachO/ExportTrie.h
@@ -22,6 +22,7 @@ class Symbol;
 
 class TrieBuilder {
 public:
+  ~TrieBuilder();
   void setImageBase(uint64_t addr) { imageBase = addr; }
   void addSymbol(const Symbol &sym) { exported.push_back(&sym); }
   // Returns the size in bytes of the serialized trie.


        


More information about the llvm-commits mailing list