diff options
author | Yuri Iozzelli <y.iozzelli@gmail.com> | 2022-02-25 16:36:35 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-25 15:36:35 +0000 |
commit | 1f59b65d8befc8512ff9045bb371ea5ec379a78c (patch) | |
tree | 349621c048c7716a746d3361c8ec6219d32f0250 /test/binary | |
parent | 08cf71aa180674432750a02581f1e214c310042d (diff) | |
download | wabt-1f59b65d8befc8512ff9045bb371ea5ec379a78c.tar.gz wabt-1f59b65d8befc8512ff9045bb371ea5ec379a78c.tar.bz2 wabt-1f59b65d8befc8512ff9045bb371ea5ec379a78c.zip |
Add initial support for code metadata (#1840)
See https://github.com/WebAssembly/tool-conventions/blob/main/CodeMetadata.md for the specification.
In particular this pr implements the following:
- Parsing code metadata sections in BinaryReader, providing appropriate callbacks that a BinaryReaderDelegate can implement:
- BinaryReaderObjdump: show the sections in a human-readable form
- BinaryReaderIr: add code metadata in the IR as expressions
- Parsing code metadata annotations in text format, adding them in the IR like the BinaryReaderIR does
- Writing the code metadata present in the IR in the proper sections when converting IR to binary
- Support in wasm-decompiler for showing code metadata as comments in the pseudo-code
All the features have corresponding tests.
Support for code metadata is gated through the --enable-code-metadata feature. For reading/writing in the text format, --enable-annotations is also required.
Missing features:
Support for function-level code metadata (offset 0)
Extensive validation in validator.cc (like making sure that all metadata instances are at the same code offset of an instruction)
Diffstat (limited to 'test/binary')
-rw-r--r-- | test/binary/bad-code-metadata-function-count.txt | 65 | ||||
-rw-r--r-- | test/binary/bad-code-metadata-function-duplicate.txt | 67 | ||||
-rw-r--r-- | test/binary/bad-code-metadata-function-index.txt | 62 | ||||
-rw-r--r-- | test/binary/bad-code-metadata-function-out-of-order.txt | 82 | ||||
-rw-r--r-- | test/binary/bad-code-metadata-instance-count.txt | 65 | ||||
-rw-r--r-- | test/binary/bad-code-metadata-instance-duplicate.txt | 68 | ||||
-rw-r--r-- | test/binary/bad-code-metadata-instance-out-of-order.txt | 68 | ||||
-rw-r--r-- | test/binary/code-metadata-section.txt | 61 |
8 files changed, 538 insertions, 0 deletions
diff --git a/test/binary/bad-code-metadata-function-count.txt b/test/binary/bad-code-metadata-function-count.txt new file mode 100644 index 00000000..50da843a --- /dev/null +++ b/test/binary/bad-code-metadata-function-count.txt @@ -0,0 +1,65 @@ +;;; TOOL: run-objdump-gen-wasm +;;; ARGS1: -x +magic +version +section(TYPE) { + count[1] + function params[0] results[1] i32 +} +section(FUNCTION) { + count[1] + type[0] +} +section(MEMORY) { + count[1] + has_max[0] + initial[0] +} +section("metadata.code.test") { + function_count[2] + function_index[0] + ann_count[1] + ann_offset[1] + ann_data_size[1] + ann_data[1] +} + +section(CODE) { + count[1] + func { + local_decls[0] + i32.const 1 + return + } +} + +(;; STDERR ;;; +0000033: warning: unable to read u32 leb128: function index +;;; STDERR ;;) +(;; STDOUT ;;; + +bad-code-metadata-function-count.wasm: file format wasm 0x1 + +Section Details: + +Type[1]: + - type[0] () -> i32 +Function[1]: + - func[0] sig=0 +Memory[1]: + - memory[0] pages: initial=0 +Custom: + - name: "metadata.code.test" + - func[0]: + - meta[1]: + - 0000000: 01 . +Code[1]: + - func[0] size=5 + +Code Disassembly: + +000037 func[0]: + 000038: 41 01 | i32.const 1 + 00003a: 0f | return + 00003b: 0b | end +;;; STDOUT ;;) diff --git a/test/binary/bad-code-metadata-function-duplicate.txt b/test/binary/bad-code-metadata-function-duplicate.txt new file mode 100644 index 00000000..4173ece2 --- /dev/null +++ b/test/binary/bad-code-metadata-function-duplicate.txt @@ -0,0 +1,67 @@ +;;; TOOL: run-objdump-gen-wasm +;;; ARGS1: -x +magic +version +section(TYPE) { + count[1] + function params[0] results[1] i32 +} +section(FUNCTION) { + count[1] + type[0] +} +section(MEMORY) { + count[1] + has_max[0] + initial[0] +} +section("metadata.code.test") { + function_count[2] + function_index[0] + ann_count[1] + ann_offset[1] + ann_data_size[1] + ann_data[1] + function_index[0] + ann_count[0] +} + +section(CODE) { + count[1] + func { + local_decls[0] + i32.const 1 + return + } +} + +(;; STDERR ;;; +0000034: warning: duplicate function index: 0 +;;; STDERR ;;) +(;; STDOUT ;;; + +bad-code-metadata-function-duplicate.wasm: file format wasm 0x1 + +Section Details: + +Type[1]: + - type[0] () -> i32 +Function[1]: + - func[0] sig=0 +Memory[1]: + - memory[0] pages: initial=0 +Custom: + - name: "metadata.code.test" + - func[0]: + - meta[1]: + - 0000000: 01 . +Code[1]: + - func[0] size=5 + +Code Disassembly: + +000039 func[0]: + 00003a: 41 01 | i32.const 1 + 00003c: 0f | return + 00003d: 0b | end +;;; STDOUT ;;) diff --git a/test/binary/bad-code-metadata-function-index.txt b/test/binary/bad-code-metadata-function-index.txt new file mode 100644 index 00000000..48bd19c6 --- /dev/null +++ b/test/binary/bad-code-metadata-function-index.txt @@ -0,0 +1,62 @@ +;;; TOOL: run-objdump-gen-wasm +;;; ARGS1: -x +magic +version +section(TYPE) { + count[1] + function params[0] results[1] i32 +} +section(FUNCTION) { + count[1] + type[0] +} +section(MEMORY) { + count[1] + has_max[0] + initial[0] +} +section("metadata.code.test") { + function_count[1] + function_index[2] + ann_count[1] + ann_offset[1] + ann_data_size[1] + ann_data[1] +} + +section(CODE) { + count[1] + func { + local_decls[0] + i32.const 1 + return + } +} + +(;; STDERR ;;; +000002f: warning: invalid function index: 2 +;;; STDERR ;;) +(;; STDOUT ;;; + +bad-code-metadata-function-index.wasm: file format wasm 0x1 + +Section Details: + +Type[1]: + - type[0] () -> i32 +Function[1]: + - func[0] sig=0 +Memory[1]: + - memory[0] pages: initial=0 +Custom: + - name: "metadata.code.test" +Code[1]: + - func[0] size=5 + +Code Disassembly: + +000037 func[0]: + 000038: 41 01 | i32.const 1 + 00003a: 0f | return + 00003b: 0b | end +;;; STDOUT ;;) diff --git a/test/binary/bad-code-metadata-function-out-of-order.txt b/test/binary/bad-code-metadata-function-out-of-order.txt new file mode 100644 index 00000000..b0c05890 --- /dev/null +++ b/test/binary/bad-code-metadata-function-out-of-order.txt @@ -0,0 +1,82 @@ +;;; TOOL: run-objdump-gen-wasm +;;; ARGS1: -x +magic +version +section(TYPE) { + count[1] + function params[0] results[1] i32 +} +section(FUNCTION) { + count[2] + type[0] + type[0] +} +section(MEMORY) { + count[1] + has_max[0] + initial[0] +} +section("metadata.code.test") { + function_count[2] + function_index[1] + ann_count[1] + ann_offset[1] + ann_data_size[1] + ann_data[1] + function_index[0] + ann_count[1] + ann_offset[1] + ann_data_size[1] + ann_data[1] +} + +section(CODE) { + count[2] + func { + local_decls[0] + i32.const 1 + return + } + func { + local_decls[0] + i32.const 1 + return + } +} + +(;; STDERR ;;; +0000035: warning: function index out of order: 0 +;;; STDERR ;;) +(;; STDOUT ;;; + +bad-code-metadata-function-out-of-order.wasm: file format wasm 0x1 + +Section Details: + +Type[1]: + - type[0] () -> i32 +Function[2]: + - func[0] sig=0 + - func[1] sig=0 +Memory[1]: + - memory[0] pages: initial=0 +Custom: + - name: "metadata.code.test" + - func[1]: + - meta[1]: + - 0000000: 01 . +Code[2]: + - func[0] size=5 + - func[1] size=5 + +Code Disassembly: + +00003d func[0]: + 00003e: 41 01 | i32.const 1 + 000040: 0f | return + 000041: 0b | end +000043 func[1]: + 000044: 41 01 | i32.const 1 + 000046: 0f | return + 000047: 0b | end +;;; STDOUT ;;) diff --git a/test/binary/bad-code-metadata-instance-count.txt b/test/binary/bad-code-metadata-instance-count.txt new file mode 100644 index 00000000..c8be5895 --- /dev/null +++ b/test/binary/bad-code-metadata-instance-count.txt @@ -0,0 +1,65 @@ +;;; TOOL: run-objdump-gen-wasm +;;; ARGS1: -x +magic +version +section(TYPE) { + count[1] + function params[0] results[1] i32 +} +section(FUNCTION) { + count[1] + type[0] +} +section(MEMORY) { + count[1] + has_max[0] + initial[0] +} +section("metadata.code.test") { + function_count[1] + function_index[0] + ann_count[2] + ann_offset[1] + ann_data_size[1] + ann_data[1] +} + +section(CODE) { + count[1] + func { + local_decls[0] + i32.const 1 + return + } +} + +(;; STDERR ;;; +0000033: warning: unable to read u32 leb128: code offset +;;; STDERR ;;) +(;; STDOUT ;;; + +bad-code-metadata-instance-count.wasm: file format wasm 0x1 + +Section Details: + +Type[1]: + - type[0] () -> i32 +Function[1]: + - func[0] sig=0 +Memory[1]: + - memory[0] pages: initial=0 +Custom: + - name: "metadata.code.test" + - func[0]: + - meta[1]: + - 0000000: 01 . +Code[1]: + - func[0] size=5 + +Code Disassembly: + +000037 func[0]: + 000038: 41 01 | i32.const 1 + 00003a: 0f | return + 00003b: 0b | end +;;; STDOUT ;;) diff --git a/test/binary/bad-code-metadata-instance-duplicate.txt b/test/binary/bad-code-metadata-instance-duplicate.txt new file mode 100644 index 00000000..95723713 --- /dev/null +++ b/test/binary/bad-code-metadata-instance-duplicate.txt @@ -0,0 +1,68 @@ +;;; TOOL: run-objdump-gen-wasm +;;; ARGS1: -x +magic +version +section(TYPE) { + count[1] + function params[0] results[1] i32 +} +section(FUNCTION) { + count[1] + type[0] +} +section(MEMORY) { + count[1] + has_max[0] + initial[0] +} +section("metadata.code.test") { + function_count[1] + function_index[0] + ann_count[2] + ann_offset[1] + ann_data_size[1] + ann_data[1] + ann_offset[1] + ann_data_size[1] + ann_data[1] +} + +section(CODE) { + count[1] + func { + local_decls[0] + i32.const 1 + return + } +} + +(;; STDERR ;;; +0000034: warning: duplicate code offset: 1 +;;; STDERR ;;) +(;; STDOUT ;;; + +bad-code-metadata-instance-duplicate.wasm: file format wasm 0x1 + +Section Details: + +Type[1]: + - type[0] () -> i32 +Function[1]: + - func[0] sig=0 +Memory[1]: + - memory[0] pages: initial=0 +Custom: + - name: "metadata.code.test" + - func[0]: + - meta[1]: + - 0000000: 01 . +Code[1]: + - func[0] size=5 + +Code Disassembly: + +00003a func[0]: + 00003b: 41 01 | i32.const 1 + 00003d: 0f | return + 00003e: 0b | end +;;; STDOUT ;;) diff --git a/test/binary/bad-code-metadata-instance-out-of-order.txt b/test/binary/bad-code-metadata-instance-out-of-order.txt new file mode 100644 index 00000000..4efb85d8 --- /dev/null +++ b/test/binary/bad-code-metadata-instance-out-of-order.txt @@ -0,0 +1,68 @@ +;;; TOOL: run-objdump-gen-wasm +;;; ARGS1: -x +magic +version +section(TYPE) { + count[1] + function params[0] results[1] i32 +} +section(FUNCTION) { + count[1] + type[0] +} +section(MEMORY) { + count[1] + has_max[0] + initial[0] +} +section("metadata.code.test") { + function_count[1] + function_index[0] + ann_count[2] + ann_offset[3] + ann_data_size[1] + ann_data[1] + ann_offset[1] + ann_data_size[1] + ann_data[1] +} + +section(CODE) { + count[1] + func { + local_decls[0] + i32.const 1 + return + } +} + +(;; STDERR ;;; +0000034: warning: code offset out of order: 1 +;;; STDERR ;;) +(;; STDOUT ;;; + +bad-code-metadata-instance-out-of-order.wasm: file format wasm 0x1 + +Section Details: + +Type[1]: + - type[0] () -> i32 +Function[1]: + - func[0] sig=0 +Memory[1]: + - memory[0] pages: initial=0 +Custom: + - name: "metadata.code.test" + - func[0]: + - meta[3]: + - 0000000: 01 . +Code[1]: + - func[0] size=5 + +Code Disassembly: + +00003a func[0]: + 00003b: 41 01 | i32.const 1 + 00003d: 0f | return + 00003e: 0b | end +;;; STDOUT ;;) diff --git a/test/binary/code-metadata-section.txt b/test/binary/code-metadata-section.txt new file mode 100644 index 00000000..9625f602 --- /dev/null +++ b/test/binary/code-metadata-section.txt @@ -0,0 +1,61 @@ +;;; TOOL: run-objdump-gen-wasm +;;; ARGS: -x +magic +version +section(TYPE) { + count[1] + function params[0] results[1] i32 +} +section(FUNCTION) { + count[1] + type[0] +} +section(MEMORY) { + count[1] + has_max[0] + initial[0] +} +section("metadata.code.test") { + function_count[1] + function_index[0] + ann_count[1] + ann_offset[1] + ann_data_size[1] + ann_data[1] +} + +section(CODE) { + count[1] + func { + local_decls[0] + i32.const 1 + return + } +} +(;; STDOUT ;;; + +code-metadata-section.wasm: file format wasm 0x1 + +Section Details: + +Type[1]: + - type[0] () -> i32 +Function[1]: + - func[0] sig=0 +Memory[1]: + - memory[0] pages: initial=0 +Custom: + - name: "metadata.code.test" + - func[0]: + - meta[1]: + - 0000000: 01 . +Code[1]: + - func[0] size=5 + +Code Disassembly: + +000037 func[0]: + 000038: 41 01 | i32.const 1 + 00003a: 0f | return + 00003b: 0b | end +;;; STDOUT ;;) |