Skip to content

Commit e27b738

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 d998702 commit e27b738

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,6 +1075,22 @@ void CodeGenModule::Release() {
10751075
if (!LangOpts.isSignReturnAddressWithAKey())
10761076
getModule().addModuleFlag(llvm::Module::Min,
10771077
"sign-return-address-with-bkey", 1);
1078+
1079+
if (getTriple().isOSBinFormatELF()) {
1080+
uint64_t PAuthABIVersion =
1081+
(LangOpts.PointerAuthCalls << 0) |
1082+
(LangOpts.PointerAuthReturns << 1) |
1083+
(LangOpts.PointerAuthVTPtrAddressDiscrimination << 2) |
1084+
(LangOpts.PointerAuthVTPtrTypeDiscrimination << 3) |
1085+
(LangOpts.PointerAuthInitFini << 4);
1086+
if (PAuthABIVersion != 0) {
1087+
getModule().addModuleFlag(llvm::Module::Error,
1088+
"aarch64-elf-pauthabi-platform", 2);
1089+
getModule().addModuleFlag(llvm::Module::Error,
1090+
"aarch64-elf-pauthabi-version",
1091+
PAuthABIVersion);
1092+
}
1093+
}
10781094
}
10791095

10801096
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-none-elf -S -emit-llvm -o - -mbranch-protection=pauthabi %s | FileCheck %s --check-prefix=ALL
2+
// RUN: %clang -target aarch64-none-elf -S -emit-llvm -o - -fptrauth-returns %s | FileCheck %s --check-prefix=RET
3+
// RUN: %clang -target aarch64-none-elf -S -emit-llvm -o - -fptrauth-calls %s | FileCheck %s --check-prefix=CALL
4+
// RUN: %clang -target aarch64-none-elf -S -emit-llvm -o - -fptrauth-calls -fptrauth-vtable-pointer-address-discrimination %s | FileCheck %s --check-prefix=VPTRADDR
5+
// RUN: %clang -target aarch64-none-elf -S -emit-llvm -o - -fptrauth-calls -fptrauth-vtable-pointer-type-discrimination %s | FileCheck %s --check-prefix=VPTRTYPE
6+
// RUN: %clang -target aarch64-none-elf -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)