From 028f47368fe844130f52ad7811c8028ebd18a38e Mon Sep 17 00:00:00 2001 From: Thomas Lively <7121787+tlively@users.noreply.github.com> Date: Tue, 1 Jun 2021 12:15:24 -0400 Subject: [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. --- src/ir/module-splitting.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/ir/module-splitting.cpp') 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 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; -- cgit v1.2.3