diff options
author | Thomas Lively <7121787+tlively@users.noreply.github.com> | 2021-06-01 12:15:24 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-01 09:15:24 -0700 |
commit | 028f47368fe844130f52ad7811c8028ebd18a38e (patch) | |
tree | 7c6b2a68a55f922d70f534abd594d900079139b3 /src | |
parent | 88606f75b97ef3014edb74484125534c2040095b (diff) | |
download | binaryen-028f47368fe844130f52ad7811c8028ebd18a38e.tar.gz binaryen-028f47368fe844130f52ad7811c8028ebd18a38e.tar.bz2 binaryen-028f47368fe844130f52ad7811c8028ebd18a38e.zip |
[wasm-split] Minimize names of newly created exports (#3905)
wasm-split would previously use internal function names to create the external
names of the functions that are newly exported from the primary module to be
imported into the secondary module. When the input module contains full function
names (as is commonly the case when emitting symbol maps), this caused the
function names to be preserved as the export names, even when names are
otherwise being stripped. To save on code size and properly anonymize functions,
generate minimal export names when debuginfo is disabled instead.
Diffstat (limited to 'src')
-rw-r--r-- | src/ir/module-splitting.cpp | 12 | ||||
-rw-r--r-- | src/ir/module-splitting.h | 4 | ||||
-rw-r--r-- | src/tools/wasm-split.cpp | 1 |
3 files changed, 15 insertions, 2 deletions
diff --git a/src/ir/module-splitting.cpp b/src/ir/module-splitting.cpp index 5f9ba0aad..d6dca8994 100644 --- a/src/ir/module-splitting.cpp +++ b/src/ir/module-splitting.cpp @@ -266,6 +266,8 @@ struct ModuleSplitter { TableSlotManager tableManager; + Names::MinifiedNameGenerator minified; + // Map from internal function names to (one of) their corresponding export // names. std::map<Name, Name> exportedPrimaryFuncs; @@ -344,8 +346,14 @@ void ModuleSplitter::exportImportFunction(Name funcName) { if (exportIt != exportedPrimaryFuncs.end()) { exportName = exportIt->second; } else { - exportName = Names::getValidExportName( - primary, config.newExportPrefix + funcName.c_str()); + if (config.minimizeNewExportNames) { + do { + exportName = config.newExportPrefix + minified.getName(); + } while (primary.getExportOrNull(exportName) != nullptr); + } else { + exportName = Names::getValidExportName( + primary, config.newExportPrefix + funcName.c_str()); + } primary.addExport( Builder::makeExport(exportName, funcName, ExternalKind::Function)); exportedPrimaryFuncs[funcName] = exportName; diff --git a/src/ir/module-splitting.h b/src/ir/module-splitting.h index 9a2597067..479fba148 100644 --- a/src/ir/module-splitting.h +++ b/src/ir/module-splitting.h @@ -62,6 +62,10 @@ struct Config { // used to differentiate between "real" exports of the module and exports that // should only be consumed by the secondary module. std::string newExportPrefix = ""; + // Whether the export names of newly created exports should be minimized. If + // false, the original function names will be used (after `newExportPrefix`) + // as the new export names. + bool minimizeNewExportNames = false; }; // Returns the new secondary module and modifies the `primary` module in place. diff --git a/src/tools/wasm-split.cpp b/src/tools/wasm-split.cpp index 3ac8b2c45..7f3fe65c4 100644 --- a/src/tools/wasm-split.cpp +++ b/src/tools/wasm-split.cpp @@ -676,6 +676,7 @@ void splitModule(Module& wasm, const WasmSplitOptions& options) { if (options.exportPrefix.size()) { config.newExportPrefix = options.exportPrefix; } + config.minimizeNewExportNames = !options.passOptions.debugInfo; std::unique_ptr<Module> secondary = ModuleSplitting::splitFunctions(wasm, config); |