[PATCH] D46555: [WebAssembly] MC: Use existing MCSymbol.Index field rather than inventing extra mapping

Sam Clegg via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 7 15:58:40 PDT 2018


sbc100 updated this revision to Diff 145581.
sbc100 added a comment.

- revert


Repository:
  rL LLVM

https://reviews.llvm.org/D46555

Files:
  lib/MC/WasmObjectWriter.cpp


Index: lib/MC/WasmObjectWriter.cpp
===================================================================
--- lib/MC/WasmObjectWriter.cpp
+++ lib/MC/WasmObjectWriter.cpp
@@ -199,8 +199,9 @@
 #endif
 };
 
+static const uint32_t INVALID_INDEX = -1;
+
 struct WasmCustomSection {
-  const uint32_t INVALID_INDEX = -1;
 
   StringRef Name;
   MCSectionWasm *Section;
@@ -238,8 +239,6 @@
   // Maps function symbols to the table element index space. Used
   // for TABLE_INDEX relocation types (i.e. address taken functions).
   DenseMap<const MCSymbolWasm *, uint32_t> TableIndices;
-  // Maps function/global symbols to the (shared) Symbol index space.
-  DenseMap<const MCSymbolWasm *, uint32_t> SymbolIndices;
   // Maps function/global symbols to the function/global/section index space.
   DenseMap<const MCSymbolWasm *, uint32_t> WasmIndices;
   // Maps data symbols to the Wasm segment and offset/size with the segment.
@@ -284,7 +283,6 @@
     CodeRelocations.clear();
     DataRelocations.clear();
     TypeIndices.clear();
-    SymbolIndices.clear();
     WasmIndices.clear();
     TableIndices.clear();
     DataLocations.clear();
@@ -666,10 +664,7 @@
     return TypeIndices[RelEntry.Symbol];
   }
 
-  if (!SymbolIndices.count(RelEntry.Symbol))
-    report_fatal_error("symbol not found in symbol index space: " +
-                       RelEntry.Symbol->getName());
-  return SymbolIndices[RelEntry.Symbol];
+  return RelEntry.Symbol->getIndex();
 }
 
 // Apply the portions of the relocation records that we can handle ourselves
@@ -1344,8 +1339,10 @@
   // Finally, populate the symbol table itself, in its "natural" order.
   for (const MCSymbol &S : Asm.symbols()) {
     const auto &WS = static_cast<const MCSymbolWasm &>(S);
-    if (!isInSymtab(WS))
+    if (!isInSymtab(WS)) {
+      WS.setIndex(INVALID_INDEX);
       continue;
+    }
     DEBUG(dbgs() << "adding to symtab: " << WS << "\n");
 
     uint32_t Flags = 0;
@@ -1369,10 +1366,12 @@
       assert(DataLocations.count(&WS) > 0);
       Info.DataRef = DataLocations.find(&WS)->second;
     }
-    SymbolIndices[&WS] = SymbolInfos.size();
+    WS.setIndex(SymbolInfos.size());
     SymbolInfos.emplace_back(Info);
   }
 
+  DEBUG(Asm.dump());
+
   {
     auto HandleReloc = [&](const WasmRelocationEntry &Rel) {
       // Functions referenced by a relocation need to put in the table.  This is
@@ -1444,11 +1443,9 @@
         report_fatal_error("fixups in .init_array should be symbol references");
       if (Sym->getKind() != MCSymbolRefExpr::VK_WebAssembly_FUNCTION)
         report_fatal_error("symbols in .init_array should be for functions");
-      auto I = SymbolIndices.find(cast<MCSymbolWasm>(&Sym->getSymbol()));
-      if (I == SymbolIndices.end())
-        report_fatal_error("symbols in .init_array should be defined");
-      uint32_t Index = I->second;
-      InitFuncs.push_back(std::make_pair(Priority, Index));
+      if (Sym->getSymbol().getIndex() == INVALID_INDEX)
+        report_fatal_error("symbols in .init_array should exist in symbtab");
+      InitFuncs.push_back(std::make_pair(Priority, Sym->getSymbol().getIndex()));
     }
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46555.145581.patch
Type: text/x-patch
Size: 3137 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180507/e53b6b20/attachment.bin>


More information about the llvm-commits mailing list