Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/tools/wasm-merge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -852,10 +852,15 @@ Input source maps can be specified by adding an -ism option right after the modu
// The functions in the module have been renamed and copied rather than
// moved, so we can get their final names directly. (We don't need this
// for the first module because it does not appear in the manifest.)
auto& funcs = moduleFuncs[inputFileName];
for (auto& func : currModule->functions) {
if (!func->imported()) {
funcs.push_back(func->name);
if (!manifestFile.empty()) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NFC: I wrapped the whole for loop with if(!manifstFile.empty()), given that funcs will only be used for the output manifest file generation.

auto& funcs = moduleFuncs[inputFileName];
for (auto& func : currModule->functions) {
if (!func->imported()) {
funcs.push_back(func->name);
// Even if the function name is empty, if we were to put it in the
// output manifest, it has to be emitted in the name section.
merged.getFunction(func->name)->hasExplicitName = true;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function might have been renamed when it was copied to the merged module, so func->name might refer to a different function, right? I think we have to make the name explicit at the point where we add the copied function to the merged module.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renaming is done in in-place currModule before merging, so it will refer to the same function.

// Rename things in the input module so that there are no conflicts with names
// in the merged module. We do so in place for efficiency.
renameInputItems(input);

}
}
}

Expand Down
29 changes: 29 additions & 0 deletions test/lit/merge/manifest-explicit-name.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
;; RUN: wasm-merge %s first %s second --rename-export-conflicts --output-manifest %t.manifest -o %t.wasm
;; RUN: cat %t.manifest | filecheck %s
;; RUN: wasm-dis %t.wasm -o - | filecheck %s --check-prefix MERGED

;; This tests if the internal names of empty function names are correctly
;; preserved in the name section so that they can match the names in the
;; manifest file.

;; CHECK: second
;; CHECK-NEXT: 0_1
;; CHECK-NEXT:

;; MERGED: (module
;; MERGED-NEXT: (type $0 (func))
;; MERGED-NEXT: (export "foo" (func $0))
;; MERGED-NEXT: (export "foo_1" (func $0_1))
;; MERGED-NEXT: (func $0
;; MERGED-NEXT: (nop)
;; MERGED-NEXT: )
;; MERGED-NEXT: (func $0_1
;; MERGED-NEXT: (nop)
;; MERGED-NEXT: )
;; MERGED-NEXT: )

(module
(func (export "foo")
nop
)
)
Loading