Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions llvm/include/llvm/MC/MCObjectStreamer.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ class MCObjectStreamer : public MCStreamer {
MCSymbol *emitCFILabel() override;
void emitCFISections(bool EH, bool Debug) override;

// TODO: Change callers to use getCurrentFragment instead.
MCFragment *getOrCreateDataFragment() { return getCurrentFragment(); }

protected:
bool changeSectionImpl(MCSection *Section, uint32_t Subsection);

Expand Down
2 changes: 0 additions & 2 deletions llvm/include/llvm/MC/MCSection.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,6 @@ class LLVM_ABI MCSection {
/// Check whether this section is "virtual", that is has no actual object
/// file contents.
bool isVirtualSection() const { return IsVirtual; }

virtual StringRef getVirtualSectionKind() const;
};

// Represents a contiguous piece of code or data within a section. Its size is
Expand Down
1 change: 0 additions & 1 deletion llvm/include/llvm/MC/MCSectionCOFF.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ class MCSectionCOFF final : public MCSection {
raw_ostream &OS,
uint32_t Subsection) const override;
bool useCodeAlign() const override;
StringRef getVirtualSectionKind() const override;

unsigned getOrAssignWinCFISectionID(unsigned *NextID) const {
if (WinCFISectionID == ~0U)
Expand Down
1 change: 0 additions & 1 deletion llvm/include/llvm/MC/MCSectionELF.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ class MCSectionELF final : public MCSection {
raw_ostream &OS,
uint32_t Subsection) const override;
bool useCodeAlign() const override;
StringRef getVirtualSectionKind() const override;

bool isUnique() const { return UniqueID != NonUniqueID; }
unsigned getUniqueID() const { return UniqueID; }
Expand Down
4 changes: 4 additions & 0 deletions llvm/include/llvm/MC/MCStreamer.h
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,12 @@ class LLVM_ABI MCStreamer {
}

MCFragment *getCurrentFragment() const {
// Ensure consistency with the section stack.
assert(!getCurrentSection().first ||
CurFrag->getParent() == getCurrentSection().first);
// Ensure we eagerly allocate an empty fragment when adding fragment with a
// variable-size tail.
assert(!CurFrag || CurFrag->getKind() == MCFragment::FT_Data);
return CurFrag;
}
/// Save the current and previous section on the section stack.
Expand Down
32 changes: 27 additions & 5 deletions llvm/lib/MC/MCAssembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -567,15 +567,37 @@ void MCAssembler::writeSectionData(raw_ostream &OS,
// not tracked for efficiency.
auto Fn = [](char c) { return c != 0; };
for (const MCFragment &F : *Sec) {
if (any_of(F.getContents(), Fn) || any_of(F.getVarContents(), Fn)) {
reportError(SMLoc(), Sec->getVirtualSectionKind() + " section '" +
Sec->getName() +
bool HasNonZero = false;
switch (F.getKind()) {
default:
reportFatalInternalError("BSS section '" + Sec->getName() +
"' contains invalid fragment");
break;
case MCFragment::FT_Data:
case MCFragment::FT_Relaxable:
HasNonZero =
any_of(F.getContents(), Fn) || any_of(F.getVarContents(), Fn);
break;
case MCFragment::FT_Align:
// Disallowed for API usage. AsmParser changes non-zero fill values to
// 0.
assert(F.getAlignFill() == 0 && "Invalid align in virtual section!");
break;
case MCFragment::FT_Fill:
HasNonZero = cast<MCFillFragment>(F).getValue() != 0;
break;
case MCFragment::FT_Org:
HasNonZero = cast<MCOrgFragment>(F).getValue() != 0;
break;
}
if (HasNonZero) {
reportError(SMLoc(), "BSS section '" + Sec->getName() +
"' cannot have non-zero bytes");
break;
}
if (F.getFixups().size() || F.getVarFixups().size()) {
reportError(SMLoc(), Sec->getVirtualSectionKind() + " section '" +
Sec->getName() + "' cannot have fixups");
reportError(SMLoc(),
"BSS section '" + Sec->getName() + "' cannot have fixups");
break;
}
}
Expand Down
18 changes: 9 additions & 9 deletions llvm/lib/MC/MCObjectStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void MCObjectStreamer::emitCFISections(bool EH, bool Debug) {
void MCObjectStreamer::emitValueImpl(const MCExpr *Value, unsigned Size,
SMLoc Loc) {
MCStreamer::emitValueImpl(Value, Size, Loc);
MCFragment *DF = getOrCreateDataFragment();
MCFragment *DF = getCurrentFragment();

MCDwarfLineEntry::make(this, getCurrentSectionOnly());

Expand Down Expand Up @@ -168,7 +168,7 @@ void MCObjectStreamer::emitLabel(MCSymbol *Symbol, SMLoc Loc) {
// If there is a current fragment, mark the symbol as pointing into it.
// Otherwise queue the label and set its fragment pointer when we emit the
// next fragment.
MCFragment *F = getOrCreateDataFragment();
MCFragment *F = getCurrentFragment();
Symbol->setFragment(F);
Symbol->setOffset(F->getContents().size());

Expand Down Expand Up @@ -202,7 +202,7 @@ void MCObjectStreamer::emitULEB128Value(const MCExpr *Value) {
emitULEB128IntValue(IntValue);
return;
}
auto *F = getOrCreateDataFragment();
auto *F = getCurrentFragment();
F->makeLEB(false, Value);
newFragment();
}
Expand All @@ -213,7 +213,7 @@ void MCObjectStreamer::emitSLEB128Value(const MCExpr *Value) {
emitSLEB128IntValue(IntValue);
return;
}
auto *F = getOrCreateDataFragment();
auto *F = getCurrentFragment();
F->makeLEB(true, Value);
newFragment();
}
Expand Down Expand Up @@ -312,7 +312,7 @@ void MCObjectStreamer::emitInstruction(const MCInst &Inst,

void MCObjectStreamer::emitInstToData(const MCInst &Inst,
const MCSubtargetInfo &STI) {
MCFragment *F = getOrCreateDataFragment();
MCFragment *F = getCurrentFragment();

// Append the instruction to the data fragment.
size_t FixupStartIndex = F->getFixups().size();
Expand Down Expand Up @@ -344,7 +344,7 @@ void MCObjectStreamer::emitInstToData(const MCInst &Inst,

void MCObjectStreamer::emitInstToFragment(const MCInst &Inst,
const MCSubtargetInfo &STI) {
auto *F = getOrCreateDataFragment();
auto *F = getCurrentFragment();
SmallVector<char, 16> Data;
SmallVector<MCFixup, 1> Fixups;
getAssembler().getEmitter().encodeInstruction(Inst, Data, Fixups, STI);
Expand Down Expand Up @@ -417,7 +417,7 @@ void MCObjectStreamer::emitDwarfAdvanceLineAddr(int64_t LineDelta,
return;
}

auto *F = getOrCreateDataFragment();
auto *F = getCurrentFragment();
F->Kind = MCFragment::FT_Dwarf;
F->setDwarfAddrDelta(buildSymbolDiff(*this, Label, LastLabel, SMLoc()));
F->setDwarfLineDelta(LineDelta);
Expand Down Expand Up @@ -449,7 +449,7 @@ void MCObjectStreamer::emitDwarfLineEndEntry(MCSection *Section,
void MCObjectStreamer::emitDwarfAdvanceFrameAddr(const MCSymbol *LastLabel,
const MCSymbol *Label,
SMLoc Loc) {
auto *F = getOrCreateDataFragment();
auto *F = getCurrentFragment();
F->Kind = MCFragment::FT_DwarfFrame;
F->setDwarfAddrDelta(buildSymbolDiff(*this, Label, LastLabel, Loc));
newFragment();
Expand Down Expand Up @@ -511,7 +511,7 @@ void MCObjectStreamer::emitCVFileChecksumOffsetDirective(unsigned FileNo) {

void MCObjectStreamer::emitBytes(StringRef Data) {
MCDwarfLineEntry::make(this, getCurrentSectionOnly());
MCFragment *DF = getOrCreateDataFragment();
MCFragment *DF = getCurrentFragment();
DF->appendContents(ArrayRef(Data.data(), Data.size()));
}

Expand Down
5 changes: 2 additions & 3 deletions llvm/lib/MC/MCParser/AsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3406,9 +3406,8 @@ bool AsmParser::parseDirectiveAlign(bool IsPow2, uint8_t ValueSize) {

if (HasFillExpr && FillExpr != 0 && Section->isVirtualSection()) {
ReturnVal |=
Warning(FillExprLoc, "ignoring non-zero fill value in " +
Section->getVirtualSectionKind() +
" section '" + Section->getName() + "'");
Warning(FillExprLoc, "ignoring non-zero fill value in BSS section '" +
Section->getName() + "'");
FillExpr = 0;
}

Expand Down
2 changes: 0 additions & 2 deletions llvm/lib/MC/MCSection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ MCSymbol *MCSection::getEndSymbol(MCContext &Ctx) {

bool MCSection::hasEnded() const { return End && End->isInSection(); }

StringRef MCSection::getVirtualSectionKind() const { return "virtual"; }

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
LLVM_DUMP_METHOD void MCSection::dump(
DenseMap<const MCFragment *, SmallVector<const MCSymbol *, 0>> *FragToSyms)
Expand Down
4 changes: 0 additions & 4 deletions llvm/lib/MC/MCSectionCOFF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,3 @@ void MCSectionCOFF::printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
}

bool MCSectionCOFF::useCodeAlign() const { return isText(); }

StringRef MCSectionCOFF::getVirtualSectionKind() const {
return "IMAGE_SCN_CNT_UNINITIALIZED_DATA";
}
2 changes: 0 additions & 2 deletions llvm/lib/MC/MCSectionELF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,5 +215,3 @@ void MCSectionELF::printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
bool MCSectionELF::useCodeAlign() const {
return getFlags() & ELF::SHF_EXECINSTR;
}

StringRef MCSectionELF::getVirtualSectionKind() const { return "SHT_NOBITS"; }
2 changes: 1 addition & 1 deletion llvm/lib/MC/MCWin64EH.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ static void EmitUnwindInfo(MCStreamer &streamer, WinEH::FrameInfo *info) {

// Emit the epilog instructions.
if (EnableUnwindV2) {
MCFragment *DF = OS->getOrCreateDataFragment();
MCFragment *DF = OS->getCurrentFragment();

bool IsLast = true;
for (const auto &Epilog : llvm::reverse(info->EpilogMap)) {
Expand Down
10 changes: 5 additions & 5 deletions llvm/lib/MC/MCWinCOFFStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ void MCWinCOFFStreamer::emitCOFFSymbolIndex(MCSymbol const *Symbol) {

void MCWinCOFFStreamer::emitCOFFSectionIndex(const MCSymbol *Symbol) {
visitUsedSymbol(*Symbol);
MCFragment *DF = getOrCreateDataFragment();
MCFragment *DF = getCurrentFragment();
const MCSymbolRefExpr *SRE = MCSymbolRefExpr::create(Symbol, getContext());
MCFixup Fixup = MCFixup::create(DF->getContents().size(), SRE, FK_SecRel_2);
DF->addFixup(Fixup);
Expand All @@ -288,7 +288,7 @@ void MCWinCOFFStreamer::emitCOFFSectionIndex(const MCSymbol *Symbol) {
void MCWinCOFFStreamer::emitCOFFSecRel32(const MCSymbol *Symbol,
uint64_t Offset) {
visitUsedSymbol(*Symbol);
MCFragment *DF = getOrCreateDataFragment();
MCFragment *DF = getCurrentFragment();
// Create Symbol A for the relocation relative reference.
const MCExpr *MCE = MCSymbolRefExpr::create(Symbol, getContext());
// Add the constant offset, if given.
Expand All @@ -306,7 +306,7 @@ void MCWinCOFFStreamer::emitCOFFSecRel32(const MCSymbol *Symbol,
void MCWinCOFFStreamer::emitCOFFImgRel32(const MCSymbol *Symbol,
int64_t Offset) {
visitUsedSymbol(*Symbol);
MCFragment *DF = getOrCreateDataFragment();
MCFragment *DF = getCurrentFragment();
// Create Symbol A for the relocation relative reference.
const MCExpr *MCE = MCSymbolRefExpr::create(
Symbol, MCSymbolRefExpr::VK_COFF_IMGREL32, getContext());
Expand All @@ -324,7 +324,7 @@ void MCWinCOFFStreamer::emitCOFFImgRel32(const MCSymbol *Symbol,

void MCWinCOFFStreamer::emitCOFFSecNumber(MCSymbol const *Symbol) {
visitUsedSymbol(*Symbol);
MCFragment *DF = getOrCreateDataFragment();
MCFragment *DF = getCurrentFragment();
// Create Symbol for section number.
const MCExpr *MCE = MCCOFFSectionNumberTargetExpr::create(
*Symbol, this->getWriter(), getContext());
Expand All @@ -338,7 +338,7 @@ void MCWinCOFFStreamer::emitCOFFSecNumber(MCSymbol const *Symbol) {

void MCWinCOFFStreamer::emitCOFFSecOffset(MCSymbol const *Symbol) {
visitUsedSymbol(*Symbol);
MCFragment *DF = getOrCreateDataFragment();
MCFragment *DF = getCurrentFragment();
// Create Symbol for section offset.
const MCExpr *MCE =
MCCOFFSectionOffsetTargetExpr::create(*Symbol, getContext());
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/MC/MCXCOFFStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void MCXCOFFStreamer::emitXCOFFSymbolLinkageWithVisibility(
void MCXCOFFStreamer::emitXCOFFRefDirective(const MCSymbol *Symbol) {
// Add a Fixup here to later record a relocation of type R_REF to prevent the
// ref symbol from being garbage collected (by the binder).
MCFragment *DF = getOrCreateDataFragment();
MCFragment *DF = getCurrentFragment();
const MCSymbolRefExpr *SRE = MCSymbolRefExpr::create(Symbol, getContext());
std::optional<MCFixupKind> MaybeKind =
getAssembler().getBackend().getFixupKind("R_REF");
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ class ARMELFStreamer : public MCELFStreamer {
getContext().reportError(Loc, "relocated expression must be 32-bit");
return;
}
getOrCreateDataFragment();
getCurrentFragment();
}

emitDataMappingSymbol();
Expand Down Expand Up @@ -1207,7 +1207,7 @@ inline void ARMELFStreamer::SwitchToExIdxSection(const MCSymbol &FnStart) {
}

void ARMELFStreamer::EmitFixup(const MCExpr *Expr, MCFixupKind Kind) {
MCFragment *Frag = getOrCreateDataFragment();
MCFragment *Frag = getCurrentFragment();
Frag->addFixup(MCFixup::create(Frag->getContents().size(), Expr, Kind));
}

Expand Down Expand Up @@ -1295,7 +1295,7 @@ void ARMELFStreamer::EmitPersonalityFixup(StringRef Name) {
MCSymbolRefExpr::create(PersonalitySym, ARM::S_ARM_NONE, getContext());

visitUsedExpr(*PersonalityRef);
MCFragment *DF = getOrCreateDataFragment();
MCFragment *DF = getCurrentFragment();
DF->addFixup(
MCFixup::create(DF->getContents().size(), PersonalityRef, FK_Data_4));
}
Expand Down
12 changes: 6 additions & 6 deletions llvm/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1033,42 +1033,42 @@ MCELFStreamer &MipsTargetELFStreamer::getStreamer() {
}

void MipsTargetELFStreamer::emitGPRel32Value(const MCExpr *Value) {
MCFragment *DF = getStreamer().getOrCreateDataFragment();
MCFragment *DF = getStreamer().getCurrentFragment();
DF->addFixup(MCFixup::create(DF->getContents().size(), Value,
Mips::fixup_Mips_GPREL32));
DF->appendContents(4, 0);
}

void MipsTargetELFStreamer::emitGPRel64Value(const MCExpr *Value) {
MCFragment *DF = getStreamer().getOrCreateDataFragment();
MCFragment *DF = getStreamer().getCurrentFragment();
DF->addFixup(MCFixup::create(DF->getContents().size(), Value,
Mips::fixup_Mips_GPREL32));
DF->appendContents(8, 0);
}

void MipsTargetELFStreamer::emitDTPRel32Value(const MCExpr *Value) {
MCFragment *DF = getStreamer().getOrCreateDataFragment();
MCFragment *DF = getStreamer().getCurrentFragment();
DF->addFixup(MCFixup::create(DF->getContents().size(), Value,
Mips::fixup_Mips_DTPREL32));
DF->appendContents(4, 0);
}

void MipsTargetELFStreamer::emitDTPRel64Value(const MCExpr *Value) {
MCFragment *DF = getStreamer().getOrCreateDataFragment();
MCFragment *DF = getStreamer().getCurrentFragment();
DF->addFixup(MCFixup::create(DF->getContents().size(), Value,
Mips::fixup_Mips_DTPREL64));
DF->appendContents(8, 0);
}

void MipsTargetELFStreamer::emitTPRel32Value(const MCExpr *Value) {
MCFragment *DF = getStreamer().getOrCreateDataFragment();
MCFragment *DF = getStreamer().getCurrentFragment();
DF->addFixup(MCFixup::create(DF->getContents().size(), Value,
Mips::fixup_Mips_TPREL32));
DF->appendContents(4, 0);
}

void MipsTargetELFStreamer::emitTPRel64Value(const MCExpr *Value) {
MCFragment *DF = getStreamer().getOrCreateDataFragment();
MCFragment *DF = getStreamer().getCurrentFragment();
DF->addFixup(MCFixup::create(DF->getContents().size(), Value,
Mips::fixup_Mips_TPREL64));
DF->appendContents(8, 0);
Expand Down
4 changes: 2 additions & 2 deletions llvm/test/MC/COFF/bss-text.s
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
# RUN: llvm-mc -triple=x86_64-pc-win32 %s

.bss
# CHECK: <unknown>:0: error: IMAGE_SCN_CNT_UNINITIALIZED_DATA section '.bss' cannot have non-zero bytes
# CHECK: <unknown>:0: error: BSS section '.bss' cannot have non-zero bytes
addb %bl,(%rax)

.section uninitialized,"b"
# CHECK: <unknown>:0: error: IMAGE_SCN_CNT_UNINITIALIZED_DATA section 'uninitialized' cannot have non-zero bytes
# CHECK: <unknown>:0: error: BSS section 'uninitialized' cannot have non-zero bytes
jmp foo

.section bss0,"b"
Expand Down
Loading
Loading