Skip to content

Commit

Permalink
[MC][ARM] Delete MCSection::HasData and move SHF_ARM_PURECODE logic t…
Browse files Browse the repository at this point in the history
…o ARMELFObjectWriter::addTargetSectionFlags

This simplifies the generic interface and also makes SHF_ARM_PURECODE
more robust (fixes a TODO). Inspecting MCDataFragment contents covers
more cases than MCObjectStreamer::EmitBytes.
  • Loading branch information
MaskRay committed Jan 5, 2020
1 parent 35efef5 commit 5511861
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 17 deletions.
7 changes: 0 additions & 7 deletions llvm/include/llvm/MC/MCSection.h
Expand Up @@ -78,10 +78,6 @@ class MCSection {
/// Whether this section has had instructions emitted into it.
bool HasInstructions : 1;

/// Whether this section has had data emitted into it.
/// Right now this is only used by the ARM backend.
bool HasData : 1;

bool IsRegistered : 1;

MCDummyFragment DummyFragment;
Expand Down Expand Up @@ -150,9 +146,6 @@ class MCSection {
bool hasInstructions() const { return HasInstructions; }
void setHasInstructions(bool Value) { HasInstructions = Value; }

bool hasData() const { return HasData; }
void setHasData(bool Value) { HasData = Value; }

bool isRegistered() const { return IsRegistered; }
void setIsRegistered(bool Value) { IsRegistered = Value; }

Expand Down
6 changes: 0 additions & 6 deletions llvm/lib/MC/MCObjectStreamer.cpp
Expand Up @@ -569,12 +569,6 @@ void MCObjectStreamer::EmitBytes(StringRef Data) {
MCDataFragment *DF = getOrCreateDataFragment();
flushPendingLabels(DF, DF->getContents().size());
DF->getContents().append(Data.begin(), Data.end());

// EmitBytes might not cover all possible ways we emit data (or could be used
// to emit executable code in some cases), but is the best method we have
// right now for checking this.
MCSection *Sec = getCurrentSectionOnly();
Sec->setHasData(true);
}

void MCObjectStreamer::EmitValueToAlignment(unsigned ByteAlignment,
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/MC/MCSection.cpp
Expand Up @@ -22,8 +22,7 @@ using namespace llvm;

MCSection::MCSection(SectionVariant V, SectionKind K, MCSymbol *Begin)
: Begin(Begin), BundleGroupBeforeFirstInst(false), HasInstructions(false),
HasData(false), IsRegistered(false), DummyFragment(this), Variant(V),
Kind(K) {}
IsRegistered(false), DummyFragment(this), Variant(V), Kind(K) {}

MCSymbol *MCSection::getEndSymbol(MCContext &Ctx) {
if (!End)
Expand Down
7 changes: 5 additions & 2 deletions llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp
Expand Up @@ -255,8 +255,11 @@ void ARMELFObjectWriter::addTargetSectionFlags(MCContext &Ctx,
// execute-only section in the object.
MCSectionELF *TextSection =
static_cast<MCSectionELF *>(Ctx.getObjectFileInfo()->getTextSection());
if (Sec.getKind().isExecuteOnly() && !TextSection->hasInstructions() &&
!TextSection->hasData()) {
if (Sec.getKind().isExecuteOnly() && !TextSection->hasInstructions()) {
for (auto &F : TextSection->getFragmentList())
if (auto *DF = dyn_cast<MCDataFragment>(&F))
if (!DF->getContents().empty())
return;
TextSection->setFlags(TextSection->getFlags() | ELF::SHF_ARM_PURECODE);
}
}
Expand Down

0 comments on commit 5511861

Please sign in to comment.