Skip to content

Commit 5e1a5ff

Browse files
committed
[MC,ARM] Move SHF_ARM_PUECODE change for .text to ARMTargetELFStreamer::finish
and remove MCELFObjectWriter::addTargetSectionFlags.
1 parent f301887 commit 5e1a5ff

File tree

5 files changed

+20
-28
lines changed

5 files changed

+20
-28
lines changed

llvm/include/llvm/MC/MCELFObjectWriter.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,6 @@ class MCELFObjectTargetWriter : public MCObjectTargetWriter {
9999
virtual void sortRelocs(const MCAssembler &Asm,
100100
std::vector<ELFRelocationEntry> &Relocs);
101101

102-
virtual void addTargetSectionFlags(MCContext &Ctx, MCSectionELF &Sec);
103-
104102
/// \name Accessors
105103
/// @{
106104
uint8_t getOSABI() const { return OSABI; }

llvm/lib/MC/ELFObjectWriter.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,8 +1018,6 @@ uint64_t ELFWriter::writeObject(MCAssembler &Asm) {
10181018
if (RelSection)
10191019
Members.second.push_back(RelSection->getOrdinal());
10201020
}
1021-
1022-
OWriter.TargetObjectWriter->addTargetSectionFlags(Ctx, Section);
10231021
}
10241022

10251023
for (auto &[Group, Members] : Groups) {

llvm/lib/MC/MCELFObjectTargetWriter.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,3 @@ void
2727
MCELFObjectTargetWriter::sortRelocs(const MCAssembler &Asm,
2828
std::vector<ELFRelocationEntry> &Relocs) {
2929
}
30-
31-
void MCELFObjectTargetWriter::addTargetSectionFlags(MCContext &Ctx,
32-
MCSectionELF &Sec) {}

llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ namespace {
4141

4242
bool needsRelocateWithSymbol(const MCValue &Val, const MCSymbol &Sym,
4343
unsigned Type) const override;
44-
45-
void addTargetSectionFlags(MCContext &Ctx, MCSectionELF &Sec) override;
4644
};
4745

4846
} // end anonymous namespace
@@ -319,25 +317,6 @@ unsigned ARMELFObjectWriter::GetRelocTypeInner(const MCValue &Target,
319317
}
320318
}
321319

322-
void ARMELFObjectWriter::addTargetSectionFlags(MCContext &Ctx,
323-
MCSectionELF &Sec) {
324-
// The mix of execute-only and non-execute-only at link time is
325-
// non-execute-only. To avoid the empty implicitly created .text
326-
// section from making the whole .text section non-execute-only, we
327-
// mark it execute-only if it is empty and there is at least one
328-
// execute-only section in the object.
329-
MCSectionELF *TextSection =
330-
static_cast<MCSectionELF *>(Ctx.getObjectFileInfo()->getTextSection());
331-
bool IsExecOnly = Sec.getFlags() & ELF::SHF_ARM_PURECODE;
332-
if (IsExecOnly && !TextSection->hasInstructions()) {
333-
for (auto &F : *TextSection)
334-
if (auto *DF = dyn_cast<MCDataFragment>(&F))
335-
if (!DF->getContents().empty())
336-
return;
337-
TextSection->setFlags(TextSection->getFlags() | ELF::SHF_ARM_PURECODE);
338-
}
339-
}
340-
341320
std::unique_ptr<MCObjectTargetWriter>
342321
llvm::createARMELFObjectWriter(uint8_t OSABI) {
343322
return std::make_unique<ARMELFObjectWriter>(OSABI);

llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "llvm/MC/MCFragment.h"
3535
#include "llvm/MC/MCInst.h"
3636
#include "llvm/MC/MCInstPrinter.h"
37+
#include "llvm/MC/MCObjectFileInfo.h"
3738
#include "llvm/MC/MCObjectWriter.h"
3839
#include "llvm/MC/MCRegisterInfo.h"
3940
#include "llvm/MC/MCSection.h"
@@ -1113,6 +1114,25 @@ void ARMTargetELFStreamer::reset() { AttributeSection = nullptr; }
11131114
void ARMTargetELFStreamer::finish() {
11141115
ARMTargetStreamer::finish();
11151116
finishAttributeSection();
1117+
1118+
// The mix of execute-only and non-execute-only at link time is
1119+
// non-execute-only. To avoid the empty implicitly created .text
1120+
// section from making the whole .text section non-execute-only, we
1121+
// mark it execute-only if it is empty and there is at least one
1122+
// execute-only section in the object.
1123+
MCContext &Ctx = getStreamer().getContext();
1124+
auto &Asm = getStreamer().getAssembler();
1125+
if (any_of(Asm, [](const MCSection &Sec) {
1126+
return cast<MCSectionELF>(Sec).getFlags() & ELF::SHF_ARM_PURECODE;
1127+
})) {
1128+
auto *Text =
1129+
static_cast<MCSectionELF *>(Ctx.getObjectFileInfo()->getTextSection());
1130+
for (auto &F : *Text)
1131+
if (auto *DF = dyn_cast<MCDataFragment>(&F))
1132+
if (!DF->getContents().empty())
1133+
return;
1134+
Text->setFlags(Text->getFlags() | ELF::SHF_ARM_PURECODE);
1135+
}
11161136
}
11171137

11181138
void ARMELFStreamer::reset() {

0 commit comments

Comments
 (0)