@@ -130,19 +130,30 @@ int main(int argc, const char *argv[]) {
130130 WasmPrinter::printModule (&wasm, std::cerr);
131131 }
132132
133- Export* dataEndExport = wasm.getExport (" __data_end" );
134- if (dataEndExport == nullptr ) {
135- Fatal () << " __data_end export not found" ;
133+ bool isSideModule = false ;
134+ for (const UserSection& section : wasm.userSections ) {
135+ if (section.name == BinaryConsts::UserSections::Dylink) {
136+ isSideModule = true ;
137+ }
136138 }
137- Global* dataEnd = wasm.getGlobal (dataEndExport->value );
138- if (dataEnd == nullptr ) {
139- Fatal () << " __data_end global not found" ;
140- }
141- if (dataEnd->type != Type::i32 ) {
142- Fatal () << " __data_end global has wrong type" ;
139+
140+ uint32_t dataSize = 0 ;
141+
142+ if (!isSideModule) {
143+ Export* dataEndExport = wasm.getExport (" __data_end" );
144+ if (dataEndExport == nullptr ) {
145+ Fatal () << " __data_end export not found" ;
146+ }
147+ Global* dataEnd = wasm.getGlobal (dataEndExport->value );
148+ if (dataEnd == nullptr ) {
149+ Fatal () << " __data_end global not found" ;
150+ }
151+ if (dataEnd->type != Type::i32 ) {
152+ Fatal () << " __data_end global has wrong type" ;
153+ }
154+ Const* dataEndConst = dataEnd->init ->cast <Const>();
155+ dataSize = dataEndConst->value .geti32 () - globalBase;
143156 }
144- Const* dataEndConst = dataEnd->init ->cast <Const>();
145- uint32_t dataSize = dataEndConst->value .geti32 () - globalBase;
146157
147158 std::vector<Name> initializerFunctions;
148159 if (wasm.getFunctionOrNull (" __wasm_call_ctors" )) {
@@ -160,8 +171,10 @@ int main(int argc, const char *argv[]) {
160171 passRunner.run ();
161172 }
162173
163- generator.generateRuntimeFunctions ();
164- generator.generateMemoryGrowthFunction ();
174+ if (!isSideModule) {
175+ generator.generateRuntimeFunctions ();
176+ generator.generateMemoryGrowthFunction ();
177+ }
165178 generator.generateDynCallThunks ();
166179 generator.generateJSCallThunks (numReservedFunctionPointers);
167180 std::string metadata = generator.generateEmscriptenMetadata (dataSize, initializerFunctions, numReservedFunctionPointers);
0 commit comments