Skip to content

Commit 4289c42

Browse files
committed
[MC] Remove the MCAsmLayout parameter from MCObjectWriter::recordRelocation
1 parent 262ad4c commit 4289c42

13 files changed

+54
-62
lines changed

llvm/include/llvm/MC/MCMachObjectWriter.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,9 @@ class MachObjectWriter : public MCObjectWriter {
237237
Relocations[Sec].push_back(P);
238238
}
239239

240-
void recordRelocation(MCAssembler &Asm, const MCAsmLayout &Layout,
241-
const MCFragment *Fragment, const MCFixup &Fixup,
242-
MCValue Target, uint64_t &FixedValue) override;
240+
void recordRelocation(MCAssembler &Asm, const MCFragment *Fragment,
241+
const MCFixup &Fixup, MCValue Target,
242+
uint64_t &FixedValue) override;
243243

244244
void bindIndirectSymbols(MCAssembler &Asm);
245245

llvm/include/llvm/MC/MCObjectWriter.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ class MCObjectWriter {
6363
/// post layout binding. The implementation is responsible for storing
6464
/// information about the relocation so that it can be emitted during
6565
/// writeObject().
66-
virtual void recordRelocation(MCAssembler &Asm, const MCAsmLayout &Layout,
67-
const MCFragment *Fragment,
66+
virtual void recordRelocation(MCAssembler &Asm, const MCFragment *Fragment,
6867
const MCFixup &Fixup, MCValue Target,
6968
uint64_t &FixedValue) = 0;
7069

llvm/lib/MC/ELFObjectWriter.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,9 @@ class ELFObjectWriter : public MCObjectWriter {
254254
return true;
255255
}
256256

257-
void recordRelocation(MCAssembler &Asm, const MCAsmLayout &Layout,
258-
const MCFragment *Fragment, const MCFixup &Fixup,
259-
MCValue Target, uint64_t &FixedValue) override;
257+
void recordRelocation(MCAssembler &Asm, const MCFragment *Fragment,
258+
const MCFixup &Fixup, MCValue Target,
259+
uint64_t &FixedValue) override;
260260
bool usesRela(const MCSectionELF &Sec) const;
261261

262262
void executePostLayoutBinding(MCAssembler &Asm,
@@ -1410,7 +1410,6 @@ bool ELFObjectWriter::shouldRelocateWithSymbol(const MCAssembler &Asm,
14101410
}
14111411

14121412
void ELFObjectWriter::recordRelocation(MCAssembler &Asm,
1413-
const MCAsmLayout &Layout,
14141413
const MCFragment *Fragment,
14151414
const MCFixup &Fixup, MCValue Target,
14161415
uint64_t &FixedValue) {
@@ -1419,7 +1418,7 @@ void ELFObjectWriter::recordRelocation(MCAssembler &Asm,
14191418
MCFixupKindInfo::FKF_IsPCRel;
14201419
const MCSectionELF &FixupSection = cast<MCSectionELF>(*Fragment->getParent());
14211420
uint64_t C = Target.getConstant();
1422-
uint64_t FixupOffset = Layout.getFragmentOffset(Fragment) + Fixup.getOffset();
1421+
uint64_t FixupOffset = Asm.getFragmentOffset(*Fragment) + Fixup.getOffset();
14231422
MCContext &Ctx = Asm.getContext();
14241423

14251424
if (const MCSymbolRefExpr *RefB = Target.getSymB()) {
@@ -1441,7 +1440,7 @@ void ELFObjectWriter::recordRelocation(MCAssembler &Asm,
14411440

14421441
assert(!IsPCRel && "should have been folded");
14431442
IsPCRel = true;
1444-
C += FixupOffset - Layout.getSymbolOffset(SymB);
1443+
C += FixupOffset - Asm.getSymbolOffset(SymB);
14451444
}
14461445

14471446
// We either rejected the fixup or folded B into C at this point.
@@ -1474,7 +1473,7 @@ void ELFObjectWriter::recordRelocation(MCAssembler &Asm,
14741473
uint64_t Addend = 0;
14751474

14761475
FixedValue = !RelocateWithSymbol && SymA && !SymA->isUndefined()
1477-
? C + Layout.getSymbolOffset(*SymA)
1476+
? C + Asm.getSymbolOffset(*SymA)
14781477
: C;
14791478
if (usesRela(FixupSection)) {
14801479
Addend = FixedValue;

llvm/lib/MC/GOFFObjectWriter.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,9 @@ class GOFFObjectWriter : public MCObjectWriter {
236236
void writeEnd();
237237

238238
// Implementation of the MCObjectWriter interface.
239-
void recordRelocation(MCAssembler &Asm, const MCAsmLayout &Layout,
240-
const MCFragment *Fragment, const MCFixup &Fixup,
241-
MCValue Target, uint64_t &FixedValue) override {}
239+
void recordRelocation(MCAssembler &Asm, const MCFragment *Fragment,
240+
const MCFixup &Fixup, MCValue Target,
241+
uint64_t &FixedValue) override {}
242242
void executePostLayoutBinding(MCAssembler &Asm,
243243
const MCAsmLayout &Layout) override {}
244244
uint64_t writeObject(MCAssembler &Asm, const MCAsmLayout &Layout) override;

llvm/lib/MC/MCAssembler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,7 @@ MCAssembler::handleFixup(MCFragment &F, const MCFixup &Fixup,
957957
// The fixup was unresolved, we need a relocation. Inform the object
958958
// writer of the relocation, and give it an opportunity to adjust the
959959
// fixup value if need be.
960-
getWriter().recordRelocation(*this, *Layout, &F, Fixup, Target, FixedValue);
960+
getWriter().recordRelocation(*this, &F, Fixup, Target, FixedValue);
961961
}
962962
return std::make_tuple(Target, FixedValue, IsResolved);
963963
}

llvm/lib/MC/MCDXContainerWriter.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ class DXContainerObjectWriter : public MCObjectWriter {
3535
~DXContainerObjectWriter() override {}
3636

3737
private:
38-
void recordRelocation(MCAssembler &Asm, const MCAsmLayout &Layout,
39-
const MCFragment *Fragment, const MCFixup &Fixup,
40-
MCValue Target, uint64_t &FixedValue) override {}
38+
void recordRelocation(MCAssembler &Asm, const MCFragment *Fragment,
39+
const MCFixup &Fixup, MCValue Target,
40+
uint64_t &FixedValue) override {}
4141

4242
void executePostLayoutBinding(MCAssembler &Asm,
4343
const MCAsmLayout &Layout) override {}

llvm/lib/MC/MachObjectWriter.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,6 @@ static bool isFixupTargetValid(const MCValue &Target) {
492492
}
493493

494494
void MachObjectWriter::recordRelocation(MCAssembler &Asm,
495-
const MCAsmLayout &Layout,
496495
const MCFragment *Fragment,
497496
const MCFixup &Fixup, MCValue Target,
498497
uint64_t &FixedValue) {

llvm/lib/MC/SPIRVObjectWriter.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ class SPIRVObjectWriter : public MCObjectWriter {
2929
~SPIRVObjectWriter() override {}
3030

3131
private:
32-
void recordRelocation(MCAssembler &Asm, const MCAsmLayout &Layout,
33-
const MCFragment *Fragment, const MCFixup &Fixup,
34-
MCValue Target, uint64_t &FixedValue) override {}
32+
void recordRelocation(MCAssembler &Asm, const MCFragment *Fragment,
33+
const MCFixup &Fixup, MCValue Target,
34+
uint64_t &FixedValue) override {}
3535

3636
void executePostLayoutBinding(MCAssembler &Asm,
3737
const MCAsmLayout &Layout) override {}

llvm/lib/MC/WasmObjectWriter.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -293,9 +293,9 @@ class WasmObjectWriter : public MCObjectWriter {
293293

294294
void writeHeader(const MCAssembler &Asm);
295295

296-
void recordRelocation(MCAssembler &Asm, const MCAsmLayout &Layout,
297-
const MCFragment *Fragment, const MCFixup &Fixup,
298-
MCValue Target, uint64_t &FixedValue) override;
296+
void recordRelocation(MCAssembler &Asm, const MCFragment *Fragment,
297+
const MCFixup &Fixup, MCValue Target,
298+
uint64_t &FixedValue) override;
299299

300300
void executePostLayoutBinding(MCAssembler &Asm,
301301
const MCAsmLayout &Layout) override;
@@ -481,7 +481,6 @@ void WasmObjectWriter::executePostLayoutBinding(MCAssembler &Asm,
481481
}
482482

483483
void WasmObjectWriter::recordRelocation(MCAssembler &Asm,
484-
const MCAsmLayout &Layout,
485484
const MCFragment *Fragment,
486485
const MCFixup &Fixup, MCValue Target,
487486
uint64_t &FixedValue) {
@@ -491,7 +490,7 @@ void WasmObjectWriter::recordRelocation(MCAssembler &Asm,
491490

492491
const auto &FixupSection = cast<MCSectionWasm>(*Fragment->getParent());
493492
uint64_t C = Target.getConstant();
494-
uint64_t FixupOffset = Layout.getFragmentOffset(Fragment) + Fixup.getOffset();
493+
uint64_t FixupOffset = Asm.getFragmentOffset(*Fragment) + Fixup.getOffset();
495494
MCContext &Ctx = Asm.getContext();
496495
bool IsLocRel = false;
497496

@@ -521,7 +520,7 @@ void WasmObjectWriter::recordRelocation(MCAssembler &Asm,
521520
return;
522521
}
523522
IsLocRel = true;
524-
C += FixupOffset - Layout.getSymbolOffset(SymB);
523+
C += FixupOffset - Asm.getSymbolOffset(SymB);
525524
}
526525

527526
// We either rejected the fixup or folded B into C at this point.
@@ -578,7 +577,7 @@ void WasmObjectWriter::recordRelocation(MCAssembler &Asm,
578577
if (!SectionSymbol)
579578
report_fatal_error("section symbol is required for relocation");
580579

581-
C += Layout.getSymbolOffset(*SymA);
580+
C += Asm.getSymbolOffset(*SymA);
582581
SymA = cast<MCSymbolWasm>(SectionSymbol);
583582
}
584583

@@ -1647,7 +1646,7 @@ uint64_t WasmObjectWriter::writeOneObject(MCAssembler &Asm,
16471646
// For each data symbol, export it in the symtab as a reference to the
16481647
// corresponding Wasm data segment.
16491648
wasm::WasmDataReference Ref = wasm::WasmDataReference{
1650-
DataSection.getSegmentIndex(), Layout.getSymbolOffset(WS),
1649+
DataSection.getSegmentIndex(), Asm.getSymbolOffset(WS),
16511650
static_cast<uint64_t>(Size)};
16521651
assert(DataLocations.count(&WS) == 0);
16531652
DataLocations[&WS] = Ref;
@@ -1749,7 +1748,7 @@ uint64_t WasmObjectWriter::writeOneObject(MCAssembler &Asm,
17491748
LLVM_DEBUG(dbgs() << " -> index:" << WasmIndex << "\n");
17501749
} else if (Base->isData()) {
17511750
auto &DataSection = static_cast<MCSectionWasm &>(WS.getSection());
1752-
uint64_t Offset = Layout.getSymbolOffset(S);
1751+
uint64_t Offset = Asm.getSymbolOffset(S);
17531752
int64_t Size = 0;
17541753
// For data symbol alias we use the size of the base symbol as the
17551754
// size of the alias. When an offset from the base is involved this
@@ -1763,7 +1762,7 @@ uint64_t WasmObjectWriter::writeOneObject(MCAssembler &Asm,
17631762
std::min(static_cast<uint64_t>(Size), Segment.Data.size() - Offset);
17641763
wasm::WasmDataReference Ref = wasm::WasmDataReference{
17651764
DataSection.getSegmentIndex(),
1766-
static_cast<uint32_t>(Layout.getSymbolOffset(S)),
1765+
static_cast<uint32_t>(Asm.getSymbolOffset(S)),
17671766
static_cast<uint32_t>(Size)};
17681767
DataLocations[&WS] = Ref;
17691768
LLVM_DEBUG(dbgs() << " -> index:" << Ref.Segment << "\n");

llvm/lib/MC/WinCOFFObjectWriter.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,9 @@ class WinCOFFWriter {
162162

163163
void reset();
164164
void executePostLayoutBinding(MCAssembler &Asm, const MCAsmLayout &Layout);
165-
void recordRelocation(MCAssembler &Asm, const MCAsmLayout &Layout,
166-
const MCFragment *Fragment, const MCFixup &Fixup,
167-
MCValue Target, uint64_t &FixedValue);
165+
void recordRelocation(MCAssembler &Asm, const MCFragment *Fragment,
166+
const MCFixup &Fixup, MCValue Target,
167+
uint64_t &FixedValue);
168168
uint64_t writeObject(MCAssembler &Asm, const MCAsmLayout &Layout);
169169

170170
private:
@@ -229,9 +229,9 @@ class WinCOFFObjectWriter : public MCObjectWriter {
229229
const MCSymbol &SymA,
230230
const MCFragment &FB, bool InSet,
231231
bool IsPCRel) const override;
232-
void recordRelocation(MCAssembler &Asm, const MCAsmLayout &Layout,
233-
const MCFragment *Fragment, const MCFixup &Fixup,
234-
MCValue Target, uint64_t &FixedValue) override;
232+
void recordRelocation(MCAssembler &Asm, const MCFragment *Fragment,
233+
const MCFixup &Fixup, MCValue Target,
234+
uint64_t &FixedValue) override;
235235
uint64_t writeObject(MCAssembler &Asm, const MCAsmLayout &Layout) override;
236236
};
237237

@@ -854,7 +854,6 @@ void WinCOFFWriter::executePostLayoutBinding(MCAssembler &Asm,
854854
}
855855

856856
void WinCOFFWriter::recordRelocation(MCAssembler &Asm,
857-
const MCAsmLayout &Layout,
858857
const MCFragment *Fragment,
859858
const MCFixup &Fixup, MCValue Target,
860859
uint64_t &FixedValue) {
@@ -894,11 +893,11 @@ void WinCOFFWriter::recordRelocation(MCAssembler &Asm,
894893
}
895894

896895
// Offset of the symbol in the section
897-
int64_t OffsetOfB = Layout.getSymbolOffset(*B);
896+
int64_t OffsetOfB = Asm.getSymbolOffset(*B);
898897

899898
// Offset of the relocation in the section
900899
int64_t OffsetOfRelocation =
901-
Layout.getFragmentOffset(Fragment) + Fixup.getOffset();
900+
Asm.getFragmentOffset(*Fragment) + Fixup.getOffset();
902901

903902
FixedValue = (OffsetOfRelocation - OffsetOfB) + Target.getConstant();
904903
} else {
@@ -908,7 +907,7 @@ void WinCOFFWriter::recordRelocation(MCAssembler &Asm,
908907
COFFRelocation Reloc;
909908

910909
Reloc.Data.SymbolTableIndex = 0;
911-
Reloc.Data.VirtualAddress = Layout.getFragmentOffset(Fragment);
910+
Reloc.Data.VirtualAddress = Asm.getFragmentOffset(*Fragment);
912911

913912
// Turn relocations for temporary symbols into section relocations.
914913
if (A.isTemporary() && !SymbolMap[&A]) {
@@ -918,7 +917,7 @@ void WinCOFFWriter::recordRelocation(MCAssembler &Asm,
918917
"Section must already have been defined in executePostLayoutBinding!");
919918
COFFSection *Section = SectionMap[TargetSection];
920919
Reloc.Symb = Section->Symbol;
921-
FixedValue += Layout.getSymbolOffset(A);
920+
FixedValue += Asm.getSymbolOffset(A);
922921
// Technically, we should do the final adjustments of FixedValue (below)
923922
// before picking an offset symbol, otherwise we might choose one which
924923
// is slightly too far away. The relocations where it really matters
@@ -1214,13 +1213,12 @@ void WinCOFFObjectWriter::executePostLayoutBinding(MCAssembler &Asm,
12141213
}
12151214

12161215
void WinCOFFObjectWriter::recordRelocation(MCAssembler &Asm,
1217-
const MCAsmLayout &Layout,
12181216
const MCFragment *Fragment,
12191217
const MCFixup &Fixup, MCValue Target,
12201218
uint64_t &FixedValue) {
12211219
assert(!isDwoSection(*Fragment->getParent()) &&
12221220
"No relocation in Dwo sections");
1223-
ObjWriter->recordRelocation(Asm, Layout, Fragment, Fixup, Target, FixedValue);
1221+
ObjWriter->recordRelocation(Asm, Fragment, Fixup, Target, FixedValue);
12241222
}
12251223

12261224
uint64_t WinCOFFObjectWriter::writeObject(MCAssembler &Asm,

0 commit comments

Comments
 (0)