]> granicus.if.org Git - llvm/commitdiff
[WebAssembly] Fix list of relocations with addends in lld
authorKeno Fischer <keno@alumni.harvard.edu>
Wed, 26 Jun 2019 00:52:42 +0000 (00:52 +0000)
committerKeno Fischer <keno@alumni.harvard.edu>
Wed, 26 Jun 2019 00:52:42 +0000 (00:52 +0000)
Summary:
The list of relocations with addend in lld was missing `R_WASM_MEMORY_ADDR_REL_SLEB`,
causing `wasm-ld` to generate corrupted output. This fixes that problem and while
we're at it pulls the list of such relocations into the Wasm.h header, to avoid
duplicating it in multiple places.

Reviewers: sbc100
Differential Revision: https://reviews.llvm.org/D63696

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@364367 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/BinaryFormat/Wasm.h
lib/BinaryFormat/Wasm.cpp
lib/MC/WasmObjectWriter.cpp

index ee48a187f8e6e164049fc749024e71a04bd926a7..0f327c188bf3bb9c75cd4481ed13e092a70375a9 100644 (file)
@@ -364,6 +364,7 @@ inline bool operator!=(const WasmGlobalType &LHS, const WasmGlobalType &RHS) {
 
 std::string toString(WasmSymbolType type);
 std::string relocTypetoString(uint32_t type);
+bool relocTypeHasAddend(uint32_t type);
 
 } // end namespace wasm
 } // end namespace llvm
index 1d36b2cb6fbdb4e1a639da07f87b9feb150dfc09..d46be481edb36306275e2ee00acc130115fc5cdf 100644 (file)
@@ -35,3 +35,17 @@ std::string llvm::wasm::relocTypetoString(uint32_t Type) {
     llvm_unreachable("unknown reloc type");
   }
 }
+
+bool llvm::wasm::relocTypeHasAddend(uint32_t Type) {
+  switch (Type) {
+  case R_WASM_MEMORY_ADDR_LEB:
+  case R_WASM_MEMORY_ADDR_SLEB:
+  case R_WASM_MEMORY_ADDR_REL_SLEB:
+  case R_WASM_MEMORY_ADDR_I32:
+  case R_WASM_FUNCTION_OFFSET_I32:
+  case R_WASM_SECTION_OFFSET_I32:
+    return true;
+  default:
+    return false;
+  }
+}
index dab5bb329bc188c7616cd9e8d7b14f2525e61efa..8743eb7ee3c92546ed5391aa619d0094e49428a0 100644 (file)
@@ -147,19 +147,7 @@ struct WasmRelocationEntry {
       : Offset(Offset), Symbol(Symbol), Addend(Addend), Type(Type),
         FixupSection(FixupSection) {}
 
-  bool hasAddend() const {
-    switch (Type) {
-    case wasm::R_WASM_MEMORY_ADDR_LEB:
-    case wasm::R_WASM_MEMORY_ADDR_SLEB:
-    case wasm::R_WASM_MEMORY_ADDR_REL_SLEB:
-    case wasm::R_WASM_MEMORY_ADDR_I32:
-    case wasm::R_WASM_FUNCTION_OFFSET_I32:
-    case wasm::R_WASM_SECTION_OFFSET_I32:
-      return true;
-    default:
-      return false;
-    }
-  }
+  bool hasAddend() const { return wasm::relocTypeHasAddend(Type); }
 
   void print(raw_ostream &Out) const {
     Out << wasm::relocTypetoString(Type) << " Off=" << Offset