[compiler-rt] [PAC][compiler-rt] Fix init/fini array signing schema (PR #150691)

Anatoly Trosinenko via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 28 06:49:12 PDT 2025


================
@@ -54,22 +54,33 @@ static void __attribute__((used)) __do_init(void) {
 }
 
 #ifdef CRT_HAS_INITFINI_ARRAY
-#if __has_feature(ptrauth_init_fini)
+# if __has_feature(ptrauth_init_fini)
 // TODO: use __ptrauth-qualified pointers when they are supported on clang side
-#if __has_feature(ptrauth_init_fini_address_discrimination)
+#  if __has_feature(ptrauth_init_fini_address_discrimination)
 __attribute__((section(".init_array"), used)) static void *__init =
     ptrauth_sign_constant(&__do_init, ptrauth_key_init_fini_pointer,
                           ptrauth_blend_discriminator(
                               &__init, __ptrauth_init_fini_discriminator));
-#else
+#  else
 __attribute__((section(".init_array"), used)) static void *__init =
     ptrauth_sign_constant(&__do_init, ptrauth_key_init_fini_pointer,
                           __ptrauth_init_fini_discriminator);
-#endif
-#else
+#  endif
+# elif __has_feature(ptrauth_calls)
+#  ifdef __aarch64__
+// If ptrauth_init_fini feature is not present, compiler emits raw unsigned
+// pointers in .init_array. Use inline assembly to avoid implicit signing of
+// __do_init function pointer with ptrauth_calls enabled.
+__asm__(".pushsection .init_array,\"aw\", at init_array\n\t"
----------------
atrosinenko wrote:

[nit] It may be a bit surprising at first to see `"aw"` flags (namely, `w` - writable), though this is how `.init_array` section is defined in the compiler-generated assembly as well (is it fixed by linker script later?..) - maybe it is worth adding a comment that `w` flag is not an error here. Feel free to ignore if this is a common practice in the `builtins` library.

https://github.com/llvm/llvm-project/pull/150691


More information about the llvm-commits mailing list