Skip to content

Commit dce1828

Browse files
committed
[MC] Remove the MCAsmLayout parameter from ELFObjectWriter
1 parent 29cdc8f commit dce1828

File tree

1 file changed

+27
-29
lines changed

1 file changed

+27
-29
lines changed

llvm/lib/MC/ELFObjectWriter.cpp

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ struct ELFWriter {
108108
DwoOnly,
109109
} Mode;
110110

111-
static uint64_t symbolValue(const MCSymbol &Sym, const MCAssembler &Asm);
112-
static bool isInSymtab(const MCAsmLayout &Layout, const MCSymbolELF &Symbol,
111+
static uint64_t symbolValue(const MCAssembler &Asm, const MCSymbol &Sym);
112+
static bool isInSymtab(const MCAssembler &Asm, const MCSymbolELF &Symbol,
113113
bool Used, bool Renamed);
114114

115115
/// Helper struct for containing some precomputed information on symbols.
@@ -168,8 +168,8 @@ struct ELFWriter {
168168

169169
void writeHeader(const MCAssembler &Asm);
170170

171-
void writeSymbol(SymbolTableWriter &Writer, uint32_t StringIndex,
172-
ELFSymbolData &MSD, const MCAsmLayout &Layout);
171+
void writeSymbol(const MCAssembler &Asm, SymbolTableWriter &Writer,
172+
uint32_t StringIndex, ELFSymbolData &MSD);
173173

174174
// Start and end offset of each section
175175
using SectionOffsetsTy =
@@ -183,7 +183,7 @@ struct ELFWriter {
183183
/// \param Asm - The assembler.
184184
/// \param SectionIndexMap - Maps a section to its index.
185185
/// \param RevGroupMap - Maps a signature symbol to the group section.
186-
void computeSymbolTable(MCAssembler &Asm, const MCAsmLayout &Layout,
186+
void computeSymbolTable(MCAssembler &Asm,
187187
const SectionIndexMapTy &SectionIndexMap,
188188
const RevGroupMapTy &RevGroupMap,
189189
SectionOffsetsTy &SectionOffsets);
@@ -193,7 +193,7 @@ struct ELFWriter {
193193
MCSectionELF *createRelocationSection(MCContext &Ctx,
194194
const MCSectionELF &Sec);
195195

196-
void writeSectionHeader(const MCAsmLayout &Layout,
196+
void writeSectionHeader(const MCAssembler &Asm,
197197
const SectionIndexMapTy &SectionIndexMap,
198198
const SectionOffsetsTy &SectionOffsets);
199199

@@ -453,7 +453,7 @@ void ELFWriter::writeHeader(const MCAssembler &Asm) {
453453
W.write<uint16_t>(StringTableIndex);
454454
}
455455

456-
uint64_t ELFWriter::symbolValue(const MCSymbol &Sym, const MCAssembler &Asm) {
456+
uint64_t ELFWriter::symbolValue(const MCAssembler &Asm, const MCSymbol &Sym) {
457457
if (Sym.isCommon())
458458
return Sym.getCommonAlignment()->value();
459459

@@ -515,11 +515,11 @@ static bool isIFunc(const MCSymbolELF *Symbol) {
515515
return true;
516516
}
517517

518-
void ELFWriter::writeSymbol(SymbolTableWriter &Writer, uint32_t StringIndex,
519-
ELFSymbolData &MSD, const MCAsmLayout &Layout) {
518+
void ELFWriter::writeSymbol(const MCAssembler &Asm, SymbolTableWriter &Writer,
519+
uint32_t StringIndex, ELFSymbolData &MSD) {
520520
const auto &Symbol = cast<MCSymbolELF>(*MSD.Symbol);
521521
const MCSymbolELF *Base =
522-
cast_or_null<MCSymbolELF>(Layout.getBaseSymbol(Symbol));
522+
cast_or_null<MCSymbolELF>(Asm.getBaseSymbol(Symbol));
523523

524524
// This has to be in sync with when computeSymbolTable uses SHN_ABS or
525525
// SHN_COMMON.
@@ -540,7 +540,7 @@ void ELFWriter::writeSymbol(SymbolTableWriter &Writer, uint32_t StringIndex,
540540
uint8_t Visibility = Symbol.getVisibility();
541541
uint8_t Other = Symbol.getOther() | Visibility;
542542

543-
uint64_t Value = symbolValue(*MSD.Symbol, Layout.getAssembler());
543+
uint64_t Value = symbolValue(Asm, *MSD.Symbol);
544544
uint64_t Size = 0;
545545

546546
const MCExpr *ESize = MSD.Symbol->getSize();
@@ -567,7 +567,7 @@ void ELFWriter::writeSymbol(SymbolTableWriter &Writer, uint32_t StringIndex,
567567

568568
if (ESize) {
569569
int64_t Res;
570-
if (!ESize->evaluateKnownAbsolute(Res, Layout))
570+
if (!ESize->evaluateKnownAbsolute(Res, *Asm.getLayout()))
571571
report_fatal_error("Size expression must be absolute.");
572572
Size = Res;
573573
}
@@ -577,7 +577,7 @@ void ELFWriter::writeSymbol(SymbolTableWriter &Writer, uint32_t StringIndex,
577577
IsReserved);
578578
}
579579

580-
bool ELFWriter::isInSymtab(const MCAsmLayout &Layout, const MCSymbolELF &Symbol,
580+
bool ELFWriter::isInSymtab(const MCAssembler &Asm, const MCSymbolELF &Symbol,
581581
bool Used, bool Renamed) {
582582
if (Symbol.isVariable()) {
583583
const MCExpr *Expr = Symbol.getVariableValue();
@@ -599,7 +599,7 @@ bool ELFWriter::isInSymtab(const MCAsmLayout &Layout, const MCSymbolELF &Symbol,
599599

600600
if (Symbol.isVariable() && Symbol.isUndefined()) {
601601
// FIXME: this is here just to diagnose the case of a var = commmon_sym.
602-
Layout.getBaseSymbol(Symbol);
602+
Asm.getBaseSymbol(Symbol);
603603
return false;
604604
}
605605

@@ -612,10 +612,10 @@ bool ELFWriter::isInSymtab(const MCAsmLayout &Layout, const MCSymbolELF &Symbol,
612612
return true;
613613
}
614614

615-
void ELFWriter::computeSymbolTable(
616-
MCAssembler &Asm, const MCAsmLayout &Layout,
617-
const SectionIndexMapTy &SectionIndexMap, const RevGroupMapTy &RevGroupMap,
618-
SectionOffsetsTy &SectionOffsets) {
615+
void ELFWriter::computeSymbolTable(MCAssembler &Asm,
616+
const SectionIndexMapTy &SectionIndexMap,
617+
const RevGroupMapTy &RevGroupMap,
618+
SectionOffsetsTy &SectionOffsets) {
619619
MCContext &Ctx = Asm.getContext();
620620
SymbolTableWriter Writer(*this, is64Bit());
621621

@@ -646,7 +646,7 @@ void ELFWriter::computeSymbolTable(
646646
bool WeakrefUsed = Symbol.isWeakrefUsedInReloc();
647647
bool isSignature = Symbol.isSignature();
648648

649-
if (!isInSymtab(Layout, Symbol, Used || WeakrefUsed || isSignature,
649+
if (!isInSymtab(Asm, Symbol, Used || WeakrefUsed || isSignature,
650650
OWriter.Renames.count(&Symbol)))
651651
continue;
652652

@@ -756,7 +756,7 @@ void ELFWriter::computeSymbolTable(
756756
? 0
757757
: StrTabBuilder.getOffset(MSD.Name);
758758
MSD.Symbol->setIndex(Index++);
759-
writeSymbol(Writer, StringIndex, MSD, Layout);
759+
writeSymbol(Asm, Writer, StringIndex, MSD);
760760
}
761761
for (; FileNameIt != FileNames.end(); ++FileNameIt) {
762762
Writer.writeSymbol(StrTabBuilder.getOffset(FileNameIt->first),
@@ -771,7 +771,7 @@ void ELFWriter::computeSymbolTable(
771771
for (ELFSymbolData &MSD : ExternalSymbolData) {
772772
unsigned StringIndex = StrTabBuilder.getOffset(MSD.Name);
773773
MSD.Symbol->setIndex(Index++);
774-
writeSymbol(Writer, StringIndex, MSD, Layout);
774+
writeSymbol(Asm, Writer, StringIndex, MSD);
775775
assert(MSD.Symbol->getBinding() != ELF::STB_LOCAL);
776776
}
777777

@@ -1033,9 +1033,9 @@ void ELFWriter::writeSection(const SectionIndexMapTy &SectionIndexMap,
10331033
Section.getEntrySize());
10341034
}
10351035

1036-
void ELFWriter::writeSectionHeader(
1037-
const MCAsmLayout &Layout, const SectionIndexMapTy &SectionIndexMap,
1038-
const SectionOffsetsTy &SectionOffsets) {
1036+
void ELFWriter::writeSectionHeader(const MCAssembler &Asm,
1037+
const SectionIndexMapTy &SectionIndexMap,
1038+
const SectionOffsetsTy &SectionOffsets) {
10391039
const unsigned NumSections = SectionTable.size();
10401040

10411041
// Null section first.
@@ -1055,7 +1055,7 @@ void ELFWriter::writeSectionHeader(
10551055
SectionOffsets.find(Section)->second;
10561056
uint64_t Size;
10571057
if (Type == ELF::SHT_NOBITS)
1058-
Size = Layout.getSectionAddressSize(Section);
1058+
Size = Asm.getSectionAddressSize(*Section);
10591059
else
10601060
Size = Offsets.second - Offsets.first;
10611061

@@ -1065,7 +1065,6 @@ void ELFWriter::writeSectionHeader(
10651065
}
10661066

10671067
uint64_t ELFWriter::writeObject(MCAssembler &Asm) {
1068-
auto &Layout = *Asm.getLayout();
10691068
uint64_t StartOffset = W.OS.tell();
10701069

10711070
MCContext &Ctx = Asm.getContext();
@@ -1157,8 +1156,7 @@ uint64_t ELFWriter::writeObject(MCAssembler &Asm) {
11571156
}
11581157

11591158
// Compute symbol table information.
1160-
computeSymbolTable(Asm, Layout, SectionIndexMap, RevGroupMap,
1161-
SectionOffsets);
1159+
computeSymbolTable(Asm, SectionIndexMap, RevGroupMap, SectionOffsets);
11621160

11631161
for (MCSectionELF *RelSection : Relocations) {
11641162
// Remember the offset into the file for this section.
@@ -1188,7 +1186,7 @@ uint64_t ELFWriter::writeObject(MCAssembler &Asm) {
11881186
const uint64_t SectionHeaderOffset = align(is64Bit() ? Align(8) : Align(4));
11891187

11901188
// ... then the section header table ...
1191-
writeSectionHeader(Layout, SectionIndexMap, SectionOffsets);
1189+
writeSectionHeader(Asm, SectionIndexMap, SectionOffsets);
11921190

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

0 commit comments

Comments
 (0)