@@ -1364,8 +1364,7 @@ void ELFObjectWriter::recordRelocation(MCAssembler &Asm,
13641364 }
13651365
13661366 // We either rejected the fixup or folded B into C at this point.
1367- const auto *RefA = Target.getAddSym ();
1368- const auto *SymA = RefA ? cast<MCSymbolELF>(RefA) : nullptr ;
1367+ const auto *SymA = cast_or_null<MCSymbolELF>(Target.getAddSym ());
13691368
13701369 bool ViaWeakRef = false ;
13711370 if (SymA && SymA->isVariable ()) {
@@ -1398,33 +1397,26 @@ void ELFObjectWriter::recordRelocation(MCAssembler &Asm,
13981397 uint64_t Addend = UseSectionSym ? C + Asm.getSymbolOffset (*SymA) : C;
13991398 FixedValue = usesRela (TO, FixupSection) ? 0 : Addend;
14001399 if (UseSectionSym) {
1401- const auto *SectionSymbol =
1402- SecA ? cast<MCSymbolELF>(SecA->getBeginSymbol ()) : nullptr ;
1403- if (SectionSymbol)
1404- SectionSymbol->setUsedInReloc ();
1405- ELFRelocationEntry Rec (FixupOffset, SectionSymbol, Type, Addend);
1406- Relocations[&FixupSection].push_back (Rec);
1407- return ;
1408- }
1409-
1410- // In PPC64 ELFv1, .quad .TOC.@tocbase in the .opd section is expected to
1411- // reference the null symbol.
1412- if (Type == ELF::R_PPC64_TOC &&
1413- TargetObjectWriter->getEMachine () == ELF::EM_PPC64)
1414- SymA = nullptr ;
1415-
1416- const MCSymbolELF *RenamedSymA = SymA;
1417- if (SymA) {
1418- if (const MCSymbolELF *R = Renames.lookup (SymA))
1419- RenamedSymA = R;
1420-
1421- if (ViaWeakRef)
1422- RenamedSymA->setIsWeakrefUsedInReloc ();
1423- else
1424- RenamedSymA->setUsedInReloc ();
1400+ SymA = cast<MCSymbolELF>(SecA->getBeginSymbol ());
1401+ SymA->setUsedInReloc ();
1402+ } else {
1403+ // In PPC64 ELFv1, .quad .TOC.@tocbase in the .opd section is expected to
1404+ // reference the null symbol.
1405+ if (Type == ELF::R_PPC64_TOC &&
1406+ TargetObjectWriter->getEMachine () == ELF::EM_PPC64)
1407+ SymA = nullptr ;
1408+
1409+ if (SymA) {
1410+ if (const MCSymbolELF *R = Renames.lookup (SymA))
1411+ SymA = R;
1412+
1413+ if (ViaWeakRef)
1414+ SymA->setIsWeakrefUsedInReloc ();
1415+ else
1416+ SymA->setUsedInReloc ();
1417+ }
14251418 }
1426- ELFRelocationEntry Rec (FixupOffset, RenamedSymA, Type, Addend);
1427- Relocations[&FixupSection].push_back (Rec);
1419+ Relocations[&FixupSection].emplace_back (FixupOffset, SymA, Type, Addend);
14281420}
14291421
14301422bool ELFObjectWriter::usesRela (const MCTargetOptions *TO,
0 commit comments