Skip to content

Commit e373f7a

Browse files
committed
MC: Simplify recordRelocation
* Remove the MCAssembler * argument. Change subclasses to use MCAssembler *MCObjectWriter::Asm. * Remove pure specifier and add an empty implementation * Change MCFragment * to MCFragment &
1 parent 346a72f commit e373f7a

17 files changed

+63
-85
lines changed

llvm/include/llvm/MC/MCDXContainerWriter.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,6 @@ class DXContainerObjectWriter final : public MCObjectWriter {
4242
raw_pwrite_stream &OS)
4343
: W(OS, llvm::endianness::little), TargetObjectWriter(std::move(MOTW)) {}
4444

45-
void recordRelocation(MCAssembler &Asm, const MCFragment *Fragment,
46-
const MCFixup &Fixup, MCValue Target,
47-
uint64_t &FixedValue) override {}
48-
4945
uint64_t writeObject(MCAssembler &Asm) override;
5046
};
5147
} // end namespace llvm

llvm/include/llvm/MC/MCELFObjectWriter.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,8 @@ class ELFObjectWriter final : public MCObjectWriter {
170170

171171
void reset() override;
172172
void executePostLayoutBinding() override;
173-
void recordRelocation(MCAssembler &Asm, const MCFragment *Fragment,
174-
const MCFixup &Fixup, MCValue Target,
175-
uint64_t &FixedValue) override;
173+
void recordRelocation(const MCFragment &F, const MCFixup &Fixup,
174+
MCValue Target, uint64_t &FixedValue) override;
176175
bool isSymbolRefDifferenceFullyResolvedImpl(const MCSymbol &SymA,
177176
const MCFragment &FB, bool InSet,
178177
bool IsPCRel) const override;

llvm/include/llvm/MC/MCMachObjectWriter.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,8 @@ class MachObjectWriter final : public MCObjectWriter {
327327
Relocations[Sec].push_back(P);
328328
}
329329

330-
void recordRelocation(MCAssembler &Asm, const MCFragment *Fragment,
331-
const MCFixup &Fixup, MCValue Target,
332-
uint64_t &FixedValue) override;
330+
void recordRelocation(const MCFragment &F, const MCFixup &Fixup,
331+
MCValue Target, uint64_t &FixedValue) override;
333332

334333
void bindIndirectSymbols(MCAssembler &Asm);
335334

llvm/include/llvm/MC/MCObjectWriter.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,8 @@ class MCObjectWriter {
7878
/// post layout binding. The implementation is responsible for storing
7979
/// information about the relocation so that it can be emitted during
8080
/// writeObject().
81-
virtual void recordRelocation(MCAssembler &Asm, const MCFragment *Fragment,
82-
const MCFixup &Fixup, MCValue Target,
83-
uint64_t &FixedValue) = 0;
81+
virtual void recordRelocation(const MCFragment &F, const MCFixup &Fixup,
82+
MCValue Target, uint64_t &FixedValue);
8483

8584
/// Check whether the difference (A - B) between two symbol references is
8685
/// fully resolved.

llvm/include/llvm/MC/MCSPIRVObjectWriter.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@ class SPIRVObjectWriter final : public MCObjectWriter {
4646
void setBuildVersion(unsigned Major, unsigned Minor, unsigned Bound);
4747

4848
private:
49-
void recordRelocation(MCAssembler &Asm, const MCFragment *Fragment,
50-
const MCFixup &Fixup, MCValue Target,
51-
uint64_t &FixedValue) override {}
52-
5349
uint64_t writeObject(MCAssembler &Asm) override;
5450
void writeHeader(const MCAssembler &Asm);
5551
};

llvm/include/llvm/MC/MCWinCOFFObjectWriter.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,8 @@ class WinCOFFObjectWriter final : public MCObjectWriter {
6767
bool isSymbolRefDifferenceFullyResolvedImpl(const MCSymbol &SymA,
6868
const MCFragment &FB, bool InSet,
6969
bool IsPCRel) const override;
70-
void recordRelocation(MCAssembler &Asm, const MCFragment *Fragment,
71-
const MCFixup &Fixup, MCValue Target,
72-
uint64_t &FixedValue) override;
70+
void recordRelocation(const MCFragment &F, const MCFixup &Fixup,
71+
MCValue Target, uint64_t &FixedValue) override;
7372
uint64_t writeObject(MCAssembler &Asm) override;
7473
int getSectionNumber(const MCSection &Section) const;
7574
};

llvm/lib/MC/ELFObjectWriter.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,12 +1322,11 @@ bool ELFObjectWriter::checkRelocation(MCContext &Ctx, SMLoc Loc,
13221322
return true;
13231323
}
13241324

1325-
void ELFObjectWriter::recordRelocation(MCAssembler &Asm,
1326-
const MCFragment *Fragment,
1325+
void ELFObjectWriter::recordRelocation(const MCFragment &F,
13271326
const MCFixup &Fixup, MCValue Target,
13281327
uint64_t &FixedValue) {
1329-
MCAsmBackend &Backend = Asm.getBackend();
1330-
const MCSectionELF &FixupSection = cast<MCSectionELF>(*Fragment->getParent());
1328+
MCAsmBackend &Backend = Asm->getBackend();
1329+
const MCSectionELF &FixupSection = cast<MCSectionELF>(*F.getParent());
13311330
MCContext &Ctx = getContext();
13321331

13331332
const auto *SymA = cast_or_null<MCSymbolELF>(Target.getAddSym());
@@ -1350,7 +1349,7 @@ void ELFObjectWriter::recordRelocation(MCAssembler &Asm,
13501349

13511350
bool IsPCRel = Backend.getFixupKindInfo(Fixup.getKind()).Flags &
13521351
MCFixupKindInfo::FKF_IsPCRel;
1353-
uint64_t FixupOffset = Asm.getFragmentOffset(*Fragment) + Fixup.getOffset();
1352+
uint64_t FixupOffset = Asm->getFragmentOffset(F) + Fixup.getOffset();
13541353
uint64_t Addend = Target.getConstant();
13551354
if (auto *RefB = Target.getSubSym()) {
13561355
const auto &SymB = cast<MCSymbolELF>(*RefB);
@@ -1371,7 +1370,7 @@ void ELFObjectWriter::recordRelocation(MCAssembler &Asm,
13711370

13721371
assert(!IsPCRel && "should have been folded");
13731372
IsPCRel = true;
1374-
Addend += FixupOffset - Asm.getSymbolOffset(SymB);
1373+
Addend += FixupOffset - Asm->getSymbolOffset(SymB);
13751374
}
13761375

13771376
unsigned Type;
@@ -1383,13 +1382,13 @@ void ELFObjectWriter::recordRelocation(MCAssembler &Asm,
13831382
bool UseSectionSym =
13841383
SymA && SymA->getBinding() == ELF::STB_LOCAL && !SymA->isUndefined();
13851384
if (UseSectionSym) {
1386-
UseSectionSym = useSectionSymbol(Asm, Target, SymA, Addend, Type);
1385+
UseSectionSym = useSectionSymbol(*Asm, Target, SymA, Addend, Type);
13871386

13881387
// Disable STT_SECTION adjustment for .reloc directives.
13891388
UseSectionSym &= !mc::isRelocRelocation(Fixup.getKind());
13901389

13911390
if (UseSectionSym)
1392-
Addend += Asm.getSymbolOffset(*SymA);
1391+
Addend += Asm->getSymbolOffset(*SymA);
13931392
}
13941393

13951394
FixedValue = usesRela(Ctx.getTargetOptions(), FixupSection) ? 0 : Addend;

llvm/lib/MC/GOFFObjectWriter.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,8 @@ class GOFFObjectWriter : public MCObjectWriter {
243243
void writeEnd();
244244

245245
// Implementation of the MCObjectWriter interface.
246-
void recordRelocation(MCAssembler &Asm, const MCFragment *Fragment,
247-
const MCFixup &Fixup, MCValue Target,
248-
uint64_t &FixedValue) override {}
246+
void recordRelocation(const MCFragment &F, const MCFixup &Fixup,
247+
MCValue Target, uint64_t &FixedValue) override {}
249248
uint64_t writeObject(MCAssembler &Asm) override;
250249
};
251250
} // end anonymous namespace

llvm/lib/MC/MCAsmBackend.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ bool MCAsmBackend::addReloc(const MCFragment &F, const MCFixup &Fixup,
126126
if (IsResolved && shouldForceRelocation(Fixup, Target))
127127
IsResolved = false;
128128
if (!IsResolved)
129-
Asm->getWriter().recordRelocation(*Asm, &F, Fixup, Target, FixedValue);
129+
Asm->getWriter().recordRelocation(F, Fixup, Target, FixedValue);
130130
return IsResolved;
131131
}
132132

llvm/lib/MC/MCObjectWriter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "llvm/MC/MCExpr.h"
1212
#include "llvm/MC/MCFragment.h"
1313
#include "llvm/MC/MCSymbol.h"
14+
#include "llvm/MC/MCValue.h"
1415
namespace llvm {
1516
class MCSection;
1617
}
@@ -29,6 +30,9 @@ void MCObjectWriter::reset() {
2930
CGProfile.clear();
3031
}
3132

33+
void MCObjectWriter::recordRelocation(const MCFragment &F, const MCFixup &Fixup,
34+
MCValue Target, uint64_t &FixedValue) {}
35+
3236
bool MCObjectWriter::isSymbolRefDifferenceFullyResolved(const MCSymbol &SA,
3337
const MCSymbol &SB,
3438
bool InSet) const {

0 commit comments

Comments
 (0)