@@ -434,10 +434,6 @@ void WasmObjectWriter::recordRelocation(MCAssembler &Asm,
434434 uint64_t FixupOffset = Layout.getFragmentOffset (Fragment) + Fixup.getOffset ();
435435 MCContext &Ctx = Asm.getContext ();
436436
437- // The .init_array isn't translated as data, so don't do relocations in it.
438- if (FixupSection.getSectionName ().startswith (" .init_array" ))
439- return ;
440-
441437 if (const MCSymbolRefExpr *RefB = Target.getSymB ()) {
442438 assert (RefB->getKind () == MCSymbolRefExpr::VK_None &&
443439 " Should not have constructed this" );
@@ -483,6 +479,12 @@ void WasmObjectWriter::recordRelocation(MCAssembler &Asm,
483479 const MCSymbolRefExpr *RefA = Target.getSymA ();
484480 const auto *SymA = RefA ? cast<MCSymbolWasm>(&RefA->getSymbol ()) : nullptr ;
485481
482+ // The .init_array isn't translated as data, so don't do relocations in it.
483+ if (FixupSection.getSectionName ().startswith (" .init_array" )) {
484+ SymA->setUsedInInitArray ();
485+ return ;
486+ }
487+
486488 if (SymA && SymA->isVariable ()) {
487489 const MCExpr *Expr = SymA->getVariableValue ();
488490 const auto *Inner = cast<MCSymbolRefExpr>(Expr);
@@ -1113,16 +1115,13 @@ void WasmObjectWriter::registerEventType(const MCSymbolWasm &Symbol) {
11131115}
11141116
11151117static bool isInSymtab (const MCSymbolWasm &Sym) {
1116- if (Sym.isUsedInReloc ())
1118+ if (Sym.isUsedInReloc () || Sym. isUsedInInitArray () )
11171119 return true ;
11181120
11191121 if (Sym.isComdat () && !Sym.isDefined ())
11201122 return false ;
11211123
1122- if (Sym.isTemporary () && Sym.getName ().empty ())
1123- return false ;
1124-
1125- if (Sym.isTemporary () && Sym.isData () && !Sym.getSize ())
1124+ if (Sym.isTemporary ())
11261125 return false ;
11271126
11281127 if (Sym.isSection ())
@@ -1578,7 +1577,7 @@ uint64_t WasmObjectWriter::writeObject(MCAssembler &Asm,
15781577 report_fatal_error (" fixups in .init_array should be symbol references" );
15791578 const auto &TargetSym = cast<const MCSymbolWasm>(SymRef->getSymbol ());
15801579 if (TargetSym.getIndex () == InvalidIndex)
1581- report_fatal_error (" symbols in .init_array should exist in symbtab " );
1580+ report_fatal_error (" symbols in .init_array should exist in symtab " );
15821581 if (!TargetSym.isFunction ())
15831582 report_fatal_error (" symbols in .init_array should be for functions" );
15841583 InitFuncs.push_back (
0 commit comments