Skip to content

Commit db603a0

Browse files
committed
[MC] Move ELF-specific handleAddSubRelocations to ELFObjectWriter::recordRelocation
1 parent d8b078d commit db603a0

File tree

4 files changed

+10
-7
lines changed

4 files changed

+10
-7
lines changed

llvm/lib/MC/ELFObjectWriter.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,6 +1377,12 @@ void ELFObjectWriter::recordRelocation(MCAssembler &Asm,
13771377
const MCTargetOptions *TO = Ctx.getTargetOptions();
13781378

13791379
if (auto *RefB = Target.getSubSym()) {
1380+
// When there is no relocation specifier, a linker relaxation target may
1381+
// emit ADD/SUB relocations for A-B+C.
1382+
if (Target.getSymA() && Backend.handleAddSubRelocations(
1383+
Asm, *Fragment, Fixup, Target, FixedValue))
1384+
return;
1385+
13801386
const auto &SymB = cast<MCSymbolELF>(*RefB);
13811387
if (SymB.isUndefined()) {
13821388
Ctx.reportError(Fixup.getLoc(),

llvm/lib/MC/MCAssembler.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -234,13 +234,6 @@ bool MCAssembler::evaluateFixup(const MCFixup &Fixup, const MCFragment *DF,
234234
}
235235
}
236236

237-
// A linker relaxation target may emit ADD/SUB relocations for A-B+C. Let
238-
// recordRelocation handle non-VK_None cases like A@plt-B+C.
239-
if (!IsResolved && Target.getSymA() && Target.getSubSym() &&
240-
Target.getRefKind() == 0 &&
241-
getBackend().handleAddSubRelocations(*this, *DF, Fixup, Target, Value))
242-
return true;
243-
244237
return IsResolved;
245238
}
246239

llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,8 @@ bool LoongArchAsmBackend::handleAddSubRelocations(const MCAssembler &Asm,
452452
const MCFixup &Fixup,
453453
const MCValue &Target,
454454
uint64_t &FixedValue) const {
455+
assert(Target.getRefKind() == 0 &&
456+
"relocatable SymA-SymB cannot have relocation specifier");
455457
std::pair<MCFixupKind, MCFixupKind> FK;
456458
uint64_t FixedValueA, FixedValueB;
457459
const MCSymbol &SA = Target.getSymA()->getSymbol();

llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,8 @@ bool RISCVAsmBackend::handleAddSubRelocations(const MCAssembler &Asm,
590590
const MCFixup &Fixup,
591591
const MCValue &Target,
592592
uint64_t &FixedValue) const {
593+
assert(Target.getRefKind() == 0 &&
594+
"relocatable SymA-SymB cannot have relocation specifier");
593595
uint64_t FixedValueA, FixedValueB;
594596
unsigned TA = 0, TB = 0;
595597
switch (Fixup.getKind()) {

0 commit comments

Comments
 (0)