Skip to content

Commit da135fa

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 4a21e3a commit da135fa

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed

clang/lib/CodeGen/CodeGenModule.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
#include "llvm/ADT/StringExtras.h"
5454
#include "llvm/ADT/StringSwitch.h"
5555
#include "llvm/Analysis/TargetLibraryInfo.h"
56+
#include "llvm/BinaryFormat/ELF.h"
5657
#include "llvm/Frontend/OpenMP/OMPIRBuilder.h"
5758
#include "llvm/IR/AttributeMask.h"
5859
#include "llvm/IR/CallingConv.h"
@@ -1161,6 +1162,25 @@ void CodeGenModule::Release() {
11611162
if (!LangOpts.isSignReturnAddressWithAKey())
11621163
getModule().addModuleFlag(llvm::Module::Min,
11631164
"sign-return-address-with-bkey", 1);
1165+
1166+
if (getTriple().isOSLinux() && getTriple().isOSBinFormatELF()) {
1167+
uint64_t PAuthABIVersion =
1168+
(LangOpts.PointerAuthIntrinsics << 0) |
1169+
(LangOpts.PointerAuthCalls << 1) |
1170+
(LangOpts.PointerAuthReturns << 2) |
1171+
(LangOpts.PointerAuthAuthTraps << 3) |
1172+
(LangOpts.PointerAuthVTPtrAddressDiscrimination << 4) |
1173+
(LangOpts.PointerAuthVTPtrTypeDiscrimination << 5) |
1174+
(LangOpts.PointerAuthInitFini << 6);
1175+
if (PAuthABIVersion != 0) {
1176+
getModule().addModuleFlag(llvm::Module::Error,
1177+
"aarch64-elf-pauthabi-platform",
1178+
llvm::ELF::AARCH64_PAUTH_PLATFORM_LLVM_LINUX);
1179+
getModule().addModuleFlag(llvm::Module::Error,
1180+
"aarch64-elf-pauthabi-version",
1181+
PAuthABIVersion);
1182+
}
1183+
}
11641184
}
11651185

11661186
if (CodeGenOpts.StackClashProtector)
+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// RUN: %clang -target aarch64-linux -S -emit-llvm -o - \
2+
// RUN: -fptrauth-intrinsics \
3+
// RUN: -fptrauth-calls \
4+
// RUN: -fptrauth-returns \
5+
// RUN: -fptrauth-auth-traps \
6+
// RUN: -fptrauth-vtable-pointer-address-discrimination \
7+
// RUN: -fptrauth-vtable-pointer-type-discrimination \
8+
// RUN: -fptrauth-init-fini %s | \
9+
// RUN: FileCheck %s --check-prefix=ALL
10+
11+
// RUN: %clang -target aarch64-linux -S -emit-llvm -o - \
12+
// RUN: -fptrauth-intrinsics %s | FileCheck %s --check-prefix=INTRIN
13+
14+
// RUN: %clang -target aarch64-linux -S -emit-llvm -o - \
15+
// RUN: -fptrauth-calls %s | FileCheck %s --check-prefix=CALL
16+
17+
// RUN: %clang -target aarch64-linux -S -emit-llvm -o - \
18+
// RUN: -fptrauth-returns %s | FileCheck %s --check-prefix=RET
19+
20+
// RUN: %clang -target aarch64-linux -S -emit-llvm -o - \
21+
// RUN: -fptrauth-auth-traps %s | FileCheck %s --check-prefix=TRAP
22+
23+
// RUN: %clang -target aarch64-linux -S -emit-llvm -o - \
24+
// RUN: -fptrauth-calls -fptrauth-vtable-pointer-address-discrimination %s | \
25+
// RUN: FileCheck %s --check-prefix=VPTRADDR
26+
27+
// RUN: %clang -target aarch64-linux -S -emit-llvm -o - \
28+
// RUN: -fptrauth-calls -fptrauth-vtable-pointer-type-discrimination %s | \
29+
// RUN: FileCheck %s --check-prefix=VPTRTYPE
30+
31+
// RUN: %clang -target aarch64-linux -S -emit-llvm -o - \
32+
// RUN: -fptrauth-calls -fptrauth-init-fini %s | \
33+
// RUN: FileCheck %s --check-prefix=INITFINI
34+
35+
// REQUIRES: aarch64-registered-target
36+
37+
// ALL: !{i32 1, !"aarch64-elf-pauthabi-platform", i32 268435458}
38+
// ALL: !{i32 1, !"aarch64-elf-pauthabi-version", i32 127}
39+
40+
// INTRIN: !{i32 1, !"aarch64-elf-pauthabi-platform", i32 268435458}
41+
// INTRIN: !{i32 1, !"aarch64-elf-pauthabi-version", i32 1}
42+
43+
// CALL: !{i32 1, !"aarch64-elf-pauthabi-platform", i32 268435458}
44+
// CALL: !{i32 1, !"aarch64-elf-pauthabi-version", i32 2}
45+
46+
// RET: !{i32 1, !"aarch64-elf-pauthabi-platform", i32 268435458}
47+
// RET: !{i32 1, !"aarch64-elf-pauthabi-version", i32 4}
48+
49+
// TRAP: !{i32 1, !"aarch64-elf-pauthabi-platform", i32 268435458}
50+
// TRAP: !{i32 1, !"aarch64-elf-pauthabi-version", i32 8}
51+
52+
// VPTRADDR: !{i32 1, !"aarch64-elf-pauthabi-platform", i32 268435458}
53+
// VPTRADDR: !{i32 1, !"aarch64-elf-pauthabi-version", i32 18}
54+
55+
// VPTRTYPE: !{i32 1, !"aarch64-elf-pauthabi-platform", i32 268435458}
56+
// VPTRTYPE: !{i32 1, !"aarch64-elf-pauthabi-version", i32 34}
57+
58+
// INITFINI: !{i32 1, !"aarch64-elf-pauthabi-platform", i32 268435458}
59+
// INITFINI: !{i32 1, !"aarch64-elf-pauthabi-version", i32 66}
60+
61+
void foo() {}

0 commit comments

Comments
 (0)