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

Vy Nguyen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 14 14:01:53 PDT 2022


oontvoo created this revision.
oontvoo added a reviewer: int3.
Herald added projects: lld-macho, All.
Herald added a reviewer: lld-macho.
oontvoo requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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

fixes PR/54378


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D121638

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


Index: lld/MachO/ExportTrie.h
===================================================================
--- lld/MachO/ExportTrie.h
+++ lld/MachO/ExportTrie.h
@@ -22,6 +22,7 @@
 
 class TrieBuilder {
 public:
+  explicit ~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.
Index: lld/MachO/ExportTrie.cpp
===================================================================
--- lld/MachO/ExportTrie.cpp
+++ lld/MachO/ExportTrie.cpp
@@ -145,8 +145,14 @@
   }
 }
 
+TrieNode::~TrieNode() {
+  for (TrieNode *node : nodes)
+    delete node;
+  nodes.clear();
+  exported.clear();
+}
 TrieNode *TrieBuilder::makeNode() {
-  auto *node = make<TrieNode>();
+  auto *node = new TrieNode();
   nodes.emplace_back(node);
   return node;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D121638.415215.patch
Type: text/x-patch
Size: 868 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220314/33185e83/attachment.bin>


More information about the llvm-commits mailing list