Skip to content

Commit 6201761

Browse files
committed
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 343f747 commit 6201761

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
@@ -91,8 +91,7 @@ class LLVM_ABI MCSection {
9191
bool IsRegistered : 1;
9292

9393
bool IsText : 1;
94-
95-
bool IsVirtual : 1;
94+
bool IsBss : 1;
9695

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

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

183182
virtual StringRef getVirtualSectionKind() const;
184183
};

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
@@ -809,7 +809,7 @@ void AsmPrinter::emitGlobalVariable(const GlobalVariable *GV) {
809809

810810
// If we have a bss global going to a section that supports the
811811
// zerofill directive, do so here.
812-
if (GVKind.isBSS() && MAI->isMachO() && TheSection->isVirtualSection()) {
812+
if (GVKind.isBSS() && MAI->isMachO() && TheSection->isBssSection()) {
813813
if (Size == 0)
814814
Size = 1; // zerofill of 0 bytes is undefined.
815815
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
@@ -393,7 +393,7 @@ void MCMachOStreamer::emitZerofill(MCSection *Section, MCSymbol *Symbol,
393393
// On darwin all virtual sections have zerofill type. Disallow the usage of
394394
// .zerofill in non-virtual functions. If something similar is needed, use
395395
// .space or .zero.
396-
if (!Section->isVirtualSection()) {
396+
if (!Section->isBssSection()) {
397397
getContext().reportError(
398398
Loc, "The usage of .zerofill is restricted to sections of "
399399
"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
@@ -131,7 +131,7 @@ uint64_t MachObjectWriter::getPaddingSize(const MCAssembler &Asm,
131131
return 0;
132132

133133
const MCSection &NextSec = *SectionOrder[Next];
134-
if (NextSec.isVirtualSection())
134+
if (NextSec.isBssSection())
135135
return 0;
136136
return offsetToAlignment(EndAddr, NextSec.getAlign());
137137
}
@@ -267,7 +267,7 @@ void MachObjectWriter::writeSection(const MCAssembler &Asm,
267267
const MCSectionMachO &Section = cast<MCSectionMachO>(Sec);
268268

269269
// The offset is unused for virtual sections.
270-
if (Section.isVirtualSection()) {
270+
if (Section.isBssSection()) {
271271
assert(Asm.getSectionFileSize(Sec) == 0 && "Invalid file size!");
272272
FileOffset = 0;
273273
}
@@ -682,13 +682,13 @@ void MachObjectWriter::computeSectionAddresses(const MCAssembler &Asm) {
682682
unsigned i = 0;
683683
// Compute the section layout order. Virtual sections must go last.
684684
for (MCSection &Sec : Asm) {
685-
if (!Sec.isVirtualSection()) {
685+
if (!Sec.isBssSection()) {
686686
SectionOrder.push_back(&Sec);
687687
cast<MCSectionMachO>(Sec).setLayoutOrder(i++);
688688
}
689689
}
690690
for (MCSection &Sec : Asm) {
691-
if (Sec.isVirtualSection()) {
691+
if (Sec.isBssSection()) {
692692
SectionOrder.push_back(&Sec);
693693
cast<MCSectionMachO>(Sec).setLayoutOrder(i++);
694694
}
@@ -883,7 +883,7 @@ uint64_t MachObjectWriter::writeObject() {
883883

884884
VMSize = std::max(VMSize, Address + Size);
885885

886-
if (Sec.isVirtualSection())
886+
if (Sec.isBssSection())
887887
continue;
888888

889889
SectionDataSize = std::max(SectionDataSize, Address + Size);
@@ -915,7 +915,7 @@ uint64_t MachObjectWriter::writeObject() {
915915
unsigned Flags = Sec.getTypeAndAttributes();
916916
if (Sec.hasInstructions())
917917
Flags |= MachO::S_ATTR_SOME_INSTRUCTIONS;
918-
if (!cast<MCSectionMachO>(Sec).isVirtualSection() &&
918+
if (!cast<MCSectionMachO>(Sec).isBssSection() &&
919919
!isUInt<32>(SectionStart)) {
920920
getContext().reportError(
921921
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)