Skip to content

Commit e2e776c

Browse files
authored
[AArch64] Always add PURECODE flag to empty .text if "+execute-only" is set (#132196)
Previously, the `SHF_AARCH64_PURECODE` section flag wasn't added to the implicitly created `.text` section if the module didn't contain any functions, because no other section had the flag set. Now, the `SHF_AARCH64_PURECODE` is always added if the "+execute-only" target feature is set for the module during compilation.
1 parent 7d04867 commit e2e776c

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

llvm/lib/Target/AArch64/AArch64TargetObjectFile.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "llvm/IR/Module.h"
1717
#include "llvm/MC/MCContext.h"
1818
#include "llvm/MC/MCExpr.h"
19+
#include "llvm/MC/MCSectionELF.h"
1920
#include "llvm/MC/MCStreamer.h"
2021
#include "llvm/MC/MCValue.h"
2122
using namespace llvm;
@@ -27,6 +28,14 @@ void AArch64_ELFTargetObjectFile::Initialize(MCContext &Ctx,
2728
// AARCH64 ELF ABI does not define static relocation type for TLS offset
2829
// within a module. Do not generate AT_location for TLS variables.
2930
SupportDebugThreadLocalLocation = false;
31+
32+
// Make sure the implicitly created empty .text section has the
33+
// SHF_AARCH64_PURECODE flag set if the "+execute-only" target feature is
34+
// present.
35+
if (TM.getMCSubtargetInfo()->hasFeature(AArch64::FeatureExecuteOnly)) {
36+
auto *Text = cast<MCSectionELF>(TextSection);
37+
Text->setFlags(Text->getFlags() | ELF::SHF_AARCH64_PURECODE);
38+
}
3039
}
3140

3241
void AArch64_ELFTargetObjectFile::emitPersonalityValueImpl(
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
; RUN: llc -filetype=obj -mtriple=aarch64 -mattr=+execute-only %s -o %t.o
2+
; RUN: llvm-readobj -S %t.o | FileCheck %s
3+
4+
; CHECK: Name: .text
5+
; CHECK-NEXT: Type: SHT_PROGBITS
6+
; CHECK-NEXT: Flags [
7+
; CHECK-NEXT: SHF_AARCH64_PURECODE
8+
; CHECK-NEXT: SHF_ALLOC
9+
; CHECK-NEXT: SHF_EXECINSTR
10+
; CHECK-NEXT: ]
11+
; CHECK-NEXT: Address:
12+
; CHECK-NEXT: Offset:
13+
; CHECK-NEXT: Size: 0

0 commit comments

Comments
 (0)