summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2019-11-19 17:05:22 -0800
committerGitHub <noreply@github.com>2019-11-19 17:05:22 -0800
commitcfa647c9fb0474687014de8d3f0b6c9f0d56a88b (patch)
tree4832a46cf6426300f6afc6f8a85270bfeb80c0b2 /src
parent00bbde099c0d968ce4ab95eba56d767d534e4094 (diff)
downloadbinaryen-cfa647c9fb0474687014de8d3f0b6c9f0d56a88b.tar.gz
binaryen-cfa647c9fb0474687014de8d3f0b6c9f0d56a88b.tar.bz2
binaryen-cfa647c9fb0474687014de8d3f0b6c9f0d56a88b.zip
Add a --strip-dwarf pass (#2454)
This pass strips DWARF debug sections, but not other debug sections. This is useful when emitting source maps, as we do need the SourceMapURL section, but the DWARF sections are not longer necessary (and we've seen a testcase where they are massively large, so big the wasm can't even be loaded in a browser...). Also contains a trivial one-line fix in --extract-function which was necessary to create the testcase here: that pass extracts a function from a wasm file (like llvm-extract) but it didn't check if an export already existed for the function.
Diffstat (limited to 'src')
-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
4 files changed, 16 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();