pac_helper: test for __has_feature macro

__has_feature is a clang extension. GCC errors out on the test.
Define a helper macro to make the code working with other compilers.

Bug: chromium:819294
Change-Id: I359150acd4700e65b4faf5f297b29664c18000d3
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4418706
Reviewed-by: Joshua Peraza <jperaza@chromium.org>
Commit-Queue: Joshua Peraza <jperaza@chromium.org>
Reviewed-by: Ben Hamilton <benhamilton@google.com>
This commit is contained in:
Stephan Hartmann 2023-04-12 17:39:38 +02:00 committed by Crashpad LUCI CQ
parent ada8dfa4a7
commit 0e3758bef6

View File

@ -14,8 +14,14 @@
#include "util/linux/pac_helper.h"
#if __has_feature(ptrauth_intrinsics)
#include <ptrauth.h>
#if defined(__has_feature)
#define CRASHPAD_HAS_FEATURE(x) __has_feature(x)
#else
#define CRASHPAD_HAS_FEATURE(x) 0
#endif
#if CRASHPAD_HAS_FEATURE(ptrauth_intrinsics)
#include <ptrauth.h>
#endif
#include "util/misc/address_types.h"
@ -23,7 +29,7 @@
namespace crashpad {
VMAddress StripPACBits(VMAddress address) {
#if __has_feature(ptrauth_intrinsics)
#if CRASHPAD_HAS_FEATURE(ptrauth_intrinsics)
address = ptrauth_strip(address, ptrauth_key_function_pointer);
#elif defined(ARCH_CPU_ARM64)
// Strip any pointer authentication bits that are assigned to the address.