summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--scripts/test/lld.py4
-rw-r--r--src/tools/wasm-emscripten-finalize.cpp17
-rw-r--r--test/lit/help/wasm-emscripten-finalize.test3
-rw-r--r--test/lld/no-emit-metadata.wat20
-rw-r--r--test/lld/no-emit-metadata.wat.out30
5 files changed, 70 insertions, 4 deletions
diff --git a/scripts/test/lld.py b/scripts/test/lld.py
index 1c632b957..2fc3261a8 100644
--- a/scripts/test/lld.py
+++ b/scripts/test/lld.py
@@ -26,6 +26,8 @@ def args_for_finalize(filename):
ret += ['--side-module']
if 'standalone-wasm' in filename:
ret += ['--standalone-wasm']
+ if 'no-emit-metadata' in filename:
+ ret += ['--no-emit-metadata']
return ret
@@ -57,7 +59,7 @@ def run_test(input_path):
actual = support.run_command(cmd)
shared.fail_if_not_identical_to_file(actual, expected_file)
- if ext == '.out':
+ if ext == '.out' and '--no-emit-metadata' not in cmd:
start = actual.find('--BEGIN METADATA --\n')
end = actual.find('-- END METADATA --\n')
if start == -1 or end == -1:
diff --git a/src/tools/wasm-emscripten-finalize.cpp b/src/tools/wasm-emscripten-finalize.cpp
index 392cf14a4..7f3e24e6a 100644
--- a/src/tools/wasm-emscripten-finalize.cpp
+++ b/src/tools/wasm-emscripten-finalize.cpp
@@ -47,6 +47,7 @@ int main(int argc, const char* argv[]) {
std::string outputSourceMapUrl;
std::string dataSegmentFile;
bool emitBinary = true;
+ bool emitMetadata = true;
bool debugInfo = false;
bool DWARF = false;
bool sideModule = false;
@@ -94,6 +95,13 @@ int main(int argc, const char* argv[]) {
WasmEmscriptenFinalizeOption,
Options::Arguments::Zero,
[&emitBinary](Options*, const std::string&) { emitBinary = false; })
+ .add(
+ "--no-emit-metadata",
+ "-n",
+ "Skip the writing to emscripten metadata JSON to stdout.",
+ WasmEmscriptenFinalizeOption,
+ Options::Arguments::Zero,
+ [&emitMetadata](Options*, const std::string&) { emitMetadata = false; })
.add("--global-base",
"",
"The address at which static globals were placed",
@@ -321,7 +329,10 @@ int main(int argc, const char* argv[]) {
BYN_TRACE("generated metadata\n");
// Substantial changes to the wasm are done, enough to create the metadata.
- std::string metadata = generator.generateEmscriptenMetadata();
+ std::string metadata;
+ if (emitMetadata) {
+ metadata = generator.generateEmscriptenMetadata();
+ }
// Finally, separate out data segments if relevant (they may have been needed
// for metadata).
@@ -347,7 +358,7 @@ int main(int argc, const char* argv[]) {
writer.setSourceMapUrl(outputSourceMapUrl);
}
writer.write(wasm, output);
- if (!emitBinary) {
+ if (emitMetadata && !emitBinary) {
output << "(;\n";
output << "--BEGIN METADATA --\n" << metadata << "-- END METADATA --\n";
output << ";)\n";
@@ -355,7 +366,7 @@ int main(int argc, const char* argv[]) {
}
// If we emit text then we emitted the metadata together with that text
// earlier. Otherwise emit it to stdout.
- if (emitBinary) {
+ if (emitMetadata && emitBinary) {
std::cout << metadata;
}
return 0;
diff --git a/test/lit/help/wasm-emscripten-finalize.test b/test/lit/help/wasm-emscripten-finalize.test
index 78cb0c11f..604e11081 100644
--- a/test/lit/help/wasm-emscripten-finalize.test
+++ b/test/lit/help/wasm-emscripten-finalize.test
@@ -20,6 +20,9 @@
;; CHECK-NEXT: output file. In this mode if no output
;; CHECK-NEXT: file is specified, we write to stdout.
;; CHECK-NEXT:
+;; CHECK-NEXT: --no-emit-metadata,-n Skip the writing to emscripten metadata
+;; CHECK-NEXT: JSON to stdout.
+;; CHECK-NEXT:
;; CHECK-NEXT: --global-base The address at which static globals were
;; CHECK-NEXT: placed
;; CHECK-NEXT:
diff --git a/test/lld/no-emit-metadata.wat b/test/lld/no-emit-metadata.wat
new file mode 100644
index 000000000..2ccbf3f29
--- /dev/null
+++ b/test/lld/no-emit-metadata.wat
@@ -0,0 +1,20 @@
+(module
+ (memory $0 2)
+ (table $0 1 1 funcref)
+ (elem (i32.const 0) $foo)
+ (global $global$0 (mut i32) (i32.const 66112))
+ (global $global$1 i32 (i32.const 66112))
+ (global $global$2 i32 (i32.const 576))
+ (export "memory" (memory $0))
+ (export "main" (func $main))
+ (export "__heap_base" (global $global$1))
+ (export "__data_end" (global $global$2))
+ (func $__original_main (result i32)
+ (nop)
+ )
+ (func $main (param $0 i32) (param $1 i32) (result i32)
+ (call $__original_main)
+ )
+ (func $foo (result i32))
+)
+
diff --git a/test/lld/no-emit-metadata.wat.out b/test/lld/no-emit-metadata.wat.out
new file mode 100644
index 000000000..281eba998
--- /dev/null
+++ b/test/lld/no-emit-metadata.wat.out
@@ -0,0 +1,30 @@
+(module
+ (type $none_=>_i32 (func (result i32)))
+ (type $i32_i32_=>_i32 (func (param i32 i32) (result i32)))
+ (type $i32_=>_i32 (func (param i32) (result i32)))
+ (global $global$0 (mut i32) (i32.const 66112))
+ (global $global$1 i32 (i32.const 66112))
+ (global $global$2 i32 (i32.const 576))
+ (memory $0 2)
+ (table $0 1 1 funcref)
+ (elem (i32.const 0) $foo)
+ (export "memory" (memory $0))
+ (export "main" (func $main))
+ (export "__heap_base" (global $global$1))
+ (export "__data_end" (global $global$2))
+ (export "dynCall_i" (func $dynCall_i))
+ (func $__original_main (result i32)
+ (nop)
+ )
+ (func $main (param $0 i32) (param $1 i32) (result i32)
+ (call $__original_main)
+ )
+ (func $foo (result i32)
+ (nop)
+ )
+ (func $dynCall_i (param $fptr i32) (result i32)
+ (call_indirect (type $none_=>_i32)
+ (local.get $fptr)
+ )
+ )
+)