summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Lively <7121787+tlively@users.noreply.github.com>2019-03-14 18:23:59 -0700
committerGitHub <noreply@github.com>2019-03-14 18:23:59 -0700
commitfc085c0971029bd5fe2bf66074c467f304dfc1e4 (patch)
tree5859683dc65e7487e8be8db9979cb5611d7485c9
parentd9cdee0437ebee89377d361e5a9320b44f252152 (diff)
downloadbinaryen-fc085c0971029bd5fe2bf66074c467f304dfc1e4.tar.gz
binaryen-fc085c0971029bd5fe2bf66074c467f304dfc1e4.tar.bz2
binaryen-fc085c0971029bd5fe2bf66074c467f304dfc1e4.zip
Add strip-target-features pass (#1946)
And run it in wasm-emscripten-finalize. This will prevent the emscripten output from changing when the target features section lands in LLVM.
-rw-r--r--src/passes/Strip.cpp5
-rw-r--r--src/passes/pass.cpp1
-rw-r--r--src/passes/passes.h1
-rw-r--r--src/tools/wasm-emscripten-finalize.cpp1
-rw-r--r--src/wasm-binary.h1
-rw-r--r--src/wasm/wasm.cpp1
-rw-r--r--test/passes/strip-target-features.bin.txt3
-rw-r--r--test/passes/strip-target-features.wasmbin0 -> 43 bytes
8 files changed, 13 insertions, 0 deletions
diff --git a/src/passes/Strip.cpp b/src/passes/Strip.cpp
index edc171ab3..40e5a9e9d 100644
--- a/src/passes/Strip.cpp
+++ b/src/passes/Strip.cpp
@@ -75,4 +75,9 @@ Pass *createStripProducersPass() {
});
}
+Pass *createStripTargetFeaturesPass() {
+ return new Strip([&](const UserSection& curr) {
+ return curr.name == BinaryConsts::UserSections::TargetFeatures;
+ });
+}
} // namespace wasm
diff --git a/src/passes/pass.cpp b/src/passes/pass.cpp
index 3712bf19e..5d8b8d2c8 100644
--- a/src/passes/pass.cpp
+++ b/src/passes/pass.cpp
@@ -138,6 +138,7 @@ void PassRegistry::registerPasses() {
registerPass("strip", "deprecated; same as strip-debug", createStripDebugPass);
registerPass("strip-debug", "strip debug info (including the names section)", createStripDebugPass);
registerPass("strip-producers", "strip the wasm producers section", createStripProducersPass);
+ registerPass("strip-target-features", "strip the wasm target features section", createStripTargetFeaturesPass);
registerPass("trap-mode-clamp", "replace trapping operations with clamping semantics", createTrapModeClamp);
registerPass("trap-mode-js", "replace trapping operations with js semantics", createTrapModeJS);
registerPass("untee", "removes local.tees, replacing them with sets and gets", createUnteePass);
diff --git a/src/passes/passes.h b/src/passes/passes.h
index ab11721fb..ac7126bd4 100644
--- a/src/passes/passes.h
+++ b/src/passes/passes.h
@@ -88,6 +88,7 @@ Pass* createSimplifyLocalsNoStructurePass();
Pass* createSimplifyLocalsNoTeeNoStructurePass();
Pass* createStripDebugPass();
Pass* createStripProducersPass();
+Pass* createStripTargetFeaturesPass();
Pass* createSouperifyPass();
Pass* createSouperifySingleUsePass();
Pass* createSpillPointersPass();
diff --git a/src/tools/wasm-emscripten-finalize.cpp b/src/tools/wasm-emscripten-finalize.cpp
index 6e898b3f0..2aa5de46f 100644
--- a/src/tools/wasm-emscripten-finalize.cpp
+++ b/src/tools/wasm-emscripten-finalize.cpp
@@ -204,6 +204,7 @@ int main(int argc, const char *argv[]) {
legalizeJavaScriptFFI ? ABI::LegalizationLevel::Full
: ABI::LegalizationLevel::Minimal
));
+ passRunner.add("strip-target-features");
passRunner.run();
}
diff --git a/src/wasm-binary.h b/src/wasm-binary.h
index a875db791..32166af00 100644
--- a/src/wasm-binary.h
+++ b/src/wasm-binary.h
@@ -345,6 +345,7 @@ extern const char* SourceMapUrl;
extern const char* Dylink;
extern const char* Linking;
extern const char* Producers;
+extern const char* TargetFeatures;
enum Subsection {
NameFunction = 1,
diff --git a/src/wasm/wasm.cpp b/src/wasm/wasm.cpp
index c12481760..c99bb0994 100644
--- a/src/wasm/wasm.cpp
+++ b/src/wasm/wasm.cpp
@@ -32,6 +32,7 @@ const char* SourceMapUrl = "sourceMappingURL";
const char* Dylink = "dylink";
const char* Linking = "linking";
const char* Producers = "producers";
+const char* TargetFeatures = "target_features";
}
}
diff --git a/test/passes/strip-target-features.bin.txt b/test/passes/strip-target-features.bin.txt
new file mode 100644
index 000000000..914273cfb
--- /dev/null
+++ b/test/passes/strip-target-features.bin.txt
@@ -0,0 +1,3 @@
+(module
+ ;; custom section "linking", size 1
+)
diff --git a/test/passes/strip-target-features.wasm b/test/passes/strip-target-features.wasm
new file mode 100644
index 000000000..1c837a1dc
--- /dev/null
+++ b/test/passes/strip-target-features.wasm
Binary files differ