aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CodeGenModule.cpp
diff options
context:
space:
mode:
authorDaniil Kovalev <dkovalev@accesssoftek.com>2024-05-09 15:32:18 +0300
committerGitHub <noreply@github.com>2024-05-09 15:32:18 +0300
commitad652efa1f65e16f5380acfba1bb132145984805 (patch)
tree257466ea18b08f973dd74fa9c73ba95c95539a25 /clang/lib/CodeGen/CodeGenModule.cpp
parentc2a87d7e032f8e6c8cbe6ab4c7cfbb7f7996ca9f (diff)
downloadllvm-ad652efa1f65e16f5380acfba1bb132145984805.zip
llvm-ad652efa1f65e16f5380acfba1bb132145984805.tar.gz
llvm-ad652efa1f65e16f5380acfba1bb132145984805.tar.bz2
[AArch64][PAC][clang][ELF] Support PAuth ABI core info (#85235)
Depends on #87545 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`. --------- Co-authored-by: Ahmed Bougacha <ahmed@bougacha.org>
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r--clang/lib/CodeGen/CodeGenModule.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index c8898ce..489c08a 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"
@@ -1190,6 +1191,37 @@ void CodeGenModule::Release() {
if (!LangOpts.isSignReturnAddressWithAKey())
getModule().addModuleFlag(llvm::Module::Min,
"sign-return-address-with-bkey", 1);
+
+ if (getTriple().isOSLinux()) {
+ assert(getTriple().isOSBinFormatELF());
+ using namespace llvm::ELF;
+ uint64_t PAuthABIVersion =
+ (LangOpts.PointerAuthIntrinsics
+ << AARCH64_PAUTH_PLATFORM_LLVM_LINUX_VERSION_INTRINSICS) |
+ (LangOpts.PointerAuthCalls
+ << AARCH64_PAUTH_PLATFORM_LLVM_LINUX_VERSION_CALLS) |
+ (LangOpts.PointerAuthReturns
+ << AARCH64_PAUTH_PLATFORM_LLVM_LINUX_VERSION_RETURNS) |
+ (LangOpts.PointerAuthAuthTraps
+ << AARCH64_PAUTH_PLATFORM_LLVM_LINUX_VERSION_AUTHTRAPS) |
+ (LangOpts.PointerAuthVTPtrAddressDiscrimination
+ << AARCH64_PAUTH_PLATFORM_LLVM_LINUX_VERSION_VPTRADDRDISCR) |
+ (LangOpts.PointerAuthVTPtrTypeDiscrimination
+ << AARCH64_PAUTH_PLATFORM_LLVM_LINUX_VERSION_VPTRTYPEDISCR) |
+ (LangOpts.PointerAuthInitFini
+ << AARCH64_PAUTH_PLATFORM_LLVM_LINUX_VERSION_INITFINI);
+ static_assert(AARCH64_PAUTH_PLATFORM_LLVM_LINUX_VERSION_INITFINI ==
+ AARCH64_PAUTH_PLATFORM_LLVM_LINUX_VERSION_LAST,
+ "Update when new enum items are defined");
+ if (PAuthABIVersion != 0) {
+ getModule().addModuleFlag(llvm::Module::Error,
+ "aarch64-elf-pauthabi-platform",
+ AARCH64_PAUTH_PLATFORM_LLVM_LINUX);
+ getModule().addModuleFlag(llvm::Module::Error,
+ "aarch64-elf-pauthabi-version",
+ PAuthABIVersion);
+ }
+ }
}
if (CodeGenOpts.StackClashProtector)