diff --git a/llvm/include/llvm/MC/MCSection.h b/llvm/include/llvm/MC/MCSection.h index fe8c13d108c2..68fc8767d6bc 100644 --- a/llvm/include/llvm/MC/MCSection.h +++ b/llvm/include/llvm/MC/MCSection.h @@ -91,8 +91,7 @@ private: bool IsRegistered : 1; bool IsText : 1; - - bool IsVirtual : 1; + bool IsBss : 1; /// Whether the section contains linker-relaxable fragments. If true, the /// offset between two locations may not be fully resolved. @@ -176,9 +175,9 @@ public: /// instead of 0s. virtual bool useCodeAlign() const = 0; - /// Check whether this section is "virtual", that is has no actual object - /// file contents. - bool isVirtualSection() const { return IsVirtual; } + /// Return true if this is a BSS section (e.g., ELF .bss or .tbss) that does + /// not store content and is typically initialized to zeroes by the runtime. + bool isBssSection() const { return IsBss; } virtual StringRef getVirtualSectionKind() const; }; diff --git a/llvm/include/llvm/MC/MCSectionGOFF.h b/llvm/include/llvm/MC/MCSectionGOFF.h index 9e3f95e82a14..b166397b5d37 100644 --- a/llvm/include/llvm/MC/MCSectionGOFF.h +++ b/llvm/include/llvm/MC/MCSectionGOFF.h @@ -111,7 +111,7 @@ public: // Returns the text style for a section. Only defined for ED and PR sections. GOFF::ESDTextStyle getTextStyle() const { - assert((isED() || isPR() || isVirtualSection()) && "Expect ED or PR section"); + assert((isED() || isPR() || isBssSection()) && "Expect ED or PR section"); if (isED()) return EDAttributes.TextStyle; if (isPR()) diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index 76a1d8c93160..10bdb81e4fb4 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -809,7 +809,7 @@ void AsmPrinter::emitGlobalVariable(const GlobalVariable *GV) { // If we have a bss global going to a section that supports the // zerofill directive, do so here. - if (GVKind.isBSS() && MAI->isMachO() && TheSection->isVirtualSection()) { + if (GVKind.isBSS() && MAI->isMachO() && TheSection->isBssSection()) { if (Size == 0) Size = 1; // zerofill of 0 bytes is undefined. emitLinkage(GV, GVSym); diff --git a/llvm/lib/MC/MCAssembler.cpp b/llvm/lib/MC/MCAssembler.cpp index 674adc92257c..317ba8128cff 100644 --- a/llvm/lib/MC/MCAssembler.cpp +++ b/llvm/lib/MC/MCAssembler.cpp @@ -362,7 +362,7 @@ uint64_t MCAssembler::getSectionAddressSize(const MCSection &Sec) const { uint64_t MCAssembler::getSectionFileSize(const MCSection &Sec) const { // Virtual sections have no file size. - if (Sec.isVirtualSection()) + if (Sec.isBssSection()) return 0; return getSectionAddressSize(Sec); } @@ -559,7 +559,7 @@ void MCAssembler::writeSectionData(raw_ostream &OS, const MCSection *Sec) const { assert(getBackendPtr() && "Expected assembler backend"); - if (Sec->isVirtualSection()) { + if (Sec->isBssSection()) { assert(getSectionFileSize(*Sec) == 0 && "Invalid size for section!"); // Ensure no fixups or non-zero bytes are written to BSS sections, catching diff --git a/llvm/lib/MC/MCMachOStreamer.cpp b/llvm/lib/MC/MCMachOStreamer.cpp index 08d2b931858a..e8bbb53b98dd 100644 --- a/llvm/lib/MC/MCMachOStreamer.cpp +++ b/llvm/lib/MC/MCMachOStreamer.cpp @@ -393,7 +393,7 @@ void MCMachOStreamer::emitZerofill(MCSection *Section, MCSymbol *Symbol, // On darwin all virtual sections have zerofill type. Disallow the usage of // .zerofill in non-virtual functions. If something similar is needed, use // .space or .zero. - if (!Section->isVirtualSection()) { + if (!Section->isBssSection()) { getContext().reportError( Loc, "The usage of .zerofill is restricted to sections of " "ZEROFILL type. Use .zero or .space instead."); diff --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp index 77bf84364c5a..4c55e97f0c1f 100644 --- a/llvm/lib/MC/MCParser/AsmParser.cpp +++ b/llvm/lib/MC/MCParser/AsmParser.cpp @@ -3404,7 +3404,7 @@ bool AsmParser::parseDirectiveAlign(bool IsPow2, uint8_t ValueSize) { const MCSection *Section = getStreamer().getCurrentSectionOnly(); assert(Section && "must have section to emit alignment"); - if (HasFillExpr && FillExpr != 0 && Section->isVirtualSection()) { + if (HasFillExpr && FillExpr != 0 && Section->isBssSection()) { ReturnVal |= Warning(FillExprLoc, "ignoring non-zero fill value in " + Section->getVirtualSectionKind() + diff --git a/llvm/lib/MC/MCSection.cpp b/llvm/lib/MC/MCSection.cpp index 93671450c0c2..fd1d072cf415 100644 --- a/llvm/lib/MC/MCSection.cpp +++ b/llvm/lib/MC/MCSection.cpp @@ -21,7 +21,7 @@ using namespace llvm; MCSection::MCSection(SectionVariant V, StringRef Name, bool IsText, bool IsVirtual, MCSymbol *Begin) : Begin(Begin), HasInstructions(false), IsRegistered(false), IsText(IsText), - IsVirtual(IsVirtual), LinkerRelaxable(false), Name(Name), Variant(V) { + IsBss(IsVirtual), LinkerRelaxable(false), Name(Name), Variant(V) { // The initial subsection number is 0. Create a fragment list. CurFragList = &Subsections.emplace_back(0u, FragList{}).second; } diff --git a/llvm/lib/MC/MachObjectWriter.cpp b/llvm/lib/MC/MachObjectWriter.cpp index 3291dd774c1e..3298eef5d41a 100644 --- a/llvm/lib/MC/MachObjectWriter.cpp +++ b/llvm/lib/MC/MachObjectWriter.cpp @@ -131,7 +131,7 @@ uint64_t MachObjectWriter::getPaddingSize(const MCAssembler &Asm, return 0; const MCSection &NextSec = *SectionOrder[Next]; - if (NextSec.isVirtualSection()) + if (NextSec.isBssSection()) return 0; return offsetToAlignment(EndAddr, NextSec.getAlign()); } @@ -267,7 +267,7 @@ void MachObjectWriter::writeSection(const MCAssembler &Asm, const MCSectionMachO &Section = cast(Sec); // The offset is unused for virtual sections. - if (Section.isVirtualSection()) { + if (Section.isBssSection()) { assert(Asm.getSectionFileSize(Sec) == 0 && "Invalid file size!"); FileOffset = 0; } @@ -682,13 +682,13 @@ void MachObjectWriter::computeSectionAddresses(const MCAssembler &Asm) { unsigned i = 0; // Compute the section layout order. Virtual sections must go last. for (MCSection &Sec : Asm) { - if (!Sec.isVirtualSection()) { + if (!Sec.isBssSection()) { SectionOrder.push_back(&Sec); cast(Sec).setLayoutOrder(i++); } } for (MCSection &Sec : Asm) { - if (Sec.isVirtualSection()) { + if (Sec.isBssSection()) { SectionOrder.push_back(&Sec); cast(Sec).setLayoutOrder(i++); } @@ -883,7 +883,7 @@ uint64_t MachObjectWriter::writeObject() { VMSize = std::max(VMSize, Address + Size); - if (Sec.isVirtualSection()) + if (Sec.isBssSection()) continue; SectionDataSize = std::max(SectionDataSize, Address + Size); @@ -915,7 +915,7 @@ uint64_t MachObjectWriter::writeObject() { unsigned Flags = Sec.getTypeAndAttributes(); if (Sec.hasInstructions()) Flags |= MachO::S_ATTR_SOME_INSTRUCTIONS; - if (!cast(Sec).isVirtualSection() && + if (!cast(Sec).isBssSection() && !isUInt<32>(SectionStart)) { getContext().reportError( SMLoc(), "cannot encode offset of section; object file too large"); diff --git a/llvm/lib/ObjCopy/MachO/MachOObject.h b/llvm/lib/ObjCopy/MachO/MachOObject.h index 8f9444f5fb02..86c6b120fa6c 100644 --- a/llvm/lib/ObjCopy/MachO/MachOObject.h +++ b/llvm/lib/ObjCopy/MachO/MachOObject.h @@ -64,14 +64,14 @@ struct Section { return static_cast(Flags & MachO::SECTION_TYPE); } - bool isVirtualSection() const { + bool isBssSection() const { return (getType() == MachO::S_ZEROFILL || getType() == MachO::S_GB_ZEROFILL || getType() == MachO::S_THREAD_LOCAL_ZEROFILL); } bool hasValidOffset() const { - return !(isVirtualSection() || OriginalOffset == 0); + return !(isBssSection() || OriginalOffset == 0); } }; diff --git a/llvm/lib/ObjCopy/MachO/MachOWriter.cpp b/llvm/lib/ObjCopy/MachO/MachOWriter.cpp index 7c24d1277dc8..89c1df869929 100644 --- a/llvm/lib/ObjCopy/MachO/MachOWriter.cpp +++ b/llvm/lib/ObjCopy/MachO/MachOWriter.cpp @@ -112,7 +112,7 @@ size_t MachOWriter::totalSize() const { for (const std::unique_ptr
&S : LC.Sections) { if (!S->hasValidOffset()) { assert((S->Offset == 0) && "Skipped section's offset must be zero"); - assert((S->isVirtualSection() || S->Size == 0) && + assert((S->isBssSection() || S->Size == 0) && "Non-zero-fill sections with zero offset must have zero size"); continue; } @@ -240,7 +240,7 @@ void MachOWriter::writeSections() { for (const std::unique_ptr
&Sec : LC.Sections) { if (!Sec->hasValidOffset()) { assert((Sec->Offset == 0) && "Skipped section's offset must be zero"); - assert((Sec->isVirtualSection() || Sec->Size == 0) && + assert((Sec->isBssSection() || Sec->Size == 0) && "Non-zero-fill sections with zero offset must have zero size"); continue; }