summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/passes/ExtractFunction.cpp14
-rw-r--r--src/passes/Strip.cpp6
-rw-r--r--src/passes/pass.cpp1
-rw-r--r--src/passes/passes.h1
-rw-r--r--test/passes/strip-dwarf.bin.txt32
-rw-r--r--test/passes/strip-dwarf.wasmbin0 -> 843 bytes
6 files changed, 48 insertions, 6 deletions
diff --git a/src/passes/ExtractFunction.cpp b/src/passes/ExtractFunction.cpp
index 01daf3504..fbc1aa7c4 100644
--- a/src/passes/ExtractFunction.cpp
+++ b/src/passes/ExtractFunction.cpp
@@ -49,12 +49,14 @@ struct ExtractFunction : public Pass {
module->memory.segments.clear();
module->table.segments.clear();
// leave just an export for the thing we want
- module->exports.clear();
- auto* export_ = new Export;
- export_->name = name;
- export_->value = name;
- export_->kind = ExternalKind::Function;
- module->addExport(export_);
+ if (!module->getExportOrNull(name)) {
+ module->exports.clear();
+ auto* export_ = new Export;
+ export_->name = name;
+ export_->value = name;
+ export_->kind = ExternalKind::Function;
+ module->addExport(export_);
+ }
}
};
diff --git a/src/passes/Strip.cpp b/src/passes/Strip.cpp
index e85379003..ace745f87 100644
--- a/src/passes/Strip.cpp
+++ b/src/passes/Strip.cpp
@@ -62,6 +62,12 @@ Pass* createStripDebugPass() {
});
}
+Pass* createStripDWARFPass() {
+ return new Strip([&](const UserSection& curr) {
+ return curr.name.find(".debug") == 0 || curr.name.find("reloc..debug") == 0;
+ });
+}
+
Pass* createStripProducersPass() {
return new Strip([&](const UserSection& curr) {
return curr.name == BinaryConsts::UserSections::Producers;
diff --git a/src/passes/pass.cpp b/src/passes/pass.cpp
index 0f6507d98..9afea38e6 100644
--- a/src/passes/pass.cpp
+++ b/src/passes/pass.cpp
@@ -320,6 +320,7 @@ void PassRegistry::registerPasses() {
registerPass("strip-debug",
"strip debug info (including the names section)",
createStripDebugPass);
+ registerPass("strip-dwarf", "strip dwarf debug info", createStripDWARFPass);
registerPass("strip-producers",
"strip the wasm producers section",
createStripProducersPass);
diff --git a/src/passes/passes.h b/src/passes/passes.h
index caa02ac8a..cc33e4300 100644
--- a/src/passes/passes.h
+++ b/src/passes/passes.h
@@ -102,6 +102,7 @@ Pass* createSimplifyLocalsNoTeePass();
Pass* createSimplifyLocalsNoStructurePass();
Pass* createSimplifyLocalsNoTeeNoStructurePass();
Pass* createStripDebugPass();
+Pass* createStripDWARFPass();
Pass* createStripProducersPass();
Pass* createStripTargetFeaturesPass();
Pass* createSouperifyPass();
diff --git a/test/passes/strip-dwarf.bin.txt b/test/passes/strip-dwarf.bin.txt
new file mode 100644
index 000000000..2276090e7
--- /dev/null
+++ b/test/passes/strip-dwarf.bin.txt
@@ -0,0 +1,32 @@
+(module
+ (type $0 (func (result i32)))
+ (type $1 (func (param i32) (result i32)))
+ (type $2 (func))
+ (type $3 (func (param i32)))
+ (type $4 (func (param i32 i32)))
+ (import "env" "__wasm_call_ctors" (func $fimport$0))
+ (import "env" "dlmalloc" (func $fimport$1 (param i32) (result i32)))
+ (import "env" "dlfree" (func $fimport$2 (param i32)))
+ (import "env" "setThrew" (func $fimport$3 (param i32 i32)))
+ (import "env" "stackSave" (func $fimport$4 (result i32)))
+ (import "env" "stackAlloc" (func $fimport$5 (param i32) (result i32)))
+ (import "env" "stackRestore" (func $fimport$6 (param i32)))
+ (import "env" "__growWasmMemory" (func $fimport$7 (param i32) (result i32)))
+ (global $global$0 i32 (i32.const 1532))
+ (export "__wasm_call_ctors" (func $fimport$0))
+ (export "_Z3foov" (func $fimport$0))
+ (export "__errno_location" (func $0))
+ (export "setThrew" (func $fimport$3))
+ (export "malloc" (func $fimport$1))
+ (export "free" (func $fimport$2))
+ (export "__data_end" (global $global$0))
+ (export "stackSave" (func $fimport$4))
+ (export "stackAlloc" (func $fimport$5))
+ (export "stackRestore" (func $fimport$6))
+ (export "__growWasmMemory" (func $fimport$7))
+ (func $0 (; 8 ;) (type $0) (result i32)
+ (i32.const 1024)
+ )
+ ;; custom section "sourceMappingURL", size 15
+ ;; custom section "sourceMappingURL", size 15
+)
diff --git a/test/passes/strip-dwarf.wasm b/test/passes/strip-dwarf.wasm
new file mode 100644
index 000000000..b9c7378e8
--- /dev/null
+++ b/test/passes/strip-dwarf.wasm
Binary files differ