[llvm] r331705 - [WebAssembly] MC: Use existing MCSymbol.Index field rather than inventing extra mapping

Sam Clegg via llvm-commits llvm-commits at lists.llvm.org
Mon May 7 17:08:21 PDT 2018


Author: sbc
Date: Mon May  7 17:08:21 2018
New Revision: 331705

URL: http://llvm.org/viewvc/llvm-project?rev=331705&view=rev
Log:
[WebAssembly] MC: Use existing MCSymbol.Index field rather than inventing extra mapping

MCSymbol has getIndex/setIndex which are implementation defined
and on other platforms are used to store the symbol table
index.  It makes sense to use this rather than invent a new
mapping.

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

Modified:
    llvm/trunk/lib/MC/WasmObjectWriter.cpp

Modified: llvm/trunk/lib/MC/WasmObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/WasmObjectWriter.cpp?rev=331705&r1=331704&r2=331705&view=diff
==============================================================================
--- llvm/trunk/lib/MC/WasmObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/WasmObjectWriter.cpp Mon May  7 17:08:21 2018
@@ -199,8 +199,9 @@ struct WasmRelocationEntry {
 #endif
 };
 
+static const uint32_t INVALID_INDEX = -1;
+
 struct WasmCustomSection {
-  const uint32_t INVALID_INDEX = -1;
 
   StringRef Name;
   MCSectionWasm *Section;
@@ -238,8 +239,6 @@ class WasmObjectWriter : public MCObject
   // 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 @@ private:
     CodeRelocations.clear();
     DataRelocations.clear();
     TypeIndices.clear();
-    SymbolIndices.clear();
     WasmIndices.clear();
     TableIndices.clear();
     DataLocations.clear();
@@ -666,10 +664,7 @@ WasmObjectWriter::getRelocationIndexValu
     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 @@ void WasmObjectWriter::writeObject(MCAss
   // 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,7 +1366,7 @@ void WasmObjectWriter::writeObject(MCAss
       assert(DataLocations.count(&WS) > 0);
       Info.DataRef = DataLocations.find(&WS)->second;
     }
-    SymbolIndices[&WS] = SymbolInfos.size();
+    WS.setIndex(SymbolInfos.size());
     SymbolInfos.emplace_back(Info);
   }
 
@@ -1444,11 +1441,10 @@ void WasmObjectWriter::writeObject(MCAss
         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()));
     }
   }
 




More information about the llvm-commits mailing list