diff options
author | Alon Zakai <azakai@google.com> | 2023-07-17 15:53:06 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-17 15:53:06 -0700 |
commit | f96fcb0e0c15299045b828447e65754727eeab57 (patch) | |
tree | 0c257cc49394909552db8c25a20520e8185cd281 /src | |
parent | a715c5f344d170c469dddd1c4d7852fa79dc2f06 (diff) | |
download | binaryen-f96fcb0e0c15299045b828447e65754727eeab57.tar.gz binaryen-f96fcb0e0c15299045b828447e65754727eeab57.tar.bz2 binaryen-f96fcb0e0c15299045b828447e65754727eeab57.zip |
wasm-merge: Error on import loops (#5820)
Diffstat (limited to 'src')
-rw-r--r-- | src/tools/wasm-merge.cpp | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/tools/wasm-merge.cpp b/src/tools/wasm-merge.cpp index 47dd1e111..9fe97669b 100644 --- a/src/tools/wasm-merge.cpp +++ b/src/tools/wasm-merge.cpp @@ -235,16 +235,20 @@ void updateNames(Module& wasm, KindNameUpdates& kindNameUpdates) { } private: - Name resolveName(NameUpdates& updates, const Name newName) { - // Iteratively lookup the updated name - // We detect loops to ensure termination + Name resolveName(NameUpdates& updates, Name newName, Name oldName) { + // Iteratively lookup the updated name. std::set<Name> visited; - Name name = newName; + auto name = newName; while (1) { auto iter = updates.find(name); - if (iter == updates.end() || visited.find(name) != visited.end()) { + if (iter == updates.end()) { return name; } + if (visited.count(name)) { + // This is a loop of imports, which means we cannot resolve a useful + // name. Report an error. + Fatal() << "wasm-merge: infinite loop of imports on " << oldName; + } visited.insert(name); name = iter->second; } @@ -258,7 +262,7 @@ void updateNames(Module& wasm, KindNameUpdates& kindNameUpdates) { auto& nameUpdates = iter->second; auto iter2 = nameUpdates.find(name); if (iter2 != nameUpdates.end()) { - name = resolveName(nameUpdates, iter2->second); + name = resolveName(nameUpdates, iter2->second, name); } } } nameMapper(kindNameUpdates); |