summaryrefslogtreecommitdiff
path: root/src/tools/wasm-split.cpp
diff options
context:
space:
mode:
authorThomas Lively <7121787+tlively@users.noreply.github.com>2021-05-18 19:33:58 -0700
committerGitHub <noreply@github.com>2021-05-19 02:33:58 +0000
commitf308e37f42c33d18bafbbbf821a70a1ca2d7e655 (patch)
tree26ae7b0d01e83912fb311a09350c022f3c80a240 /src/tools/wasm-split.cpp
parent8099dd859dc2732bea9b9f0c56440bb34a4d22c3 (diff)
downloadbinaryen-f308e37f42c33d18bafbbbf821a70a1ca2d7e655.tar.gz
binaryen-f308e37f42c33d18bafbbbf821a70a1ca2d7e655.tar.bz2
binaryen-f308e37f42c33d18bafbbbf821a70a1ca2d7e655.zip
[wasm-split] Add a --symbolmap option (#3894)
The new option emits a symbol map file for each of the split modules. The file names are created by appending ".symbols" to each of the Wasm output file names.
Diffstat (limited to 'src/tools/wasm-split.cpp')
-rw-r--r--src/tools/wasm-split.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/tools/wasm-split.cpp b/src/tools/wasm-split.cpp
index 171774d82..272582e65 100644
--- a/src/tools/wasm-split.cpp
+++ b/src/tools/wasm-split.cpp
@@ -20,6 +20,7 @@
#include "ir/module-splitting.h"
#include "ir/module-utils.h"
#include "ir/names.h"
+#include "pass.h"
#include "support/file.h"
#include "support/name.h"
#include "support/utilities.h"
@@ -48,6 +49,7 @@ std::set<Name> parseNameList(const std::string& list) {
struct WasmSplitOptions : ToolOptions {
bool verbose = false;
bool emitBinary = true;
+ bool symbolMap = false;
bool instrument = false;
@@ -140,6 +142,12 @@ WasmSplitOptions::WasmSplitOptions()
[&](Options* o, const std::string& argument) {
secondaryOutput = argument;
})
+ .add("--symbolmap",
+ "",
+ "Write a symbol map file for each of the output modules. Not usable "
+ "with --instrument.",
+ Options::Arguments::Zero,
+ [&](Options* o, const std::string& argument) { symbolMap = true; })
.add("--import-namespace",
"",
"The namespace from which to import objects from the primary "
@@ -228,6 +236,9 @@ bool WasmSplitOptions::validate() {
if (splitFuncs.size()) {
fail("--split-funcs cannot be used with --instrument");
}
+ if (symbolMap) {
+ fail("--symbolmap cannot be used with --instrument");
+ }
} else {
if (output.size()) {
fail(
@@ -552,6 +563,14 @@ std::set<Name> readProfile(Module& wasm, const WasmSplitOptions& options) {
return keptFuncs;
}
+void writeSymbolMap(Module& wasm, std::string filename) {
+ PassOptions options;
+ options.arguments["symbolmap"] = filename;
+ PassRunner runner(&wasm, options);
+ runner.add("symbolmap");
+ runner.run();
+}
+
void splitModule(Module& wasm, const WasmSplitOptions& options) {
std::set<Name> keepFuncs;
@@ -641,6 +660,11 @@ void splitModule(Module& wasm, const WasmSplitOptions& options) {
adjustTableSize(wasm, options.initialTableSize);
adjustTableSize(*secondary, options.initialTableSize);
+ if (options.symbolMap) {
+ writeSymbolMap(wasm, options.primaryOutput + ".symbols");
+ writeSymbolMap(*secondary, options.secondaryOutput + ".symbols");
+ }
+
// Write the output modules
ModuleWriter writer;
writer.setBinary(options.emitBinary);