[llvm] Use MapVector to fix lld thinLTO bep issue. (PR #117551)

via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 25 17:26:38 PST 2024


https://github.com/llvmssh updated https://github.com/llvm/llvm-project/pull/117551

>From 86e55de0b3e468cc45a2586d35c92898890447d3 Mon Sep 17 00:00:00 2001
From: shaosenhao <shaosenhao at huawei.com>
Date: Thu, 21 Nov 2024 14:58:08 +0800
Subject: [PATCH] When the ModuleSymbolTable is generated, the binary
 consistency problem occurs due to the unorder of the data structure when
 collecting asm symbols.  Use MapVector to fix lld thinLTO bep issue.

---
 llvm/lib/Object/ModuleSymbolTable.cpp | 2 +-
 llvm/lib/Object/RecordStreamer.h      | 7 ++++---
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/llvm/lib/Object/ModuleSymbolTable.cpp b/llvm/lib/Object/ModuleSymbolTable.cpp
index 54e654a0d121cb..dc8ba00d3c91c7 100644
--- a/llvm/lib/Object/ModuleSymbolTable.cpp
+++ b/llvm/lib/Object/ModuleSymbolTable.cpp
@@ -144,7 +144,7 @@ void ModuleSymbolTable::CollectAsmSymbols(
     Streamer.flushSymverDirectives();
 
     for (auto &KV : Streamer) {
-      StringRef Key = KV.first();
+      StringRef Key = KV.first;
       RecordStreamer::State Value = KV.second;
       // FIXME: For now we just assume that all asm symbols are executable.
       uint32_t Res = BasicSymbolRef::SF_Executable;
diff --git a/llvm/lib/Object/RecordStreamer.h b/llvm/lib/Object/RecordStreamer.h
index 70b41f270720b4..946578ef06d11e 100644
--- a/llvm/lib/Object/RecordStreamer.h
+++ b/llvm/lib/Object/RecordStreamer.h
@@ -14,6 +14,7 @@
 #include "llvm/MC/MCDirectives.h"
 #include "llvm/MC/MCStreamer.h"
 #include "llvm/Support/SMLoc.h"
+#include "llvm/ADT/MapVector.h"
 #include <vector>
 
 namespace llvm {
@@ -28,11 +29,11 @@ class RecordStreamer : public MCStreamer {
 
 private:
   const Module &M;
-  StringMap<State> Symbols;
+  MapVector<StringRef, State> Symbols;
   // Map of aliases created by .symver directives, saved so we can update
   // their symbol binding after parsing complete. This maps from each
   // aliasee to its list of aliases.
-  DenseMap<const MCSymbol *, std::vector<StringRef>> SymverAliasMap;
+  MapVector<const MCSymbol *, std::vector<StringRef>> SymverAliasMap;
 
   /// Get the state recorded for the given symbol.
   State getSymbolState(const MCSymbol *Sym);
@@ -70,7 +71,7 @@ class RecordStreamer : public MCStreamer {
   void flushSymverDirectives();
 
   // Symbols iterators
-  using const_iterator = StringMap<State>::const_iterator;
+  using const_iterator = MapVector<StringRef, State>::const_iterator;
   const_iterator begin();
   const_iterator end();
 



More information about the llvm-commits mailing list