@@ -436,10 +436,6 @@ void WasmObjectWriter::recordRelocation(MCAssembler &Asm,
436
436
uint64_t FixupOffset = Layout.getFragmentOffset (Fragment) + Fixup.getOffset ();
437
437
MCContext &Ctx = Asm.getContext ();
438
438
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
-
443
439
if (const MCSymbolRefExpr *RefB = Target.getSymB ()) {
444
440
// To get here the A - B expression must have failed evaluateAsRelocatable.
445
441
// This means either A or B must be undefined and in WebAssembly we can't
@@ -456,6 +452,12 @@ void WasmObjectWriter::recordRelocation(MCAssembler &Asm,
456
452
const MCSymbolRefExpr *RefA = Target.getSymA ();
457
453
const auto *SymA = cast<MCSymbolWasm>(&RefA->getSymbol ());
458
454
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
+
459
461
if (SymA->isVariable ()) {
460
462
const MCExpr *Expr = SymA->getVariableValue ();
461
463
const auto *Inner = cast<MCSymbolRefExpr>(Expr);
@@ -1084,16 +1086,13 @@ void WasmObjectWriter::registerEventType(const MCSymbolWasm &Symbol) {
1084
1086
}
1085
1087
1086
1088
static bool isInSymtab (const MCSymbolWasm &Sym) {
1087
- if (Sym.isUsedInReloc ())
1089
+ if (Sym.isUsedInReloc () || Sym. isUsedInInitArray () )
1088
1090
return true ;
1089
1091
1090
1092
if (Sym.isComdat () && !Sym.isDefined ())
1091
1093
return false ;
1092
1094
1093
- if (Sym.isTemporary () && Sym.getName ().empty ())
1094
- return false ;
1095
-
1096
- if (Sym.isTemporary () && Sym.isData () && !Sym.getSize ())
1095
+ if (Sym.isTemporary ())
1097
1096
return false ;
1098
1097
1099
1098
if (Sym.isSection ())
@@ -1565,7 +1564,7 @@ uint64_t WasmObjectWriter::writeObject(MCAssembler &Asm,
1565
1564
report_fatal_error (" fixups in .init_array should be symbol references" );
1566
1565
const auto &TargetSym = cast<const MCSymbolWasm>(SymRef->getSymbol ());
1567
1566
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 " );
1569
1568
if (!TargetSym.isFunction ())
1570
1569
report_fatal_error (" symbols in .init_array should be for functions" );
1571
1570
InitFuncs.push_back (
0 commit comments