diff options
author | Eric Christopher <echristo@gmail.com> | 2018-09-06 22:09:31 +0000 |
---|---|---|
committer | Eric Christopher <echristo@gmail.com> | 2018-09-06 22:09:31 +0000 |
commit | fe83270ee9ad66548326625a170ac062079556d0 (patch) | |
tree | b600d892a0905f2039d7a59dd3fdb93639664f11 /llvm/lib/Target/ARM/ARMTargetObjectFile.cpp | |
parent | 950a1a393675c806e24f803a33e6ece7652c4160 (diff) | |
download | llvm-fe83270ee9ad66548326625a170ac062079556d0.zip llvm-fe83270ee9ad66548326625a170ac062079556d0.tar.gz llvm-fe83270ee9ad66548326625a170ac062079556d0.tar.bz2 |
The initial .text section generated in object files was missing the
SHF_ARM_PURECODE flag when being built with the -mexecute-only flag.
All code sections of an ELF must have the flag set for the final .text
section to be execute-only, otherwise the flag gets removed.
A HasData flag is added to MCSection to aid in the determination that
the section is empty. A virtual setTargetSectionFlags is added to
MCELFObjectTargetWriter to allow subclasses to set target specific
section flags to be added to sections which we then use in the ARM
backend to set SHF_ARM_PURECODE.
Patch by Ivan Lozano!
Reviewed By: echristo
Differential Revision: https://reviews.llvm.org/D48792
llvm-svn: 341593
Diffstat (limited to 'llvm/lib/Target/ARM/ARMTargetObjectFile.cpp')
-rw-r--r-- | llvm/lib/Target/ARM/ARMTargetObjectFile.cpp | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/llvm/lib/Target/ARM/ARMTargetObjectFile.cpp b/llvm/lib/Target/ARM/ARMTargetObjectFile.cpp index d062076..9c13359 100644 --- a/llvm/lib/Target/ARM/ARMTargetObjectFile.cpp +++ b/llvm/lib/Target/ARM/ARMTargetObjectFile.cpp @@ -32,7 +32,8 @@ void ARMElfTargetObjectFile::Initialize(MCContext &Ctx, const TargetMachine &TM) { const ARMBaseTargetMachine &ARM_TM = static_cast<const ARMBaseTargetMachine &>(TM); bool isAAPCS_ABI = ARM_TM.TargetABI == ARMBaseTargetMachine::ARMABI::ARM_ABI_AAPCS; - // genExecuteOnly = ARM_TM.getSubtargetImpl()->genExecuteOnly(); + bool genExecuteOnly = + ARM_TM.getMCSubtargetInfo()->hasFeature(ARM::FeatureExecuteOnly); TargetLoweringObjectFileELF::Initialize(Ctx, TM); InitializeELF(isAAPCS_ABI); @@ -40,6 +41,17 @@ void ARMElfTargetObjectFile::Initialize(MCContext &Ctx, if (isAAPCS_ABI) { LSDASection = nullptr; } + + // Make code section unreadable when in execute-only mode + if (genExecuteOnly) { + unsigned Type = ELF::SHT_PROGBITS; + unsigned Flags = + ELF::SHF_EXECINSTR | ELF::SHF_ALLOC | ELF::SHF_ARM_PURECODE; + // Since we cannot modify flags for an existing section, we create a new + // section with the right flags, and use 0 as the unique ID for + // execute-only text + TextSection = Ctx.getELFSection(".text", Type, Flags, 0, "", 0U); + } } const MCExpr *ARMElfTargetObjectFile::getTTypeGlobalReference( |