Skip to content

Commit 1365f3f

Browse files
MaskRaycachemeifyoucan
authored andcommitted
MC: Rename isVirtualSection to isBssSection
The term BSS (Block Started by Symbol) is a standard, widely recognized term, available in the a.out object file format and adopted by formats like COFF, XCOFF, Mach-O (called S_ZEROFILL while `__bss` is also used), and ELF. To avoid introducing unfamiliar terms, we should use isBSSSection instead of isVirtualSection.
1 parent 09d155b commit 1365f3f

File tree

10 files changed

+21
-22
lines changed

10 files changed

+21
-22
lines changed

llvm/include/llvm/MC/MCSection.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ class LLVM_ABI MCSection {
9292
bool IsRegistered : 1;
9393

9494
bool IsText : 1;
95-
96-
bool IsVirtual : 1;
95+
bool IsBss : 1;
9796

9897
/// Whether the section contains linker-relaxable fragments. If true, the
9998
/// offset between two locations may not be fully resolved.
@@ -177,9 +176,9 @@ class LLVM_ABI MCSection {
177176
/// instead of 0s.
178177
virtual bool useCodeAlign() const = 0;
179178

180-
/// Check whether this section is "virtual", that is has no actual object
181-
/// file contents.
182-
bool isVirtualSection() const { return IsVirtual; }
179+
/// Return true if this is a BSS section (e.g., ELF .bss or .tbss) that does
180+
/// not store content and is typically initialized to zeroes by the runtime.
181+
bool isBssSection() const { return IsBss; }
183182

184183
virtual StringRef getVirtualSectionKind() const;
185184
};

llvm/include/llvm/MC/MCSectionGOFF.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class LLVM_ABI MCSectionGOFF final : public MCSection {
111111

112112
// Returns the text style for a section. Only defined for ED and PR sections.
113113
GOFF::ESDTextStyle getTextStyle() const {
114-
assert((isED() || isPR() || isVirtualSection()) && "Expect ED or PR section");
114+
assert((isED() || isPR() || isBssSection()) && "Expect ED or PR section");
115115
if (isED())
116116
return EDAttributes.TextStyle;
117117
if (isPR())

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,7 @@ void AsmPrinter::emitGlobalVariable(const GlobalVariable *GV) {
810810

811811
// If we have a bss global going to a section that supports the
812812
// zerofill directive, do so here.
813-
if (GVKind.isBSS() && MAI->isMachO() && TheSection->isVirtualSection()) {
813+
if (GVKind.isBSS() && MAI->isMachO() && TheSection->isBssSection()) {
814814
if (Size == 0)
815815
Size = 1; // zerofill of 0 bytes is undefined.
816816
emitLinkage(GV, GVSym);

llvm/lib/MC/MCAssembler.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ uint64_t MCAssembler::getSectionAddressSize(const MCSection &Sec) const {
362362

363363
uint64_t MCAssembler::getSectionFileSize(const MCSection &Sec) const {
364364
// Virtual sections have no file size.
365-
if (Sec.isVirtualSection())
365+
if (Sec.isBssSection())
366366
return 0;
367367
return getSectionAddressSize(Sec);
368368
}
@@ -559,7 +559,7 @@ void MCAssembler::writeSectionData(raw_ostream &OS,
559559
const MCSection *Sec) const {
560560
assert(getBackendPtr() && "Expected assembler backend");
561561

562-
if (Sec->isVirtualSection()) {
562+
if (Sec->isBssSection()) {
563563
assert(getSectionFileSize(*Sec) == 0 && "Invalid size for section!");
564564

565565
// Ensure no fixups or non-zero bytes are written to BSS sections, catching

llvm/lib/MC/MCMachOStreamer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ void MCMachOStreamer::emitZerofill(MCSection *Section, MCSymbol *Symbol,
401401
// On darwin all virtual sections have zerofill type. Disallow the usage of
402402
// .zerofill in non-virtual functions. If something similar is needed, use
403403
// .space or .zero.
404-
if (!Section->isVirtualSection()) {
404+
if (!Section->isBssSection()) {
405405
getContext().reportError(
406406
Loc, "The usage of .zerofill is restricted to sections of "
407407
"ZEROFILL type. Use .zero or .space instead.");

llvm/lib/MC/MCParser/AsmParser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3404,7 +3404,7 @@ bool AsmParser::parseDirectiveAlign(bool IsPow2, uint8_t ValueSize) {
34043404
const MCSection *Section = getStreamer().getCurrentSectionOnly();
34053405
assert(Section && "must have section to emit alignment");
34063406

3407-
if (HasFillExpr && FillExpr != 0 && Section->isVirtualSection()) {
3407+
if (HasFillExpr && FillExpr != 0 && Section->isBssSection()) {
34083408
ReturnVal |=
34093409
Warning(FillExprLoc, "ignoring non-zero fill value in " +
34103410
Section->getVirtualSectionKind() +

llvm/lib/MC/MCSection.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ using namespace llvm;
2121
MCSection::MCSection(SectionVariant V, StringRef Name, bool IsText,
2222
bool IsVirtual, MCSymbol *Begin)
2323
: Begin(Begin), HasInstructions(false), IsRegistered(false), IsText(IsText),
24-
IsVirtual(IsVirtual), LinkerRelaxable(false), Name(Name), Variant(V) {
24+
IsBss(IsVirtual), LinkerRelaxable(false), Name(Name), Variant(V) {
2525
// The initial subsection number is 0. Create a fragment list.
2626
CurFragList = &Subsections.emplace_back(0u, FragList{}).second;
2727
}

llvm/lib/MC/MachObjectWriter.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ uint64_t MachObjectWriter::getPaddingSize(const MCAssembler &Asm,
134134
return 0;
135135

136136
const MCSection &NextSec = *SectionOrder[Next];
137-
if (NextSec.isVirtualSection())
137+
if (NextSec.isBssSection())
138138
return 0;
139139
return offsetToAlignment(EndAddr, NextSec.getAlign());
140140
}
@@ -277,7 +277,7 @@ void MachObjectWriter::writeSection(const MCAssembler &Asm,
277277
const MCSectionMachO &Section = cast<MCSectionMachO>(Sec);
278278

279279
// The offset is unused for virtual sections.
280-
if (Section.isVirtualSection()) {
280+
if (Section.isBssSection()) {
281281
assert(Asm.getSectionFileSize(Sec) == 0 && "Invalid file size!");
282282
FileOffset = 0;
283283
}
@@ -692,13 +692,13 @@ void MachObjectWriter::computeSectionAddresses(const MCAssembler &Asm) {
692692
unsigned i = 0;
693693
// Compute the section layout order. Virtual sections must go last.
694694
for (MCSection &Sec : Asm) {
695-
if (!Sec.isVirtualSection()) {
695+
if (!Sec.isBssSection()) {
696696
SectionOrder.push_back(&Sec);
697697
cast<MCSectionMachO>(Sec).setLayoutOrder(i++);
698698
}
699699
}
700700
for (MCSection &Sec : Asm) {
701-
if (Sec.isVirtualSection()) {
701+
if (Sec.isBssSection()) {
702702
SectionOrder.push_back(&Sec);
703703
cast<MCSectionMachO>(Sec).setLayoutOrder(i++);
704704
}
@@ -895,7 +895,7 @@ void MachObjectWriter::writeMachOHeader(MCAssembler &Asm) {
895895

896896
VMSize = std::max(VMSize, Address + Size);
897897

898-
if (Sec.isVirtualSection())
898+
if (Sec.isBssSection())
899899
continue;
900900

901901
SectionDataSize = std::max(SectionDataSize, Address + Size);
@@ -938,7 +938,7 @@ void MachObjectWriter::writeMachOHeader(MCAssembler &Asm) {
938938
unsigned Flags = Sec.getTypeAndAttributes();
939939
if (Sec.hasInstructions())
940940
Flags |= MachO::S_ATTR_SOME_INSTRUCTIONS;
941-
if (!cast<MCSectionMachO>(Sec).isVirtualSection() &&
941+
if (!cast<MCSectionMachO>(Sec).isBssSection() &&
942942
!isUInt<32>(SectionStart)) {
943943
getContext().reportError(
944944
SMLoc(), "cannot encode offset of section; object file too large");

llvm/lib/ObjCopy/MachO/MachOObject.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,14 @@ struct Section {
6464
return static_cast<MachO::SectionType>(Flags & MachO::SECTION_TYPE);
6565
}
6666

67-
bool isVirtualSection() const {
67+
bool isBssSection() const {
6868
return (getType() == MachO::S_ZEROFILL ||
6969
getType() == MachO::S_GB_ZEROFILL ||
7070
getType() == MachO::S_THREAD_LOCAL_ZEROFILL);
7171
}
7272

7373
bool hasValidOffset() const {
74-
return !(isVirtualSection() || OriginalOffset == 0);
74+
return !(isBssSection() || OriginalOffset == 0);
7575
}
7676
};
7777

llvm/lib/ObjCopy/MachO/MachOWriter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ size_t MachOWriter::totalSize() const {
112112
for (const std::unique_ptr<Section> &S : LC.Sections) {
113113
if (!S->hasValidOffset()) {
114114
assert((S->Offset == 0) && "Skipped section's offset must be zero");
115-
assert((S->isVirtualSection() || S->Size == 0) &&
115+
assert((S->isBssSection() || S->Size == 0) &&
116116
"Non-zero-fill sections with zero offset must have zero size");
117117
continue;
118118
}
@@ -240,7 +240,7 @@ void MachOWriter::writeSections() {
240240
for (const std::unique_ptr<Section> &Sec : LC.Sections) {
241241
if (!Sec->hasValidOffset()) {
242242
assert((Sec->Offset == 0) && "Skipped section's offset must be zero");
243-
assert((Sec->isVirtualSection() || Sec->Size == 0) &&
243+
assert((Sec->isBssSection() || Sec->Size == 0) &&
244244
"Non-zero-fill sections with zero offset must have zero size");
245245
continue;
246246
}

0 commit comments

Comments
 (0)