[PATCH] D44350: [WebAssembly] Improve logging and comments around relocations. NFC.

Sam Clegg via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 9 21:28:59 PST 2018


sbc100 created this revision.
Herald added subscribers: llvm-commits, sunfish, aheejin, jgravelle-google, dschuff, jfb.

Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D44350

Files:
  wasm/InputChunks.cpp
  wasm/InputFiles.cpp


Index: wasm/InputFiles.cpp
===================================================================
--- wasm/InputFiles.cpp
+++ wasm/InputFiles.cpp
@@ -49,10 +49,9 @@
       "\n       Global Imports : " + Twine(WasmObj->getNumImportedGlobals()));
 }
 
-// Relocations contain an index into the function, global or table index
-// space of the input file.  This function takes a relocation and returns the
-// relocated index (i.e. translates from the input index space to the output
-// index space).
+// Relocations contain either symbol or type indices.  This function takes a
+// relocation and returns relocated index (i.e. translates from the input
+// sybmol/type space to the output symbol/type space).
 uint32_t ObjFile::calcNewIndex(const WasmRelocation &Reloc) const {
   if (Reloc.Type == R_WEBASSEMBLY_TYPE_INDEX_LEB) {
     assert(TypeIsUsed[Reloc.Index]);
Index: wasm/InputChunks.cpp
===================================================================
--- wasm/InputChunks.cpp
+++ wasm/InputChunks.cpp
@@ -23,6 +23,15 @@
 using namespace lld;
 using namespace lld::wasm;
 
+StringRef ReloctTypeToString(uint8_t RelocType) {
+  switch (RelocType) {
+#define WASM_RELOC(NAME, REL) case REL: return #NAME;
+#include "llvm/BinaryFormat/WasmRelocs.def"
+#undef WASM_RELOC
+  }
+  llvm_unreachable("unknown reloc type");
+}
+
 std::string lld::toString(const InputChunk *C) {
   return (toString(C->File) + ":(" + C->getName() + ")").str();
 }
@@ -46,14 +55,14 @@
   if (Relocations.empty())
     return;
 
-  DEBUG(dbgs() << "applyRelocations: count=" << Relocations.size() << "\n");
+  DEBUG(dbgs() << "applying relocations: count=" << Relocations.size() << "\n");
   int32_t Off = OutputOffset - getInputSectionOffset();
 
   for (const WasmRelocation &Rel : Relocations) {
     uint8_t *Loc = Buf + Rel.Offset + Off;
-    uint64_t Value = File->calcNewValue(Rel);
-
-    DEBUG(dbgs() << "write reloc: type=" << Rel.Type << " index=" << Rel.Index
+    uint32_t Value = File->calcNewValue(Rel);
+    DEBUG(dbgs() << "apply reloc: type=" << ReloctTypeToString(Rel.Type)
+                 << " addend=" << Rel.Addend << " index=" << Rel.Index
                  << " value=" << Value << " offset=" << Rel.Offset << "\n");
 
     switch (Rel.Type) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44350.137897.patch
Type: text/x-patch
Size: 2251 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180310/7d14fe0d/attachment.bin>


More information about the llvm-commits mailing list