[llvm] 5511861 - [MC][ARM] Delete MCSection::HasData and move SHF_ARM_PURECODE logic to ARMELFObjectWriter::addTargetSectionFlags
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sun Jan 5 14:20:41 PST 2020
Author: Fangrui Song
Date: 2020-01-05T14:20:34-08:00
New Revision: 5511861e6dc81e702587bb4d07deba35571db293
URL: https://github.com/llvm/llvm-project/commit/5511861e6dc81e702587bb4d07deba35571db293
DIFF: https://github.com/llvm/llvm-project/commit/5511861e6dc81e702587bb4d07deba35571db293.diff
LOG: [MC][ARM] Delete MCSection::HasData and move SHF_ARM_PURECODE logic to 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.
Added:
Modified:
llvm/include/llvm/MC/MCSection.h
llvm/lib/MC/MCObjectStreamer.cpp
llvm/lib/MC/MCSection.cpp
llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/MC/MCSection.h b/llvm/include/llvm/MC/MCSection.h
index d66e42b656b1..d80cc5b086b3 100644
--- a/llvm/include/llvm/MC/MCSection.h
+++ b/llvm/include/llvm/MC/MCSection.h
@@ -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;
@@ -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; }
diff --git a/llvm/lib/MC/MCObjectStreamer.cpp b/llvm/lib/MC/MCObjectStreamer.cpp
index 5c42667f9910..d8a7ab043eb8 100644
--- a/llvm/lib/MC/MCObjectStreamer.cpp
+++ b/llvm/lib/MC/MCObjectStreamer.cpp
@@ -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,
diff --git a/llvm/lib/MC/MCSection.cpp b/llvm/lib/MC/MCSection.cpp
index 7a953054e729..074534bd73db 100644
--- a/llvm/lib/MC/MCSection.cpp
+++ b/llvm/lib/MC/MCSection.cpp
@@ -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)
diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp
index 1fee38821a49..2c26dd388c05 100644
--- a/llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp
+++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp
@@ -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);
}
}
More information about the llvm-commits
mailing list