@@ -1364,8 +1364,7 @@ void ELFObjectWriter::recordRelocation(MCAssembler &Asm,
1364
1364
}
1365
1365
1366
1366
// 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 ());
1369
1368
1370
1369
bool ViaWeakRef = false ;
1371
1370
if (SymA && SymA->isVariable ()) {
@@ -1398,33 +1397,26 @@ void ELFObjectWriter::recordRelocation(MCAssembler &Asm,
1398
1397
uint64_t Addend = UseSectionSym ? C + Asm.getSymbolOffset (*SymA) : C;
1399
1398
FixedValue = usesRela (TO, FixupSection) ? 0 : Addend;
1400
1399
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
+ }
1425
1418
}
1426
- ELFRelocationEntry Rec (FixupOffset, RenamedSymA, Type, Addend);
1427
- Relocations[&FixupSection].push_back (Rec);
1419
+ Relocations[&FixupSection].emplace_back (FixupOffset, SymA, Type, Addend);
1428
1420
}
1429
1421
1430
1422
bool ELFObjectWriter::usesRela (const MCTargetOptions *TO,
0 commit comments