[PATCH] D95163: [WebAssembly] Test that invalid symbol/relocation types generate errors

Sam Clegg via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 21 12:09:57 PST 2021


sbc100 created this revision.
Herald added subscribers: wingo, ecnelises, sunfish, hiraditya, jgravelle-google, dschuff.
sbc100 requested review of this revision.
Herald added subscribers: llvm-commits, aheejin.
Herald added a project: LLVM.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95163

Files:
  llvm/lib/Object/WasmObjectFile.cpp
  llvm/test/Object/Inputs/WASM/bad-reloc-type.wasm
  llvm/test/Object/Inputs/WASM/bad-symbol-type.wasm
  llvm/test/Object/wasm-bad-reloc-type.test
  llvm/test/Object/wasm-bad-symbol-type.test


Index: llvm/test/Object/wasm-bad-symbol-type.test
===================================================================
--- /dev/null
+++ llvm/test/Object/wasm-bad-symbol-type.test
@@ -0,0 +1,3 @@
+RUN: not llvm-objdump -s %p/Inputs/WASM/bad-symbol-type.wasm 2>&1 | FileCheck %s
+
+CHECK: Invalid symbol type: 63
Index: llvm/test/Object/wasm-bad-reloc-type.test
===================================================================
--- /dev/null
+++ llvm/test/Object/wasm-bad-reloc-type.test
@@ -0,0 +1,3 @@
+RUN: not llvm-objdump -s %p/Inputs/WASM/bad-reloc-type.wasm 2>&1 | FileCheck %s
+
+CHECK: Bad relocation type: 63
Index: llvm/lib/Object/WasmObjectFile.cpp
===================================================================
--- llvm/lib/Object/WasmObjectFile.cpp
+++ llvm/lib/Object/WasmObjectFile.cpp
@@ -693,7 +693,8 @@
     }
 
     default:
-      return make_error<GenericBinaryError>("Invalid symbol type",
+      return make_error<GenericBinaryError>("Invalid symbol type: " +
+                                                Twine(unsigned(Info.Kind)),
                                             object_error::parse_failed);
     }
 
@@ -850,14 +851,15 @@
   uint32_t PreviousOffset = 0;
   while (RelocCount--) {
     wasm::WasmRelocation Reloc = {};
-    Reloc.Type = readVaruint32(Ctx);
+    uint32_t type = readVaruint32(Ctx);
+    Reloc.Type = type;
     Reloc.Offset = readVaruint32(Ctx);
     if (Reloc.Offset < PreviousOffset)
       return make_error<GenericBinaryError>("Relocations not in offset order",
                                             object_error::parse_failed);
     PreviousOffset = Reloc.Offset;
     Reloc.Index = readVaruint32(Ctx);
-    switch (Reloc.Type) {
+    switch (type) {
     case wasm::R_WASM_FUNCTION_INDEX_LEB:
     case wasm::R_WASM_TABLE_INDEX_SLEB:
     case wasm::R_WASM_TABLE_INDEX_SLEB64:
@@ -935,9 +937,8 @@
       Reloc.Addend = readVarint32(Ctx);
       break;
     default:
-      return make_error<GenericBinaryError>("Bad relocation type: " +
-                                                Twine(Reloc.Type),
-                                            object_error::parse_failed);
+      return make_error<GenericBinaryError>(
+          "Bad relocation type: " + Twine(type), object_error::parse_failed);
     }
 
     // Relocations must fit inside the section, and must appear in order.  They


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D95163.318281.patch
Type: text/x-patch
Size: 2371 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210121/d137c196/attachment.bin>


More information about the llvm-commits mailing list