@@ -434,10 +434,6 @@ void WasmObjectWriter::recordRelocation(MCAssembler &Asm,
434
434
uint64_t FixupOffset = Layout.getFragmentOffset (Fragment) + Fixup.getOffset ();
435
435
MCContext &Ctx = Asm.getContext ();
436
436
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
-
441
437
if (const MCSymbolRefExpr *RefB = Target.getSymB ()) {
442
438
assert (RefB->getKind () == MCSymbolRefExpr::VK_None &&
443
439
" Should not have constructed this" );
@@ -483,6 +479,12 @@ void WasmObjectWriter::recordRelocation(MCAssembler &Asm,
483
479
const MCSymbolRefExpr *RefA = Target.getSymA ();
484
480
const auto *SymA = RefA ? cast<MCSymbolWasm>(&RefA->getSymbol ()) : nullptr ;
485
481
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
+
486
488
if (SymA && SymA->isVariable ()) {
487
489
const MCExpr *Expr = SymA->getVariableValue ();
488
490
const auto *Inner = cast<MCSymbolRefExpr>(Expr);
@@ -1113,16 +1115,13 @@ void WasmObjectWriter::registerEventType(const MCSymbolWasm &Symbol) {
1113
1115
}
1114
1116
1115
1117
static bool isInSymtab (const MCSymbolWasm &Sym) {
1116
- if (Sym.isUsedInReloc ())
1118
+ if (Sym.isUsedInReloc () || Sym. isUsedInInitArray () )
1117
1119
return true ;
1118
1120
1119
1121
if (Sym.isComdat () && !Sym.isDefined ())
1120
1122
return false ;
1121
1123
1122
- if (Sym.isTemporary () && Sym.getName ().empty ())
1123
- return false ;
1124
-
1125
- if (Sym.isTemporary () && Sym.isData () && !Sym.getSize ())
1124
+ if (Sym.isTemporary ())
1126
1125
return false ;
1127
1126
1128
1127
if (Sym.isSection ())
@@ -1578,7 +1577,7 @@ uint64_t WasmObjectWriter::writeObject(MCAssembler &Asm,
1578
1577
report_fatal_error (" fixups in .init_array should be symbol references" );
1579
1578
const auto &TargetSym = cast<const MCSymbolWasm>(SymRef->getSymbol ());
1580
1579
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 " );
1582
1581
if (!TargetSym.isFunction ())
1583
1582
report_fatal_error (" symbols in .init_array should be for functions" );
1584
1583
InitFuncs.push_back (
0 commit comments