Skip to content

Commit a40ca78

Browse files
committed
[MC] Remove MCAsmLayout::{getSectionFileSize,getSectionAddressSize}
1 parent 71ff749 commit a40ca78

File tree

8 files changed

+34
-48
lines changed

8 files changed

+34
-48
lines changed

llvm/include/llvm/MC/MCAsmLayout.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,6 @@ class MCAsmLayout {
5454
/// \name Utility Functions
5555
/// @{
5656

57-
/// Get the address space size of the given section, as it effects
58-
/// layout. This may differ from the size reported by \see
59-
/// getSectionFileSize() by not including section tail padding.
60-
uint64_t getSectionAddressSize(const MCSection *Sec) const;
61-
62-
/// Get the data size of the given section, as emitted to the object
63-
/// file. This may include additional padding, or be 0 for virtual sections.
64-
uint64_t getSectionFileSize(const MCSection *Sec) const;
65-
6657
/// Variant that reports a fatal error if the offset is not computable.
6758
uint64_t getSymbolOffset(const MCSymbol &S) const;
6859

llvm/include/llvm/MC/MCMachObjectWriter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ class MachObjectWriter : public MCObjectWriter {
159159
uint64_t getFragmentAddress(const MCAssembler &Asm,
160160
const MCFragment *Fragment) const;
161161

162-
uint64_t getPaddingSize(const MCSection *SD, const MCAsmLayout &Layout) const;
162+
uint64_t getPaddingSize(const MCAssembler &Asm, const MCSection *SD) const;
163163

164164
const MCSymbol *getAtom(const MCSymbol &S) const;
165165

@@ -191,7 +191,7 @@ class MachObjectWriter : public MCObjectWriter {
191191
uint64_t SectionDataSize, uint32_t MaxProt,
192192
uint32_t InitProt);
193193

194-
void writeSection(const MCAsmLayout &Layout, const MCSection &Sec,
194+
void writeSection(const MCAssembler &Asm, const MCSection &Sec,
195195
uint64_t VMAddr, uint64_t FileOffset, unsigned Flags,
196196
uint64_t RelocationsStart, unsigned NumRelocations);
197197

llvm/lib/MC/MCAssembler.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -603,19 +603,13 @@ uint64_t MCAssembler::getSectionAddressSize(const MCSection &Sec) const {
603603
const MCFragment &F = *Sec.curFragList()->Tail;
604604
return getFragmentOffset(F) + computeFragmentSize(F);
605605
}
606-
uint64_t MCAsmLayout::getSectionAddressSize(const MCSection *Sec) const {
607-
return Assembler.getSectionAddressSize(*Sec);
608-
}
609606

610607
uint64_t MCAssembler::getSectionFileSize(const MCSection &Sec) const {
611608
// Virtual sections have no file size.
612609
if (Sec.isVirtualSection())
613610
return 0;
614611
return getSectionAddressSize(Sec);
615612
}
616-
uint64_t MCAsmLayout::getSectionFileSize(const MCSection *Sec) const {
617-
return Assembler.getSectionFileSize(*Sec);
618-
}
619613

620614
bool MCAssembler::registerSymbol(const MCSymbol &Symbol) {
621615
bool Changed = !Symbol.isRegistered();

llvm/lib/MC/MachObjectWriter.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,14 @@ uint64_t MachObjectWriter::getSymbolAddress(const MCSymbol &S,
121121
Layout.getSymbolOffset(S);
122122
}
123123

124-
uint64_t MachObjectWriter::getPaddingSize(const MCSection *Sec,
125-
const MCAsmLayout &Layout) const {
126-
uint64_t EndAddr = getSectionAddress(Sec) + Layout.getSectionAddressSize(Sec);
124+
uint64_t MachObjectWriter::getPaddingSize(const MCAssembler &Asm,
125+
const MCSection *Sec) const {
126+
uint64_t EndAddr = getSectionAddress(Sec) + Asm.getSectionAddressSize(*Sec);
127127
unsigned Next = Sec->getLayoutOrder() + 1;
128-
if (Next >= Layout.getSectionOrder().size())
128+
if (Next >= Asm.getLayout()->getSectionOrder().size())
129129
return 0;
130130

131-
const MCSection &NextSec = *Layout.getSectionOrder()[Next];
131+
const MCSection &NextSec = *Asm.getLayout()->getSectionOrder()[Next];
132132
if (NextSec.isVirtualSection())
133133
return 0;
134134
return offsetToAlignment(EndAddr, NextSec.getAlign());
@@ -245,17 +245,17 @@ void MachObjectWriter::writeSegmentLoadCommand(
245245
assert(W.OS.tell() - Start == SegmentLoadCommandSize);
246246
}
247247

248-
void MachObjectWriter::writeSection(const MCAsmLayout &Layout,
248+
void MachObjectWriter::writeSection(const MCAssembler &Asm,
249249
const MCSection &Sec, uint64_t VMAddr,
250250
uint64_t FileOffset, unsigned Flags,
251251
uint64_t RelocationsStart,
252252
unsigned NumRelocations) {
253-
uint64_t SectionSize = Layout.getSectionAddressSize(&Sec);
253+
uint64_t SectionSize = Asm.getSectionAddressSize(Sec);
254254
const MCSectionMachO &Section = cast<MCSectionMachO>(Sec);
255255

256256
// The offset is unused for virtual sections.
257257
if (Section.isVirtualSection()) {
258-
assert(Layout.getSectionFileSize(&Sec) == 0 && "Invalid file size!");
258+
assert(Asm.getSectionFileSize(Sec) == 0 && "Invalid file size!");
259259
FileOffset = 0;
260260
}
261261

@@ -679,7 +679,7 @@ void MachObjectWriter::computeSectionAddresses(const MCAssembler &Asm) {
679679
// Explicitly pad the section to match the alignment requirements of the
680680
// following one. This is for 'gas' compatibility, it shouldn't
681681
/// strictly be necessary.
682-
StartAddress += getPaddingSize(Sec, *Asm.getLayout());
682+
StartAddress += getPaddingSize(Asm, Sec);
683683
}
684684
}
685685

@@ -857,7 +857,7 @@ uint64_t MachObjectWriter::writeObject(MCAssembler &Asm) {
857857
uint64_t Address = getSectionAddress(&Sec);
858858
uint64_t Size = Asm.getSectionAddressSize(Sec);
859859
uint64_t FileSize = Asm.getSectionFileSize(Sec);
860-
FileSize += getPaddingSize(&Sec, Layout);
860+
FileSize += getPaddingSize(Asm, &Sec);
861861

862862
VMSize = std::max(VMSize, Address + Size);
863863

@@ -893,7 +893,7 @@ uint64_t MachObjectWriter::writeObject(MCAssembler &Asm) {
893893
unsigned Flags = Sec.getTypeAndAttributes();
894894
if (Sec.hasInstructions())
895895
Flags |= MachO::S_ATTR_SOME_INSTRUCTIONS;
896-
writeSection(Layout, Sec, getSectionAddress(&Sec), SectionStart, Flags,
896+
writeSection(Asm, Sec, getSectionAddress(&Sec), SectionStart, Flags,
897897
RelocTableEnd, NumRelocs);
898898
RelocTableEnd += NumRelocs * sizeof(MachO::any_relocation_info);
899899
}
@@ -995,7 +995,7 @@ uint64_t MachObjectWriter::writeObject(MCAssembler &Asm) {
995995
for (const MCSection &Sec : Asm) {
996996
Asm.writeSectionData(W.OS, &Sec);
997997

998-
uint64_t Pad = getPaddingSize(&Sec, Layout);
998+
uint64_t Pad = getPaddingSize(Asm, &Sec);
999999
W.OS.write_zeros(Pad);
10001000
}
10011001

llvm/lib/MC/WasmObjectWriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1062,7 +1062,7 @@ uint32_t WasmObjectWriter::writeCodeSection(const MCAssembler &Asm,
10621062
for (const WasmFunction &Func : Functions) {
10631063
auto *FuncSection = static_cast<MCSectionWasm *>(Func.Section);
10641064

1065-
int64_t Size = Layout.getSectionAddressSize(FuncSection);
1065+
int64_t Size = Asm.getSectionAddressSize(*FuncSection);
10661066
encodeULEB128(Size, W->OS);
10671067
FuncSection->setSectionOffset(W->OS.tell() - Section.ContentsOffset);
10681068
Asm.writeSectionData(W->OS, FuncSection);

llvm/lib/MC/WinCOFFObjectWriter.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ class WinCOFFWriter {
172172
COFFSymbol *GetOrCreateCOFFSymbol(const MCSymbol *Symbol);
173173
COFFSection *createSection(StringRef Name);
174174

175-
void defineSection(MCSectionCOFF const &Sec, const MCAsmLayout &Layout);
175+
void defineSection(const MCAssembler &Asm, MCSectionCOFF const &Sec);
176176

177177
COFFSymbol *getLinkedSymbol(const MCSymbol &Symbol);
178178
void DefineSymbol(const MCSymbol &Symbol, MCAssembler &Assembler,
@@ -318,8 +318,8 @@ static uint32_t getAlignment(const MCSectionCOFF &Sec) {
318318

319319
/// This function takes a section data object from the assembler
320320
/// and creates the associated COFF section staging object.
321-
void WinCOFFWriter::defineSection(const MCSectionCOFF &MCSec,
322-
const MCAsmLayout &Layout) {
321+
void WinCOFFWriter::defineSection(const MCAssembler &Asm,
322+
const MCSectionCOFF &MCSec) {
323323
COFFSection *Section = createSection(MCSec.getName());
324324
COFFSymbol *Symbol = createSymbol(MCSec.getName());
325325
Section->Symbol = Symbol;
@@ -354,8 +354,8 @@ void WinCOFFWriter::defineSection(const MCSectionCOFF &MCSec,
354354
if (UseOffsetLabels && !MCSec.empty()) {
355355
const uint32_t Interval = 1 << OffsetLabelIntervalBits;
356356
uint32_t N = 1;
357-
for (uint32_t Off = Interval, E = Layout.getSectionAddressSize(&MCSec);
358-
Off < E; Off += Interval) {
357+
for (uint32_t Off = Interval, E = Asm.getSectionAddressSize(MCSec); Off < E;
358+
Off += Interval) {
359359
auto Name = ("$L" + MCSec.getName() + "_" + Twine(N++)).str();
360360
COFFSymbol *Label = createSymbol(Name);
361361
Label->Section = Section;
@@ -775,7 +775,7 @@ void WinCOFFWriter::assignFileOffsets(MCAssembler &Asm,
775775
if (!Sec || Sec->Number == -1)
776776
continue;
777777

778-
Sec->Header.SizeOfRawData = Layout.getSectionAddressSize(&Section);
778+
Sec->Header.SizeOfRawData = Asm.getSectionAddressSize(Section);
779779

780780
if (IsPhysicalSection(Sec)) {
781781
Sec->Header.PointerToRawData = Offset;
@@ -841,7 +841,7 @@ void WinCOFFWriter::executePostLayoutBinding(MCAssembler &Asm) {
841841
if ((Mode == NonDwoOnly && isDwoSection(Section)) ||
842842
(Mode == DwoOnly && !isDwoSection(Section)))
843843
continue;
844-
defineSection(static_cast<const MCSectionCOFF &>(Section), Layout);
844+
defineSection(Asm, static_cast<const MCSectionCOFF &>(Section));
845845
}
846846

847847
if (Mode != DwoOnly)

llvm/lib/MC/XCOFFObjectWriter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,7 +1477,7 @@ void XCOFFObjectWriter::assignAddressesAndIndices(MCAssembler &Asm,
14771477
for (auto &Csect : *Group) {
14781478
const MCSectionXCOFF *MCSec = Csect.MCSec;
14791479
Csect.Address = alignTo(Address, MCSec->getAlign());
1480-
Csect.Size = Layout.getSectionAddressSize(MCSec);
1480+
Csect.Size = Asm.getSectionAddressSize(*MCSec);
14811481
Address = Csect.Address + Csect.Size;
14821482
Csect.SymbolTableIndex = SymbolTableIndex;
14831483
SymbolIndexMap[MCSec->getQualNameSymbol()] = Csect.SymbolTableIndex;
@@ -1560,7 +1560,7 @@ void XCOFFObjectWriter::assignAddressesAndIndices(MCAssembler &Asm,
15601560

15611561
// Section size.
15621562
// For DWARF section, we must use the real size which may be not aligned.
1563-
DwarfSection.Size = DwarfSect.Size = Layout.getSectionAddressSize(MCSec);
1563+
DwarfSection.Size = DwarfSect.Size = Asm.getSectionAddressSize(*MCSec);
15641564

15651565
Address = DwarfSection.Address + DwarfSection.Size;
15661566

llvm/tools/dsymutil/MachOUtils.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -323,17 +323,18 @@ static void transferSegmentAndSections(
323323
}
324324

325325
// Write the __DWARF segment load command to the output file.
326-
static bool createDwarfSegment(uint64_t VMAddr, uint64_t FileOffset,
326+
static bool createDwarfSegment(const MCAssembler& Asm,uint64_t VMAddr, uint64_t FileOffset,
327327
uint64_t FileSize, unsigned NumSections,
328-
MCAsmLayout &Layout, MachObjectWriter &Writer) {
328+
MachObjectWriter &Writer) {
329+
auto &Layout = *Asm.getLayout();
329330
Writer.writeSegmentLoadCommand("__DWARF", NumSections, VMAddr,
330331
alignTo(FileSize, 0x1000), FileOffset,
331332
FileSize, /* MaxProt */ 7,
332333
/* InitProt =*/3);
333334

334335
for (unsigned int i = 0, n = Layout.getSectionOrder().size(); i != n; ++i) {
335336
MCSection *Sec = Layout.getSectionOrder()[i];
336-
if (Sec->begin() == Sec->end() || !Layout.getSectionFileSize(Sec))
337+
if (!Asm.getSectionFileSize(*Sec))
337338
continue;
338339

339340
Align Alignment = Sec->getAlign();
@@ -345,10 +346,10 @@ static bool createDwarfSegment(uint64_t VMAddr, uint64_t FileOffset,
345346
"'s file offset exceeds 4GB."
346347
" Refusing to produce an invalid Mach-O file.");
347348
}
348-
Writer.writeSection(Layout, *Sec, VMAddr, FileOffset, 0, 0, 0);
349+
Writer.writeSection(Asm, *Sec, VMAddr, FileOffset, 0, 0, 0);
349350

350-
FileOffset += Layout.getSectionAddressSize(Sec);
351-
VMAddr += Layout.getSectionAddressSize(Sec);
351+
FileOffset += Asm.getSectionAddressSize(*Sec);
352+
VMAddr += Asm.getSectionAddressSize(*Sec);
352353
}
353354
return true;
354355
}
@@ -495,7 +496,7 @@ bool generateDsymCompanion(
495496
if (Sec->begin() == Sec->end())
496497
continue;
497498

498-
if (uint64_t Size = Layout.getSectionFileSize(Sec)) {
499+
if (uint64_t Size = MCAsm.getSectionFileSize(*Sec)) {
499500
DwarfSegmentSize = alignTo(DwarfSegmentSize, Sec->getAlign());
500501
DwarfSegmentSize += Size;
501502
++NumDwarfSections;
@@ -586,8 +587,8 @@ bool generateDsymCompanion(
586587
}
587588

588589
// Write the load command for the __DWARF segment.
589-
if (!createDwarfSegment(DwarfVMAddr, DwarfSegmentStart, DwarfSegmentSize,
590-
NumDwarfSections, Layout, Writer))
590+
if (!createDwarfSegment(MCAsm, DwarfVMAddr, DwarfSegmentStart, DwarfSegmentSize,
591+
NumDwarfSections, Writer))
591592
return false;
592593

593594
assert(OutFile.tell() == LoadCommandSize + HeaderSize);

0 commit comments

Comments
 (0)