Skip to content

Commit a0cc186

Browse files
committed
[AArch64][PAC][clang][ELF] Support PAuth ABI compatibility tag
Emit PAuth ABI compatibility tag values as llvm module flags: - `aarch64-elf-pauthabi-platform` - `aarch64-elf-pauthabi-version`
1 parent c8d71df commit a0cc186

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#include "llvm/ADT/StringExtras.h"
5252
#include "llvm/ADT/StringSwitch.h"
5353
#include "llvm/Analysis/TargetLibraryInfo.h"
54+
#include "llvm/BinaryFormat/ELF.h"
5455
#include "llvm/Frontend/OpenMP/OMPIRBuilder.h"
5556
#include "llvm/IR/AttributeMask.h"
5657
#include "llvm/IR/CallingConv.h"
@@ -1075,6 +1076,23 @@ void CodeGenModule::Release() {
10751076
if (!LangOpts.isSignReturnAddressWithAKey())
10761077
getModule().addModuleFlag(llvm::Module::Min,
10771078
"sign-return-address-with-bkey", 1);
1079+
1080+
if (getTriple().isOSLinux() && getTriple().isOSBinFormatELF()) {
1081+
uint64_t PAuthABIVersion =
1082+
(LangOpts.PointerAuthCalls << 0) |
1083+
(LangOpts.PointerAuthReturns << 1) |
1084+
(LangOpts.PointerAuthVTPtrAddressDiscrimination << 2) |
1085+
(LangOpts.PointerAuthVTPtrTypeDiscrimination << 3) |
1086+
(LangOpts.PointerAuthInitFini << 4);
1087+
if (PAuthABIVersion != 0) {
1088+
getModule().addModuleFlag(
1089+
llvm::Module::Error, "aarch64-elf-pauthabi-platform",
1090+
llvm::ELF::GNU_PROPERTY_AARCH64_FEATURE_PAUTH_PLATFORM_LINUX);
1091+
getModule().addModuleFlag(llvm::Module::Error,
1092+
"aarch64-elf-pauthabi-version",
1093+
PAuthABIVersion);
1094+
}
1095+
}
10781096
}
10791097

10801098
if (!CodeGenOpts.MemoryProfileOutput.empty()) {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// RUN: %clang -target aarch64-linux -S -emit-llvm -o - -mbranch-protection=pauthabi %s | FileCheck %s --check-prefix=ALL
2+
// RUN: %clang -target aarch64-linux -S -emit-llvm -o - -fptrauth-returns %s | FileCheck %s --check-prefix=RET
3+
// RUN: %clang -target aarch64-linux -S -emit-llvm -o - -fptrauth-calls %s | FileCheck %s --check-prefix=CALL
4+
// RUN: %clang -target aarch64-linux -S -emit-llvm -o - -fptrauth-calls -fptrauth-vtable-pointer-address-discrimination %s | FileCheck %s --check-prefix=VPTRADDR
5+
// RUN: %clang -target aarch64-linux -S -emit-llvm -o - -fptrauth-calls -fptrauth-vtable-pointer-type-discrimination %s | FileCheck %s --check-prefix=VPTRTYPE
6+
// RUN: %clang -target aarch64-linux -S -emit-llvm -o - -fptrauth-calls -fptrauth-init-fini %s | FileCheck %s --check-prefix=INITFINI
7+
8+
// REQUIRES: aarch64-registered-target
9+
10+
// ALL: !{i32 1, !"aarch64-elf-pauthabi-platform", i32 2}
11+
// ALL: !{i32 1, !"aarch64-elf-pauthabi-version", i32 31}
12+
13+
// RET: !{i32 1, !"aarch64-elf-pauthabi-platform", i32 2}
14+
// RET: !{i32 1, !"aarch64-elf-pauthabi-version", i32 2}
15+
16+
// CALL: !{i32 1, !"aarch64-elf-pauthabi-platform", i32 2}
17+
// CALL: !{i32 1, !"aarch64-elf-pauthabi-version", i32 1}
18+
19+
// VPTRADDR: !{i32 1, !"aarch64-elf-pauthabi-platform", i32 2}
20+
// VPTRADDR: !{i32 1, !"aarch64-elf-pauthabi-version", i32 5}
21+
22+
// VPTRTYPE: !{i32 1, !"aarch64-elf-pauthabi-platform", i32 2}
23+
// VPTRTYPE: !{i32 1, !"aarch64-elf-pauthabi-version", i32 9}
24+
25+
// INITFINI: !{i32 1, !"aarch64-elf-pauthabi-platform", i32 2}
26+
// INITFINI: !{i32 1, !"aarch64-elf-pauthabi-version", i32 17}
27+
28+
void foo() {}

0 commit comments

Comments
 (0)