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

Daniil Kovalev via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 28 07:05:29 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"
----------------
kovdan01 wrote:

@atrosinenko I might be missing smth, but `w` flag does not look surprising to me - we have relocations against init/fini array sections, and the section should be writable. Of course, we might make this non-writable after relocations are resolves, and it looks like that lld tries to do such a trick for init/fini array sections, but anyway, the `w` flag still needs to be here.

Maybe I've misinterpreted your comment and you are talking about smth else - could you please clarify your concerns so we do not have misunderstanding?

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


More information about the llvm-commits mailing list