@@ -1278,7 +1278,6 @@ bool ELFObjectWriter::useSectionSymbol(const MCValue &Val,
1278
1278
// If we change such a relocation to use the section, the linker would think
1279
1279
// that it pointed to another string and subtracting 42 at runtime will
1280
1280
// produce the wrong value.
1281
- auto EMachine = TargetObjectWriter->getEMachine ();
1282
1281
if (Sym->isInSection ()) {
1283
1282
auto &Sec = cast<MCSectionELF>(Sym->getSection ());
1284
1283
unsigned Flags = Sec.getFlags ();
@@ -1288,7 +1287,8 @@ bool ELFObjectWriter::useSectionSymbol(const MCValue &Val,
1288
1287
1289
1288
// gold<2.34 incorrectly ignored the addend for R_386_GOTOFF (9)
1290
1289
// (http://sourceware.org/PR16794).
1291
- if (EMachine == ELF::EM_386 && Type == ELF::R_386_GOTOFF)
1290
+ if (TargetObjectWriter->getEMachine () == ELF::EM_386 &&
1291
+ Type == ELF::R_386_GOTOFF)
1292
1292
return false ;
1293
1293
1294
1294
// ld.lld handles R_MIPS_HI16/R_MIPS_LO16 separately, not as a whole, so
@@ -1298,7 +1298,8 @@ bool ELFObjectWriter::useSectionSymbol(const MCValue &Val,
1298
1298
// (like R_RISCV_PC_INDIRECT for R_RISCV_PCREL_HI20 / R_RISCV_PCREL_LO12)
1299
1299
// but the complexity is unnecessary given that GNU as keeps the original
1300
1300
// symbol for this case as well.
1301
- if (EMachine == ELF::EM_MIPS && !hasRelocationAddend ())
1301
+ if (TargetObjectWriter->getEMachine () == ELF::EM_MIPS &&
1302
+ !hasRelocationAddend ())
1302
1303
return false ;
1303
1304
}
1304
1305
@@ -1331,14 +1332,14 @@ void ELFObjectWriter::recordRelocation(const MCFragment &F,
1331
1332
const MCFixup &Fixup, MCValue Target,
1332
1333
uint64_t &FixedValue) {
1333
1334
MCAsmBackend &Backend = Asm->getBackend ();
1334
- const MCSectionELF &FixupSection = cast<MCSectionELF>(*F.getParent ());
1335
+ const MCSectionELF &Section = cast<MCSectionELF>(*F.getParent ());
1335
1336
MCContext &Ctx = getContext ();
1336
1337
1337
1338
const auto *SymA = cast_or_null<MCSymbolELF>(Target.getAddSym ());
1338
1339
const MCSectionELF *SecA = (SymA && SymA->isInSection ())
1339
1340
? cast<MCSectionELF>(&SymA->getSection ())
1340
1341
: nullptr ;
1341
- if (DwoOS && !checkRelocation (Fixup.getLoc (), &FixupSection , SecA))
1342
+ if (DwoOS && !checkRelocation (Fixup.getLoc (), &Section , SecA))
1342
1343
return ;
1343
1344
1344
1345
bool IsPCRel = Backend.getFixupKindInfo (Fixup.getKind ()).Flags &
@@ -1356,7 +1357,7 @@ void ELFObjectWriter::recordRelocation(const MCFragment &F,
1356
1357
1357
1358
assert (!SymB.isAbsolute () && " Should have been folded" );
1358
1359
const MCSection &SecB = SymB.getSection ();
1359
- if (&SecB != &FixupSection ) {
1360
+ if (&SecB != &Section ) {
1360
1361
Ctx.reportError (Fixup.getLoc (),
1361
1362
" Cannot represent a difference across sections" );
1362
1363
return ;
@@ -1373,31 +1374,23 @@ void ELFObjectWriter::recordRelocation(const MCFragment &F,
1373
1374
else
1374
1375
Type = TargetObjectWriter->getRelocType (Fixup, Target, IsPCRel);
1375
1376
1376
- bool UseSectionSym =
1377
- SymA && SymA->getBinding () == ELF::STB_LOCAL && !SymA->isUndefined ();
1378
- if (UseSectionSym) {
1379
- UseSectionSym = useSectionSymbol (Target, SymA, Addend, Type);
1380
-
1381
- // Disable STT_SECTION adjustment for .reloc directives.
1382
- UseSectionSym &= !mc::isRelocRelocation (Fixup.getKind ());
1383
-
1384
- if (UseSectionSym)
1385
- Addend += Asm->getSymbolOffset (*SymA);
1386
- }
1387
-
1388
- FixedValue = usesRela (Ctx.getTargetOptions (), FixupSection) ? 0 : Addend;
1389
- if (UseSectionSym) {
1377
+ // Convert SymA to an STT_SECTION symbol if it's defined, local, and meets
1378
+ // specific conditions, unless it's a .reloc directive, which disables
1379
+ // STT_SECTION adjustment.
1380
+ bool UseSectionSym = SymA && SymA->getBinding () == ELF::STB_LOCAL &&
1381
+ !SymA->isUndefined () &&
1382
+ !mc::isRelocRelocation (Fixup.getKind ());
1383
+ if (UseSectionSym && useSectionSymbol (Target, SymA, Addend, Type)) {
1384
+ Addend += Asm->getSymbolOffset (*SymA);
1390
1385
SymA = cast<MCSymbolELF>(SecA->getBeginSymbol ());
1386
+ } else if (const MCSymbolELF *R = Renames.lookup (SymA)) {
1387
+ SymA = R;
1388
+ }
1389
+ if (SymA)
1391
1390
SymA->setUsedInReloc ();
1392
- } else {
1393
- if (SymA) {
1394
- if (const MCSymbolELF *R = Renames.lookup (SymA))
1395
- SymA = R;
1396
1391
1397
- SymA->setUsedInReloc ();
1398
- }
1399
- }
1400
- Relocations[&FixupSection].emplace_back (FixupOffset, SymA, Type, Addend);
1392
+ FixedValue = usesRela (Ctx.getTargetOptions (), Section) ? 0 : Addend;
1393
+ Relocations[&Section].emplace_back (FixupOffset, SymA, Type, Addend);
1401
1394
}
1402
1395
1403
1396
bool ELFObjectWriter::usesRela (const MCTargetOptions *TO,
0 commit comments