Skip to content

Commit 7687261

Browse files
committed
ELFObjectWriter: Remove MCAssembler * arguments
1 parent b754e40 commit 7687261

File tree

4 files changed

+24
-32
lines changed

4 files changed

+24
-32
lines changed

llvm/include/llvm/MC/MCELFObjectWriter.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ class MCELFObjectTargetWriter : public MCObjectTargetWriter {
9191
virtual bool needsRelocateWithSymbol(const MCValue &Val, const MCSymbol &Sym,
9292
unsigned Type) const;
9393

94-
virtual void sortRelocs(const MCAssembler &Asm,
95-
std::vector<ELFRelocationEntry> &Relocs);
94+
virtual void sortRelocs(std::vector<ELFRelocationEntry> &Relocs);
9695

9796
/// \name Accessors
9897
/// @{

llvm/lib/MC/ELFObjectWriter.cpp

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,8 @@ struct ELFWriter {
120120
DwoOnly,
121121
} Mode;
122122

123-
static uint64_t symbolValue(const MCAssembler &Asm, const MCSymbol &Sym);
124-
static bool isInSymtab(const MCAssembler &Asm, const MCSymbolELF &Symbol,
125-
bool Used, bool Renamed);
123+
uint64_t symbolValue(const MCSymbol &Sym);
124+
bool isInSymtab(const MCSymbolELF &Symbol, bool Used, bool Renamed);
126125

127126
/// Helper struct for containing some precomputed information on symbols.
128127
struct ELFSymbolData {
@@ -181,7 +180,7 @@ struct ELFWriter {
181180
W.write(Val);
182181
}
183182

184-
void writeHeader(const MCAssembler &Asm);
183+
void writeHeader();
185184

186185
void writeSymbol(SymbolTableWriter &Writer, uint32_t StringIndex,
187186
ELFSymbolData &MSD);
@@ -193,16 +192,16 @@ struct ELFWriter {
193192
///
194193
/// \param Asm - The assembler.
195194
/// \param RevGroupMap - Maps a signature symbol to the group section.
196-
void computeSymbolTable(MCAssembler &Asm, const RevGroupMapTy &RevGroupMap);
195+
void computeSymbolTable(const RevGroupMapTy &RevGroupMap);
197196

198197
void writeAddrsigSection();
199198

200199
MCSectionELF *createRelocationSection(MCContext &Ctx,
201200
const MCSectionELF &Sec);
202201

203-
void writeSectionHeaders(const MCAssembler &Asm);
202+
void writeSectionHeaders();
204203

205-
void writeSectionData(const MCAssembler &Asm, MCSection &Sec);
204+
void writeSectionData(MCSection &Sec);
206205

207206
void writeSectionHeaderEntry(uint32_t Name, uint32_t Type, uint64_t Flags,
208207
uint64_t Address, uint64_t Offset, uint64_t Size,
@@ -285,7 +284,7 @@ bool ELFWriter::is64Bit() const {
285284
}
286285

287286
// Emit the ELF header.
288-
void ELFWriter::writeHeader(const MCAssembler &Asm) {
287+
void ELFWriter::writeHeader() {
289288
// ELF Header
290289
// ----------
291290
//
@@ -346,7 +345,7 @@ void ELFWriter::writeHeader(const MCAssembler &Asm) {
346345
W.write<uint16_t>(StringTableIndex);
347346
}
348347

349-
uint64_t ELFWriter::symbolValue(const MCAssembler &Asm, const MCSymbol &Sym) {
348+
uint64_t ELFWriter::symbolValue(const MCSymbol &Sym) {
350349
if (Sym.isCommon())
351350
return Sym.getCommonAlignment()->value();
352351

@@ -433,7 +432,7 @@ void ELFWriter::writeSymbol(SymbolTableWriter &Writer, uint32_t StringIndex,
433432
uint8_t Visibility = Symbol.getVisibility();
434433
uint8_t Other = Symbol.getOther() | Visibility;
435434

436-
uint64_t Value = symbolValue(Asm, *MSD.Symbol);
435+
uint64_t Value = symbolValue(*MSD.Symbol);
437436
uint64_t Size = 0;
438437

439438
const MCExpr *ESize = MSD.Symbol->getSize();
@@ -470,8 +469,7 @@ void ELFWriter::writeSymbol(SymbolTableWriter &Writer, uint32_t StringIndex,
470469
IsReserved);
471470
}
472471

473-
bool ELFWriter::isInSymtab(const MCAssembler &Asm, const MCSymbolELF &Symbol,
474-
bool Used, bool Renamed) {
472+
bool ELFWriter::isInSymtab(const MCSymbolELF &Symbol, bool Used, bool Renamed) {
475473
if (Symbol.isVariable()) {
476474
const MCExpr *Expr = Symbol.getVariableValue();
477475
// Target Expressions that are always inlined do not appear in the symtab
@@ -505,8 +503,7 @@ bool ELFWriter::isInSymtab(const MCAssembler &Asm, const MCSymbolELF &Symbol,
505503
return true;
506504
}
507505

508-
void ELFWriter::computeSymbolTable(MCAssembler &Asm,
509-
const RevGroupMapTy &RevGroupMap) {
506+
void ELFWriter::computeSymbolTable(const RevGroupMapTy &RevGroupMap) {
510507
MCContext &Ctx = Asm.getContext();
511508
SymbolTableWriter Writer(*this, is64Bit());
512509

@@ -537,7 +534,7 @@ void ELFWriter::computeSymbolTable(MCAssembler &Asm,
537534
bool WeakrefUsed = Symbol.isWeakrefUsedInReloc();
538535
bool isSignature = Symbol.isSignature();
539536

540-
if (!isInSymtab(Asm, Symbol, Used || WeakrefUsed || isSignature,
537+
if (!isInSymtab(Symbol, Used || WeakrefUsed || isSignature,
541538
OWriter.Renames.count(&Symbol)))
542539
continue;
543540

@@ -747,7 +744,7 @@ bool ELFWriter::maybeWriteCompression(
747744
return true;
748745
}
749746

750-
void ELFWriter::writeSectionData(const MCAssembler &Asm, MCSection &Sec) {
747+
void ELFWriter::writeSectionData(MCSection &Sec) {
751748
MCSectionELF &Section = static_cast<MCSectionELF &>(Sec);
752749
StringRef SectionName = Section.getName();
753750
auto &Ctx = Asm.getContext();
@@ -828,7 +825,7 @@ void ELFWriter::writeRelocations(const MCSectionELF &Sec) {
828825
const bool Rela = OWriter.usesRela(TO, Sec);
829826

830827
// Sort the relocation entries. MIPS needs this.
831-
OWriter.TargetObjectWriter->sortRelocs(Asm, Relocs);
828+
OWriter.TargetObjectWriter->sortRelocs(Relocs);
832829

833830
if (OWriter.TargetObjectWriter->getEMachine() == ELF::EM_MIPS) {
834831
for (const ELFRelocationEntry &Entry : Relocs) {
@@ -946,7 +943,7 @@ void ELFWriter::writeSectionHeader(uint32_t GroupSymbolIndex, uint64_t Offset,
946943
Section.getEntrySize());
947944
}
948945

949-
void ELFWriter::writeSectionHeaders(const MCAssembler &Asm) {
946+
void ELFWriter::writeSectionHeaders() {
950947
uint64_t Start = W.OS.tell();
951948
const unsigned NumSections = SectionTable.size();
952949

@@ -1028,7 +1025,7 @@ uint64_t ELFWriter::writeObject() {
10281025
RevGroupMapTy RevGroupMap;
10291026

10301027
// Write out the ELF header ...
1031-
writeHeader(Asm);
1028+
writeHeader();
10321029

10331030
stats::ELFHeaderBytes += W.OS.tell() - StartOffset;
10341031

@@ -1048,7 +1045,7 @@ uint64_t ELFWriter::writeObject() {
10481045
const uint64_t SecStart = align(Section.getAlign());
10491046

10501047
const MCSymbolELF *SignatureSymbol = Section.getGroup();
1051-
writeSectionData(Asm, Section);
1048+
writeSectionData(Section);
10521049

10531050
uint64_t SecEnd = W.OS.tell();
10541051
Section.setOffsets(SecStart, SecEnd);
@@ -1108,7 +1105,7 @@ uint64_t ELFWriter::writeObject() {
11081105
}
11091106

11101107
// Compute symbol table information.
1111-
computeSymbolTable(Asm, RevGroupMap);
1108+
computeSymbolTable(RevGroupMap);
11121109

11131110
for (MCSectionELF *RelSection : Relocations) {
11141111
// Remember the offset into the file for this section.
@@ -1137,7 +1134,7 @@ uint64_t ELFWriter::writeObject() {
11371134
const uint64_t SectionHeaderOffset = align(is64Bit() ? Align(8) : Align(4));
11381135

11391136
// ... then the section header table ...
1140-
writeSectionHeaders(Asm);
1137+
writeSectionHeaders();
11411138

11421139
uint16_t NumSections = support::endian::byte_swap<uint16_t>(
11431140
(SectionTable.size() + 1 >= ELF::SHN_LORESERVE) ? (uint16_t)ELF::SHN_UNDEF

llvm/lib/MC/MCELFObjectTargetWriter.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,5 @@ bool MCELFObjectTargetWriter::needsRelocateWithSymbol(const MCValue &,
2323
return false;
2424
}
2525

26-
void
27-
MCELFObjectTargetWriter::sortRelocs(const MCAssembler &Asm,
28-
std::vector<ELFRelocationEntry> &Relocs) {
29-
}
26+
void MCELFObjectTargetWriter::sortRelocs(
27+
std::vector<ELFRelocationEntry> &Relocs) {}

llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ class MipsELFObjectWriter : public MCELFObjectTargetWriter {
5252
const MCFixup &Fixup, bool IsPCRel) const override;
5353
bool needsRelocateWithSymbol(const MCValue &Val, const MCSymbol &Sym,
5454
unsigned Type) const override;
55-
void sortRelocs(const MCAssembler &Asm,
56-
std::vector<ELFRelocationEntry> &Relocs) override;
55+
void sortRelocs(std::vector<ELFRelocationEntry> &Relocs) override;
5756
};
5857

5958
/// The possible results of the Predicate function used by find_best.
@@ -381,8 +380,7 @@ unsigned MipsELFObjectWriter::getRelocType(MCContext &Ctx,
381380
/// It should also be noted that this function is not affected by whether
382381
/// the symbol was kept or rewritten into a section-relative equivalent. We
383382
/// always match using the expressions from the source.
384-
void MipsELFObjectWriter::sortRelocs(const MCAssembler &Asm,
385-
std::vector<ELFRelocationEntry> &Relocs) {
383+
void MipsELFObjectWriter::sortRelocs(std::vector<ELFRelocationEntry> &Relocs) {
386384
// We do not need to sort the relocation table for RELA relocations which
387385
// N32/N64 uses as the relocation addend contains the value we require,
388386
// rather than it being split across a pair of relocations.

0 commit comments

Comments
 (0)