Skip to content

[AArch64] Always add PURECODE flag to empty .text if "+execute-only" is set #132196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions llvm/lib/Target/AArch64/AArch64TargetObjectFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "llvm/IR/Module.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCExpr.h"
#include "llvm/MC/MCSectionELF.h"
#include "llvm/MC/MCStreamer.h"
#include "llvm/MC/MCValue.h"
using namespace llvm;
Expand All @@ -27,6 +28,14 @@ void AArch64_ELFTargetObjectFile::Initialize(MCContext &Ctx,
// AARCH64 ELF ABI does not define static relocation type for TLS offset
// within a module. Do not generate AT_location for TLS variables.
SupportDebugThreadLocalLocation = false;

// Make sure the implicitly created empty .text section has the
// SHF_AARCH64_PURECODE flag set if the "+execute-only" target feature is
// present.
if (TM.getMCSubtargetInfo()->hasFeature(AArch64::FeatureExecuteOnly)) {
auto *Text = cast<MCSectionELF>(TextSection);
Text->setFlags(Text->getFlags() | ELF::SHF_AARCH64_PURECODE);
}
}

void AArch64_ELFTargetObjectFile::emitPersonalityValueImpl(
Expand Down
13 changes: 13 additions & 0 deletions llvm/test/CodeGen/AArch64/execute-only-empty.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
; RUN: llc -filetype=obj -mtriple=aarch64 -mattr=+execute-only %s -o %t.o
; RUN: llvm-readobj -S %t.o | FileCheck %s

; CHECK: Name: .text
; CHECK-NEXT: Type: SHT_PROGBITS
; CHECK-NEXT: Flags [
; CHECK-NEXT: SHF_AARCH64_PURECODE
; CHECK-NEXT: SHF_ALLOC
; CHECK-NEXT: SHF_EXECINSTR
; CHECK-NEXT: ]
; CHECK-NEXT: Address:
; CHECK-NEXT: Offset:
; CHECK-NEXT: Size: 0