@@ -1145,6 +1145,8 @@ void Writer::createSyntheticInitFunctions() {
11451145
11461146 static WasmSignature nullSignature = {{}, {}};
11471147
1148+ createApplyDataRelocationsFunction ();
1149+
11481150 // Passive segments are used to avoid memory being reinitialized on each
11491151 // thread's instantiation. These passive segments are initialized and
11501152 // dropped in __wasm_init_memory, which is registered as the start function
@@ -1467,15 +1469,29 @@ void Writer::createApplyDataRelocationsFunction() {
14671469 {
14681470 raw_string_ostream os (bodyContent);
14691471 writeUleb128 (os, 0 , " num locals" );
1472+ uint64_t off = os.tell ();
14701473 for (const OutputSegment *seg : segments)
14711474 if (!config->sharedMemory || !seg->isTLS ())
14721475 for (const InputChunk *inSeg : seg->inputSegments )
14731476 inSeg->generateRelocationCode (os);
14741477
1478+ if (off == os.tell ()) {
1479+ LLVM_DEBUG (dbgs () << " skipping empty __wasm_apply_data_relocs\n " );
1480+ return ;
1481+ }
14751482 writeU8 (os, WASM_OPCODE_END, " END" );
14761483 }
14771484
1478- createFunction (WasmSym::applyDataRelocs, bodyContent);
1485+ // __wasm_apply_data_relocs
1486+ // Function that applies relocations to data segment post-instantiation.
1487+ static WasmSignature nullSignature = {{}, {}};
1488+ auto def = symtab->addSyntheticFunction (
1489+ " __wasm_apply_data_relocs" ,
1490+ WASM_SYMBOL_VISIBILITY_DEFAULT | WASM_SYMBOL_EXPORTED,
1491+ make<SyntheticFunction>(nullSignature, " __wasm_apply_data_relocs" ));
1492+ def->markLive ();
1493+
1494+ createFunction (def, bodyContent);
14791495}
14801496
14811497void Writer::createApplyTLSRelocationsFunction () {
@@ -1771,8 +1787,6 @@ void Writer::run() {
17711787
17721788 if (!config->relocatable ) {
17731789 // Create linker synthesized functions
1774- if (WasmSym::applyDataRelocs)
1775- createApplyDataRelocationsFunction ();
17761790 if (WasmSym::applyGlobalRelocs)
17771791 createApplyGlobalRelocationsFunction ();
17781792 if (WasmSym::applyTLSRelocs)
0 commit comments