[llvm] 5e1a5ff - [MC,ARM] Move SHF_ARM_PUECODE change for .text to ARMTargetELFStreamer::finish
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 5 18:08:44 PDT 2024
Author: Fangrui Song
Date: 2024-08-05T18:08:39-07:00
New Revision: 5e1a5ffc2a464bc472ad92852e90de2f75c90eed
URL: https://github.com/llvm/llvm-project/commit/5e1a5ffc2a464bc472ad92852e90de2f75c90eed
DIFF: https://github.com/llvm/llvm-project/commit/5e1a5ffc2a464bc472ad92852e90de2f75c90eed.diff
LOG: [MC,ARM] Move SHF_ARM_PUECODE change for .text to ARMTargetELFStreamer::finish
and remove MCELFObjectWriter::addTargetSectionFlags.
Added:
Modified:
llvm/include/llvm/MC/MCELFObjectWriter.h
llvm/lib/MC/ELFObjectWriter.cpp
llvm/lib/MC/MCELFObjectTargetWriter.cpp
llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp
llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/MC/MCELFObjectWriter.h b/llvm/include/llvm/MC/MCELFObjectWriter.h
index 4952e0383b211..3b418083eecce 100644
--- a/llvm/include/llvm/MC/MCELFObjectWriter.h
+++ b/llvm/include/llvm/MC/MCELFObjectWriter.h
@@ -99,8 +99,6 @@ class MCELFObjectTargetWriter : public MCObjectTargetWriter {
virtual void sortRelocs(const MCAssembler &Asm,
std::vector<ELFRelocationEntry> &Relocs);
- virtual void addTargetSectionFlags(MCContext &Ctx, MCSectionELF &Sec);
-
/// \name Accessors
/// @{
uint8_t getOSABI() const { return OSABI; }
diff --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp
index f958905a26aa4..c40a074137ab2 100644
--- a/llvm/lib/MC/ELFObjectWriter.cpp
+++ b/llvm/lib/MC/ELFObjectWriter.cpp
@@ -1018,8 +1018,6 @@ uint64_t ELFWriter::writeObject(MCAssembler &Asm) {
if (RelSection)
Members.second.push_back(RelSection->getOrdinal());
}
-
- OWriter.TargetObjectWriter->addTargetSectionFlags(Ctx, Section);
}
for (auto &[Group, Members] : Groups) {
diff --git a/llvm/lib/MC/MCELFObjectTargetWriter.cpp b/llvm/lib/MC/MCELFObjectTargetWriter.cpp
index c35e1f26dc1ef..49cca57d3aaa3 100644
--- a/llvm/lib/MC/MCELFObjectTargetWriter.cpp
+++ b/llvm/lib/MC/MCELFObjectTargetWriter.cpp
@@ -27,6 +27,3 @@ void
MCELFObjectTargetWriter::sortRelocs(const MCAssembler &Asm,
std::vector<ELFRelocationEntry> &Relocs) {
}
-
-void MCELFObjectTargetWriter::addTargetSectionFlags(MCContext &Ctx,
- MCSectionELF &Sec) {}
diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp
index 50a59ce767630..ddc62b5345981 100644
--- a/llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp
+++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp
@@ -41,8 +41,6 @@ namespace {
bool needsRelocateWithSymbol(const MCValue &Val, const MCSymbol &Sym,
unsigned Type) const override;
-
- void addTargetSectionFlags(MCContext &Ctx, MCSectionELF &Sec) override;
};
} // end anonymous namespace
@@ -319,25 +317,6 @@ unsigned ARMELFObjectWriter::GetRelocTypeInner(const MCValue &Target,
}
}
-void ARMELFObjectWriter::addTargetSectionFlags(MCContext &Ctx,
- MCSectionELF &Sec) {
- // The mix of execute-only and non-execute-only at link time is
- // non-execute-only. To avoid the empty implicitly created .text
- // section from making the whole .text section non-execute-only, we
- // mark it execute-only if it is empty and there is at least one
- // execute-only section in the object.
- MCSectionELF *TextSection =
- static_cast<MCSectionELF *>(Ctx.getObjectFileInfo()->getTextSection());
- bool IsExecOnly = Sec.getFlags() & ELF::SHF_ARM_PURECODE;
- if (IsExecOnly && !TextSection->hasInstructions()) {
- for (auto &F : *TextSection)
- if (auto *DF = dyn_cast<MCDataFragment>(&F))
- if (!DF->getContents().empty())
- return;
- TextSection->setFlags(TextSection->getFlags() | ELF::SHF_ARM_PURECODE);
- }
-}
-
std::unique_ptr<MCObjectTargetWriter>
llvm::createARMELFObjectWriter(uint8_t OSABI) {
return std::make_unique<ARMELFObjectWriter>(OSABI);
diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp
index 9df752f8eb680..59f29660a7777 100644
--- a/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp
+++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp
@@ -34,6 +34,7 @@
#include "llvm/MC/MCFragment.h"
#include "llvm/MC/MCInst.h"
#include "llvm/MC/MCInstPrinter.h"
+#include "llvm/MC/MCObjectFileInfo.h"
#include "llvm/MC/MCObjectWriter.h"
#include "llvm/MC/MCRegisterInfo.h"
#include "llvm/MC/MCSection.h"
@@ -1113,6 +1114,25 @@ void ARMTargetELFStreamer::reset() { AttributeSection = nullptr; }
void ARMTargetELFStreamer::finish() {
ARMTargetStreamer::finish();
finishAttributeSection();
+
+ // The mix of execute-only and non-execute-only at link time is
+ // non-execute-only. To avoid the empty implicitly created .text
+ // section from making the whole .text section non-execute-only, we
+ // mark it execute-only if it is empty and there is at least one
+ // execute-only section in the object.
+ MCContext &Ctx = getStreamer().getContext();
+ auto &Asm = getStreamer().getAssembler();
+ if (any_of(Asm, [](const MCSection &Sec) {
+ return cast<MCSectionELF>(Sec).getFlags() & ELF::SHF_ARM_PURECODE;
+ })) {
+ auto *Text =
+ static_cast<MCSectionELF *>(Ctx.getObjectFileInfo()->getTextSection());
+ for (auto &F : *Text)
+ if (auto *DF = dyn_cast<MCDataFragment>(&F))
+ if (!DF->getContents().empty())
+ return;
+ Text->setFlags(Text->getFlags() | ELF::SHF_ARM_PURECODE);
+ }
}
void ARMELFStreamer::reset() {
More information about the llvm-commits
mailing list