@@ -374,6 +374,44 @@ if(SNMALLOC_COMPILER_SUPPORT_MCX16)
374374 target_compile_options (snmalloc INTERFACE $<$<COMPILE_LANGUAGE :CXX >:-mcx16 >)
375375endif ()
376376
377+ check_cxx_compiler_flag (
378+ "-Werror -march=armv8.3-a+pauth -fptrauth-intrinsics"
379+ SNMALLOC_COMPILER_SUPPORT_MARCH_V83A_PAUTH )
380+ if (SNMALLOC_COMPILER_SUPPORT_MARCH_V83A_PAUTH)
381+ set (SNMALLOC_SAVED_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} " )
382+ set (CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -march=armv8.3-a+pauth -fptrauth-intrinsics" )
383+ check_cxx_source_compiles ("
384+ #if !defined(__aarch64__) && !defined(_M_ARM64) && !defined(_M_ARM64EC)
385+ # error PAC instructions require AArch64
386+ #endif
387+ #if !__has_include(<ptrauth.h>)
388+ # error Missing ptrauth.h
389+ #endif
390+ #include <ptrauth.h>
391+ #ifndef __ARM_FEATURE_PAUTH
392+ # error Compiler target does not expose pointer authentication
393+ #endif
394+ static inline void* sign_and_auth(void* ptr, void* storage)
395+ {
396+ auto discriminator = ptrauth_blend_discriminator(storage, 0x5678U);
397+ auto signed_ptr = ptrauth_sign_unauthenticated(
398+ ptr, ptrauth_key_process_dependent_data, discriminator);
399+ return ptrauth_auth_data(
400+ signed_ptr, ptrauth_key_process_dependent_data, discriminator);
401+ }
402+ int main()
403+ {
404+ return sign_and_auth(nullptr, reinterpret_cast<void*>(0x1234UL)) != nullptr;
405+ }
406+ " SNMALLOC_COMPILER_SUPPORT_PACA_PACG )
407+ set (CMAKE_REQUIRED_FLAGS "${SNMALLOC_SAVED_REQUIRED_FLAGS} " )
408+ unset (SNMALLOC_SAVED_REQUIRED_FLAGS)
409+ endif ()
410+ if (SNMALLOC_COMPILER_SUPPORT_PACA_PACG)
411+ target_compile_options (snmalloc INTERFACE
412+ $<$<COMPILE_LANGUAGE :CXX >:-march =armv8 .3-a +pauth -fptrauth -intrinsics >)
413+ endif ()
414+
377415if (NOT SNMALLOC_HEADER_ONLY_LIBRARY AND SNMALLOC_IPO)
378416 check_ipo_supported (RESULT HAS_IPO )
379417 if (HAS_IPO)
@@ -400,6 +438,7 @@ add_as_define(SNMALLOC_PLATFORM_HAS_GETENTROPY)
400438add_as_define (SNMALLOC_PTHREAD_ATFORK_WORKS )
401439add_as_define (SNMALLOC_HAS_LINUX_RANDOM_H )
402440add_as_define (SNMALLOC_HAS_LINUX_FUTEX_H )
441+ add_as_define (SNMALLOC_COMPILER_SUPPORT_PACA_PACG )
403442if (SNMALLOC_NO_REALLOCARRAY)
404443 add_as_define (SNMALLOC_NO_REALLOCARRAY )
405444endif ()
0 commit comments