https://github.com/kovdan01 created https://github.com/llvm/llvm-project/pull/85235
Depends on #85231 and #85232 Emit PAuth ABI compatibility tag values as llvm module flags: - `aarch64-elf-pauthabi-platform` - `aarch64-elf-pauthabi-version` For platform 0x10000002 (llvm_linux), the version value bits correspond to the following LangOptions defined in #85232: - bit 0: `PointerAuthIntrinsics`; - bit 1: `PointerAuthCalls`; - bit 2: `PointerAuthReturns`; - bit 3: `PointerAuthAuthTraps`; - bit 4: `PointerAuthVTPtrAddressDiscrimination`; - bit 5: `PointerAuthVTPtrTypeDiscrimination`; - bit 6: `PointerAuthInitFini`. >From da135fa4ce8fb560b043cb3d5931528539d4e1ea Mon Sep 17 00:00:00 2001 From: Daniil Kovalev <dkova...@accesssoftek.com> Date: Wed, 13 Mar 2024 23:02:04 +0300 Subject: [PATCH] [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` --- clang/lib/CodeGen/CodeGenModule.cpp | 20 ++++++++ clang/test/CodeGen/aarch64-elf-pauthabi.c | 61 +++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 clang/test/CodeGen/aarch64-elf-pauthabi.c diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 967319bdfc4571..a98dee86876abd 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -53,6 +53,7 @@ #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/Analysis/TargetLibraryInfo.h" +#include "llvm/BinaryFormat/ELF.h" #include "llvm/Frontend/OpenMP/OMPIRBuilder.h" #include "llvm/IR/AttributeMask.h" #include "llvm/IR/CallingConv.h" @@ -1161,6 +1162,25 @@ void CodeGenModule::Release() { if (!LangOpts.isSignReturnAddressWithAKey()) getModule().addModuleFlag(llvm::Module::Min, "sign-return-address-with-bkey", 1); + + if (getTriple().isOSLinux() && getTriple().isOSBinFormatELF()) { + uint64_t PAuthABIVersion = + (LangOpts.PointerAuthIntrinsics << 0) | + (LangOpts.PointerAuthCalls << 1) | + (LangOpts.PointerAuthReturns << 2) | + (LangOpts.PointerAuthAuthTraps << 3) | + (LangOpts.PointerAuthVTPtrAddressDiscrimination << 4) | + (LangOpts.PointerAuthVTPtrTypeDiscrimination << 5) | + (LangOpts.PointerAuthInitFini << 6); + if (PAuthABIVersion != 0) { + getModule().addModuleFlag(llvm::Module::Error, + "aarch64-elf-pauthabi-platform", + llvm::ELF::AARCH64_PAUTH_PLATFORM_LLVM_LINUX); + getModule().addModuleFlag(llvm::Module::Error, + "aarch64-elf-pauthabi-version", + PAuthABIVersion); + } + } } if (CodeGenOpts.StackClashProtector) diff --git a/clang/test/CodeGen/aarch64-elf-pauthabi.c b/clang/test/CodeGen/aarch64-elf-pauthabi.c new file mode 100644 index 00000000000000..8f3e2d9b274b5a --- /dev/null +++ b/clang/test/CodeGen/aarch64-elf-pauthabi.c @@ -0,0 +1,61 @@ +// RUN: %clang -target aarch64-linux -S -emit-llvm -o - \ +// RUN: -fptrauth-intrinsics \ +// RUN: -fptrauth-calls \ +// RUN: -fptrauth-returns \ +// RUN: -fptrauth-auth-traps \ +// RUN: -fptrauth-vtable-pointer-address-discrimination \ +// RUN: -fptrauth-vtable-pointer-type-discrimination \ +// RUN: -fptrauth-init-fini %s | \ +// RUN: FileCheck %s --check-prefix=ALL + +// RUN: %clang -target aarch64-linux -S -emit-llvm -o - \ +// RUN: -fptrauth-intrinsics %s | FileCheck %s --check-prefix=INTRIN + +// RUN: %clang -target aarch64-linux -S -emit-llvm -o - \ +// RUN: -fptrauth-calls %s | FileCheck %s --check-prefix=CALL + +// RUN: %clang -target aarch64-linux -S -emit-llvm -o - \ +// RUN: -fptrauth-returns %s | FileCheck %s --check-prefix=RET + +// RUN: %clang -target aarch64-linux -S -emit-llvm -o - \ +// RUN: -fptrauth-auth-traps %s | FileCheck %s --check-prefix=TRAP + +// RUN: %clang -target aarch64-linux -S -emit-llvm -o - \ +// RUN: -fptrauth-calls -fptrauth-vtable-pointer-address-discrimination %s | \ +// RUN: FileCheck %s --check-prefix=VPTRADDR + +// RUN: %clang -target aarch64-linux -S -emit-llvm -o - \ +// RUN: -fptrauth-calls -fptrauth-vtable-pointer-type-discrimination %s | \ +// RUN: FileCheck %s --check-prefix=VPTRTYPE + +// RUN: %clang -target aarch64-linux -S -emit-llvm -o - \ +// RUN: -fptrauth-calls -fptrauth-init-fini %s | \ +// RUN: FileCheck %s --check-prefix=INITFINI + +// REQUIRES: aarch64-registered-target + +// ALL: !{i32 1, !"aarch64-elf-pauthabi-platform", i32 268435458} +// ALL: !{i32 1, !"aarch64-elf-pauthabi-version", i32 127} + +// INTRIN: !{i32 1, !"aarch64-elf-pauthabi-platform", i32 268435458} +// INTRIN: !{i32 1, !"aarch64-elf-pauthabi-version", i32 1} + +// CALL: !{i32 1, !"aarch64-elf-pauthabi-platform", i32 268435458} +// CALL: !{i32 1, !"aarch64-elf-pauthabi-version", i32 2} + +// RET: !{i32 1, !"aarch64-elf-pauthabi-platform", i32 268435458} +// RET: !{i32 1, !"aarch64-elf-pauthabi-version", i32 4} + +// TRAP: !{i32 1, !"aarch64-elf-pauthabi-platform", i32 268435458} +// TRAP: !{i32 1, !"aarch64-elf-pauthabi-version", i32 8} + +// VPTRADDR: !{i32 1, !"aarch64-elf-pauthabi-platform", i32 268435458} +// VPTRADDR: !{i32 1, !"aarch64-elf-pauthabi-version", i32 18} + +// VPTRTYPE: !{i32 1, !"aarch64-elf-pauthabi-platform", i32 268435458} +// VPTRTYPE: !{i32 1, !"aarch64-elf-pauthabi-version", i32 34} + +// INITFINI: !{i32 1, !"aarch64-elf-pauthabi-platform", i32 268435458} +// INITFINI: !{i32 1, !"aarch64-elf-pauthabi-version", i32 66} + +void foo() {} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits