@@ -436,10 +436,6 @@ void WasmObjectWriter::recordRelocation(MCAssembler &Asm,
436436 uint64_t FixupOffset = Layout.getFragmentOffset (Fragment) + Fixup.getOffset ();
437437 MCContext &Ctx = Asm.getContext ();
438438
439- // The .init_array isn't translated as data, so don't do relocations in it.
440- if (FixupSection.getSectionName ().startswith (" .init_array" ))
441- return ;
442-
443439 if (const MCSymbolRefExpr *RefB = Target.getSymB ()) {
444440 // To get here the A - B expression must have failed evaluateAsRelocatable.
445441 // This means either A or B must be undefined and in WebAssembly we can't
@@ -456,6 +452,12 @@ void WasmObjectWriter::recordRelocation(MCAssembler &Asm,
456452 const MCSymbolRefExpr *RefA = Target.getSymA ();
457453 const auto *SymA = cast<MCSymbolWasm>(&RefA->getSymbol ());
458454
455+ // The .init_array isn't translated as data, so don't do relocations in it.
456+ if (FixupSection.getSectionName ().startswith (" .init_array" )) {
457+ SymA->setUsedInInitArray ();
458+ return ;
459+ }
460+
459461 if (SymA->isVariable ()) {
460462 const MCExpr *Expr = SymA->getVariableValue ();
461463 const auto *Inner = cast<MCSymbolRefExpr>(Expr);
@@ -1084,16 +1086,13 @@ void WasmObjectWriter::registerEventType(const MCSymbolWasm &Symbol) {
10841086}
10851087
10861088static bool isInSymtab (const MCSymbolWasm &Sym) {
1087- if (Sym.isUsedInReloc ())
1089+ if (Sym.isUsedInReloc () || Sym. isUsedInInitArray () )
10881090 return true ;
10891091
10901092 if (Sym.isComdat () && !Sym.isDefined ())
10911093 return false ;
10921094
1093- if (Sym.isTemporary () && Sym.getName ().empty ())
1094- return false ;
1095-
1096- if (Sym.isTemporary () && Sym.isData () && !Sym.getSize ())
1095+ if (Sym.isTemporary ())
10971096 return false ;
10981097
10991098 if (Sym.isSection ())
@@ -1565,7 +1564,7 @@ uint64_t WasmObjectWriter::writeObject(MCAssembler &Asm,
15651564 report_fatal_error (" fixups in .init_array should be symbol references" );
15661565 const auto &TargetSym = cast<const MCSymbolWasm>(SymRef->getSymbol ());
15671566 if (TargetSym.getIndex () == InvalidIndex)
1568- report_fatal_error (" symbols in .init_array should exist in symbtab " );
1567+ report_fatal_error (" symbols in .init_array should exist in symtab " );
15691568 if (!TargetSym.isFunction ())
15701569 report_fatal_error (" symbols in .init_array should be for functions" );
15711570 InitFuncs.push_back (
0 commit comments