[llvm] r358801 - [WebAssembly] Object: Improve error messages on invalid section

Sam Clegg via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 19 17:11:47 PDT 2019


Author: sbc
Date: Fri Apr 19 17:11:46 2019
New Revision: 358801

URL: http://llvm.org/viewvc/llvm-project?rev=358801&view=rev
Log:
[WebAssembly] Object: Improve error messages on invalid section

Also add a test.

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

Modified:
    llvm/trunk/lib/Object/WasmObjectFile.cpp
    llvm/trunk/test/Object/wasm-invalid-file.yaml

Modified: llvm/trunk/lib/Object/WasmObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/WasmObjectFile.cpp?rev=358801&r1=358800&r2=358801&view=diff
==============================================================================
--- llvm/trunk/lib/Object/WasmObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/WasmObjectFile.cpp Fri Apr 19 17:11:46 2019
@@ -319,8 +319,8 @@ Error WasmObjectFile::parseSection(WasmS
   case wasm::WASM_SEC_DATACOUNT:
     return parseDataCountSection(Ctx);
   default:
-    return make_error<GenericBinaryError>("Bad section type",
-                                          object_error::parse_failed);
+    return make_error<GenericBinaryError>(
+        "Invalid section type: " + Twine(Sec.Type), object_error::parse_failed);
   }
 }
 
@@ -1607,7 +1607,7 @@ int WasmSectionOrderChecker::getSectionO
   case wasm::WASM_SEC_EVENT:
     return WASM_SEC_ORDER_EVENT;
   default:
-    llvm_unreachable("invalid section");
+    return WASM_SEC_ORDER_NONE;
   }
 }
 

Modified: llvm/trunk/test/Object/wasm-invalid-file.yaml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/wasm-invalid-file.yaml?rev=358801&r1=358800&r2=358801&view=diff
==============================================================================
--- llvm/trunk/test/Object/wasm-invalid-file.yaml (original)
+++ llvm/trunk/test/Object/wasm-invalid-file.yaml Fri Apr 19 17:11:46 2019
@@ -14,3 +14,9 @@ FileHeader:
 # RUN: not llvm-objdump -h %t.wasm 2>&1 | FileCheck %s -check-prefix=CHECK-SECTION-SIZE
 
 # CHECK-SECTION-SIZE: '{{.*}}.wasm': Section too large
+
+# RUN: yaml2obj %s > %t.wasm
+# # Append an section with invalid type (type 0x20, size 0x1, content 0x0)
+# RUN: echo -e -n "\x20\x01\x00" >> %t.wasm
+# RUN: not llvm-objdump -h %t.wasm 2>&1 | FileCheck %s -check-prefix=CHECK-SECTION-TYPE
+# CHECK-SECTION-TYPE: '{{.*}}.wasm': Invalid section type: 32




More information about the llvm-commits mailing list