diff --git a/libyul/backends/wasm/BinaryTransform.cpp b/libyul/backends/wasm/BinaryTransform.cpp index 58a34ac04..87f47e28c 100644 --- a/libyul/backends/wasm/BinaryTransform.cpp +++ b/libyul/backends/wasm/BinaryTransform.cpp @@ -305,13 +305,15 @@ bytes BinaryTransform::run(Module const& _module) ret += exportSection(functionIDs); map> subModulePosAndSize; - for (auto const& sub: _module.subModules) + for (auto const& [name, module]: _module.subModules) { // TODO should we prefix and / or shorten the name? - bytes data = BinaryTransform::run(sub.second); - size_t length = data.size(); - ret += customSection(sub.first, move(data)); - subModulePosAndSize[sub.first] = {ret.size() - length, length}; + bytes data = BinaryTransform::run(module); + size_t const length = data.size(); + ret += customSection(name, move(data)); + // Skip all the previous sections and the size field of this current custom section. + size_t const offset = ret.size() - length; + subModulePosAndSize[name] = {offset, length}; } BinaryTransform bt( diff --git a/libyul/backends/wasm/BinaryTransform.h b/libyul/backends/wasm/BinaryTransform.h index 348250546..d164c11bf 100644 --- a/libyul/backends/wasm/BinaryTransform.h +++ b/libyul/backends/wasm/BinaryTransform.h @@ -112,6 +112,8 @@ private: std::map const m_globalIDs; std::map const m_functionIDs; std::map const m_functionTypes; + /// The map of submodules, where the pair refers to the [offset, length]. The offset is + /// an absolute offset within the resulting assembled bytecode. std::map> const m_subModulePosAndSize; std::map m_locals;