[llvm] d75b371 - [WebAssembly] Test that invalid symbol/relocation types generate errors
Sam Clegg via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 21 14:02:04 PST 2021
Author: Sam Clegg
Date: 2021-01-21T13:58:28-08:00
New Revision: d75b3719828f3e0c9736476e50a08e5083f90c0b
URL: https://github.com/llvm/llvm-project/commit/d75b3719828f3e0c9736476e50a08e5083f90c0b
DIFF: https://github.com/llvm/llvm-project/commit/d75b3719828f3e0c9736476e50a08e5083f90c0b.diff
LOG: [WebAssembly] Test that invalid symbol/relocation types generate errors
See https://bugs.llvm.org/show_bug.cgi?id=48827
Differential Revision: https://reviews.llvm.org/D95163
Added:
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
Modified:
llvm/lib/Object/WasmObjectFile.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Object/WasmObjectFile.cpp b/llvm/lib/Object/WasmObjectFile.cpp
index a349dde303e5..65adec341ebe 100644
--- a/llvm/lib/Object/WasmObjectFile.cpp
+++ b/llvm/lib/Object/WasmObjectFile.cpp
@@ -693,7 +693,8 @@ Error WasmObjectFile::parseLinkingSectionSymtab(ReadContext &Ctx) {
}
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 @@ Error WasmObjectFile::parseRelocSection(StringRef Name, ReadContext &Ctx) {
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 @@ Error WasmObjectFile::parseRelocSection(StringRef Name, ReadContext &Ctx) {
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
diff --git a/llvm/test/Object/Inputs/WASM/bad-reloc-type.wasm b/llvm/test/Object/Inputs/WASM/bad-reloc-type.wasm
new file mode 100644
index 000000000000..0f6de0ef6778
Binary files /dev/null and b/llvm/test/Object/Inputs/WASM/bad-reloc-type.wasm
diff er
diff --git a/llvm/test/Object/Inputs/WASM/bad-symbol-type.wasm b/llvm/test/Object/Inputs/WASM/bad-symbol-type.wasm
new file mode 100644
index 000000000000..8c7135f89f3b
Binary files /dev/null and b/llvm/test/Object/Inputs/WASM/bad-symbol-type.wasm
diff er
diff --git a/llvm/test/Object/wasm-bad-reloc-type.test b/llvm/test/Object/wasm-bad-reloc-type.test
new file mode 100644
index 000000000000..786532aa12b2
--- /dev/null
+++ b/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
diff --git a/llvm/test/Object/wasm-bad-symbol-type.test b/llvm/test/Object/wasm-bad-symbol-type.test
new file mode 100644
index 000000000000..06846a18f8f5
--- /dev/null
+++ b/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
More information about the llvm-commits
mailing list