Skip to content

Binary Reading: Don't pick internal names for things that overlap with the name section #7700

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
15 changes: 9 additions & 6 deletions src/wasm/wasm-binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2518,12 +2518,15 @@ getOrMakeName(const std::unordered_map<Index, Name>& nameMap,
Name name,
std::unordered_set<Name>& usedNames) {
if (auto it = nameMap.find(i); it != nameMap.end()) {
return {it->second, true};
} else {
auto valid = Names::getValidNameGivenExisting(name, usedNames);
usedNames.insert(valid);
return {valid, false};
}
// We found a name in the names section. Use it, and also note it as used
// so we don't generate such a name below, later.
Comment on lines +2521 to +2522
Copy link
Member

Choose a reason for hiding this comment

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

Is there anything stopping us from generating a name below and later running into it in the names section?

Copy link
Member Author

Choose a reason for hiding this comment

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

I believe this code aims to avoid that, be pre-populating the names:

void WasmBinaryReader::readFunctionSignatures() {
size_t num = getU32LEB();
auto numImports = wasm.functions.size();
std::unordered_set<Name> usedNames;
for (auto& [index, name] : functionNames) {
if (index >= num + numImports) {
std::cerr << "warning: function index out of bounds in name section: "
<< name << " at index " << index << '\n';
}
usedNames.insert(name);
}

But that raises the question of why that didn't fix this issue. Unfortunately, I can only reproduce this with an experimental pass not yet in a PR, so I don't have a good testcase. Anyhow, let's hold off on this until that PR is ready.

auto mappedName = it->second;
usedNames.insert(mappedName);
return {mappedName, true};
}
auto valid = Names::getValidNameGivenExisting(name, usedNames);
usedNames.insert(valid);
return {valid, false};
}

void WasmBinaryReader::readMemories() {
Expand Down
Loading