@@ -54,22 +54,33 @@ static void __attribute__((used)) __do_init(void) {
54
54
}
55
55
56
56
#ifdef CRT_HAS_INITFINI_ARRAY
57
- #if __has_feature (ptrauth_init_fini )
57
+ # if __has_feature (ptrauth_init_fini )
58
58
// TODO: use __ptrauth-qualified pointers when they are supported on clang side
59
- #if __has_feature (ptrauth_init_fini_address_discrimination )
59
+ # if __has_feature (ptrauth_init_fini_address_discrimination )
60
60
__attribute__((section (".init_array" ), used )) static void * __init =
61
61
ptrauth_sign_constant (& __do_init , ptrauth_key_init_fini_pointer ,
62
62
ptrauth_blend_discriminator (
63
63
& __init , __ptrauth_init_fini_discriminator ));
64
- #else
64
+ # else
65
65
__attribute__((section (".init_array" ), used )) static void * __init =
66
66
ptrauth_sign_constant (& __do_init , ptrauth_key_init_fini_pointer ,
67
67
__ptrauth_init_fini_discriminator );
68
- #endif
69
- #else
68
+ # endif
69
+ # elif __has_feature (ptrauth_calls )
70
+ # ifdef __aarch64__
71
+ // If ptrauth_init_fini feature is not present, compiler emits raw unsigned
72
+ // pointers in .init_array. Use inline assembly to avoid implicit signing of
73
+ // __do_init function pointer with ptrauth_calls enabled.
74
+ __asm__(".pushsection .init_array,\"aw\",@init_array\n\t"
75
+ ".xword __do_init\n\t"
76
+ ".popsection" );
77
+ # else
78
+ # error "ptrauth_calls is only supported for AArch64"
79
+ # endif
80
+ # else
70
81
__attribute__((section (".init_array" ),
71
82
used )) static void (* __init )(void ) = __do_init ;
72
- #endif
83
+ # endif
73
84
#elif defined(__i386__ ) || defined(__x86_64__ )
74
85
__asm__(".pushsection .init,\"ax\",@progbits\n\t"
75
86
"call __do_init\n\t"
@@ -125,22 +136,33 @@ static void __attribute__((used)) __do_fini(void) {
125
136
}
126
137
127
138
#ifdef CRT_HAS_INITFINI_ARRAY
128
- #if __has_feature (ptrauth_init_fini )
139
+ # if __has_feature (ptrauth_init_fini )
129
140
// TODO: use __ptrauth-qualified pointers when they are supported on clang side
130
- #if __has_feature (ptrauth_init_fini_address_discrimination )
141
+ # if __has_feature (ptrauth_init_fini_address_discrimination )
131
142
__attribute__((section (".fini_array" ), used )) static void * __fini =
132
143
ptrauth_sign_constant (& __do_fini , ptrauth_key_init_fini_pointer ,
133
144
ptrauth_blend_discriminator (
134
145
& __fini , __ptrauth_init_fini_discriminator ));
135
- #else
146
+ # else
136
147
__attribute__((section (".fini_array" ), used )) static void * __fini =
137
148
ptrauth_sign_constant (& __do_fini , ptrauth_key_init_fini_pointer ,
138
149
__ptrauth_init_fini_discriminator );
139
- #endif
140
- #else
150
+ # endif
151
+ # elif __has_feature (ptrauth_calls )
152
+ # ifdef __aarch64__
153
+ // If ptrauth_init_fini feature is not present, compiler emits raw unsigned
154
+ // pointers in .fini_array. Use inline assembly to avoid implicit signing of
155
+ // __do_fini function pointer with ptrauth_calls enabled.
156
+ __asm__(".pushsection .fini_array,\"aw\",@fini_array\n\t"
157
+ ".xword __do_fini\n\t"
158
+ ".popsection" );
159
+ # else
160
+ # error "ptrauth_calls is only supported for AArch64"
161
+ # endif
162
+ # else
141
163
__attribute__((section (".fini_array" ),
142
164
used )) static void (* __fini )(void ) = __do_fini ;
143
- #endif
165
+ # endif
144
166
#elif defined(__i386__ ) || defined(__x86_64__ )
145
167
__asm__(".pushsection .fini,\"ax\",@progbits\n\t"
146
168
"call __do_fini\n\t"
0 commit comments