[PATCH] D46092: [WebAssembly] Implement getRelocationValueString()

Sam Clegg via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 25 16:06:43 PDT 2018


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

And use it in llvm-objdump.


Repository:
  rL LLVM

https://reviews.llvm.org/D46092

Files:
  lib/Object/WasmObjectFile.cpp
  test/Object/objdump-relocations.test
  test/tools/llvm-objdump/WebAssembly/relocations.test
  tools/llvm-objdump/llvm-objdump.cpp


Index: tools/llvm-objdump/llvm-objdump.cpp
===================================================================
--- tools/llvm-objdump/llvm-objdump.cpp
+++ tools/llvm-objdump/llvm-objdump.cpp
@@ -917,9 +917,17 @@
                                                 const RelocationRef &RelRef,
                                                 SmallVectorImpl<char> &Result) {
   const wasm::WasmRelocation& Rel = Obj->getWasmRelocation(RelRef);
+  symbol_iterator SI = RelRef.getSymbol();
   std::string fmtbuf;
   raw_string_ostream fmt(fmtbuf);
-  fmt << Rel.Index << (Rel.Addend < 0 ? "" : "+") << Rel.Addend;
+  Expected<StringRef> SymNameOrErr = SI->getName();
+  if (!SymNameOrErr) {
+    fmt << Rel.Index;
+  } else {
+    StringRef SymName = *SymNameOrErr;
+    Result.append(SymName.begin(), SymName.end());
+  }
+  fmt << (Rel.Addend < 0 ? "" : "+") << Rel.Addend;
   fmt.flush();
   Result.append(fmtbuf.begin(), fmtbuf.end());
   return std::error_code();
Index: test/tools/llvm-objdump/WebAssembly/relocations.test
===================================================================
--- test/tools/llvm-objdump/WebAssembly/relocations.test
+++ test/tools/llvm-objdump/WebAssembly/relocations.test
@@ -5,4 +5,4 @@
 @bar = hidden global i32* @foo2, align 4
 
 ; CHECK:      RELOCATION RECORDS FOR [DATA]:
-; CHECK-NEXT: 00000018 R_WEBASSEMBLY_MEMORY_ADDR_I32 1+0
+; CHECK-NEXT: 00000018 R_WEBASSEMBLY_MEMORY_ADDR_I32 foo2+0
Index: test/Object/objdump-relocations.test
===================================================================
--- test/Object/objdump-relocations.test
+++ test/Object/objdump-relocations.test
@@ -60,9 +60,9 @@
 ELF-MIPSEL: R_MIPS_CALL16 SomeOtherFunction
 
 WASM:      CODE
-WASM-NEXT: R_WEBASSEMBLY_MEMORY_ADDR_SLEB 1+0
-WASM-NEXT: R_WEBASSEMBLY_FUNCTION_INDEX_LEB 2+0
-WASM-NEXT: R_WEBASSEMBLY_FUNCTION_INDEX_LEB 3+0
+WASM-NEXT: R_WEBASSEMBLY_MEMORY_ADDR_SLEB .L.str+0
+WASM-NEXT: R_WEBASSEMBLY_FUNCTION_INDEX_LEB puts+0
+WASM-NEXT: R_WEBASSEMBLY_FUNCTION_INDEX_LEB SomeOtherFunction+0
 
 ELF-complex-x86-64: .text
 ELF-complex-x86-64-NEXT: R_X86_64_8 .data-4
Index: lib/Object/WasmObjectFile.cpp
===================================================================
--- lib/Object/WasmObjectFile.cpp
+++ lib/Object/WasmObjectFile.cpp
@@ -1139,10 +1139,14 @@
   return Rel.Offset;
 }
 
-symbol_iterator WasmObjectFile::getRelocationSymbol(DataRefImpl Rel) const {
-  llvm_unreachable("not yet implemented");
-  SymbolRef Ref;
-  return symbol_iterator(Ref);
+symbol_iterator WasmObjectFile::getRelocationSymbol(DataRefImpl Ref) const {
+  const wasm::WasmRelocation &Rel = getWasmRelocation(Ref);
+  if (Rel.Type == wasm::R_WEBASSEMBLY_TYPE_INDEX_LEB)
+    return symbol_end();
+  DataRefImpl Sym;
+  Sym.d.a = Rel.Index;
+  Sym.d.b = 0;
+  return symbol_iterator(SymbolRef(Sym, this));
 }
 
 uint64_t WasmObjectFile::getRelocationType(DataRefImpl Ref) const {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46092.144033.patch
Type: text/x-patch
Size: 2894 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180425/454f708e/attachment.bin>


More information about the llvm-commits mailing list