[PATCH] D48793: [AArch64] Set execute-only flags in .text.
Ivan Lozano via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 29 15:02:08 PDT 2018
ivanlozano created this revision.
ivanlozano added reviewers: srhines, echristo, eugenis, peter.smith.
Herald added a reviewer: javed.absar.
Herald added subscribers: llvm-commits, kristof.beyls.
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.
Repository:
rL LLVM
https://reviews.llvm.org/D48793
Files:
lib/Target/AArch64/AArch64TargetObjectFile.cpp
test/MC/AArch64/elf-execute-only-section.ll
Index: test/MC/AArch64/elf-execute-only-section.ll
===================================================================
--- /dev/null
+++ test/MC/AArch64/elf-execute-only-section.ll
@@ -0,0 +1,9 @@
+; RUN: llc < %s -mtriple=aarch64 -mattr=+execute-only -filetype=obj %s -o - |\
+; RUN: llvm-readelf -s | FileCheck %s
+
+; CHECK-NOT: {{.text[ ]+PROGBITS[ ]+[0-9]+ [0-9]+ [0-9]+ [0-9]+ AX[^p]}}
+; CHECK: {{.text[ ]+PROGBITS[ ]+[0-9]+ [0-9]+ [0-9]+ [0-9]+ AXp}}
+define void @test_func() {
+entry:
+ ret void
+}
Index: lib/Target/AArch64/AArch64TargetObjectFile.cpp
===================================================================
--- lib/Target/AArch64/AArch64TargetObjectFile.cpp
+++ lib/Target/AArch64/AArch64TargetObjectFile.cpp
@@ -10,6 +10,7 @@
#include "AArch64TargetObjectFile.h"
#include "AArch64TargetMachine.h"
#include "llvm/BinaryFormat/Dwarf.h"
+#include "llvm/BinaryFormat/ELF.h"
#include "llvm/IR/Mangler.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCExpr.h"
@@ -23,6 +24,18 @@
const TargetMachine &TM) {
TargetLoweringObjectFileELF::Initialize(Ctx, TM);
InitializeELF(TM.Options.UseInitArray);
+
+ bool genExecuteOnly = TM.getMCSubtargetInfo()->hasFeature(AArch64::FeatureExecuteOnly);
+
+ // 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);
+ }
}
AArch64_MachoTargetObjectFile::AArch64_MachoTargetObjectFile()
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D48793.153588.patch
Type: text/x-patch
Size: 1801 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180629/e651dde6/attachment.bin>
More information about the llvm-commits
mailing list