Skip to content

Commit 6fef80d

Browse files
committed
Fix tests on aarch64 / with newer LLVM
1 parent 3cfb7c8 commit 6fef80d

File tree

11 files changed

+202
-52
lines changed

11 files changed

+202
-52
lines changed

crates/objc2/src/rc/id.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,13 @@ impl<T: Message> Id<T> {
377377
// swiftc: https://github.com/apple/swift/blob/swift-5.5.3-RELEASE/lib/IRGen/GenObjC.cpp#L148-L173
378378
// Clang: https://github.com/llvm/llvm-project/blob/889317d47b7f046cf0e68746da8f7f264582fb5b/clang/lib/CodeGen/CGObjC.cpp#L2339-L2373
379379
//
380+
// Note that LLVM may sometimes insert extra instructions between the
381+
// assembly and the `objc_retainAutoreleasedReturnValue` call,
382+
// especially when doing tail calls and it needs to clean up the
383+
// function frame. Unsure how to avoid this in a performant manner?
384+
// Maybe force not doing tail calls by inserting assembly to do the
385+
// call manually?
386+
//
380387
// Resources:
381388
// - https://www.mikeash.com/pyblog/friday-qa-2011-09-30-automatic-reference-counting.html
382389
// - https://www.galloway.me.uk/2012/02/how-does-objc_retainautoreleasedreturnvalue-work/
@@ -423,7 +430,7 @@ impl<T: Message> Id<T> {
423430
// https://developer.apple.com/videos/play/wwdc2022/110363/
424431
#[cfg(all(target_arch = "aarch64", not(feature = "unstable-apple-new")))]
425432
unsafe {
426-
// Same as `mov x29, x29`
433+
// Same as `mov x29, x29`.
427434
core::arch::asm!("mov fp, fp", options(nomem, preserves_flags, nostack))
428435
};
429436

crates/objc2/src/rc/test_object.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,10 @@ mod tests {
405405
// x86 autorelease_return is not currently tail-called, so the
406406
// optimization doesn't work on declare_class! functions.
407407
2
408-
} else if cfg!(any(debug_assertions, feature = "exception")) {
408+
} else if cfg!(target_arch = "aarch64") {
409+
// Currently doesn't work
410+
2
411+
} else if cfg!(any(debug_assertions, feature = "catch-all")) {
409412
2
410413
} else {
411414
1

crates/objc2/tests/id_retain_autoreleased.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ fn test_retain_autoreleased() {
3434
} else if cfg!(all(target_arch = "arm", panic = "unwind")) {
3535
// 32-bit ARM unwinding interferes with the optimization
3636
2
37-
} else if cfg!(any(debug_assertions, feature = "exception")) {
37+
} else if cfg!(any(debug_assertions, feature = "catch-all")) {
3838
2
3939
} else {
4040
1

crates/test-assembly/crates/test_msg_send_id/expected/apple-aarch64.s

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,19 @@ _handle_autoreleased:
130130
ldp x29, x30, [sp], #16
131131
b _objc_retainAutoreleasedReturnValue
132132

133+
.globl _handle_autoreleased_with_arg
134+
.p2align 2
135+
_handle_autoreleased_with_arg:
136+
stp x29, x30, [sp, #-16]!
137+
mov x29, sp
138+
and w2, w2, #0xff
139+
bl _objc_msgSend
140+
; InlineAsm Start
141+
mov x29, x29
142+
; InlineAsm End
143+
ldp x29, x30, [sp], #16
144+
b _objc_retainAutoreleasedReturnValue
145+
133146
.globl _handle_autoreleased_fallible
134147
.p2align 2
135148
_handle_autoreleased_fallible:
@@ -143,11 +156,11 @@ _handle_autoreleased_fallible:
143156
mov x29, x29
144157
; InlineAsm End
145158
bl _objc_retainAutoreleasedReturnValue
146-
cbz x0, LBB11_2
159+
cbz x0, LBB12_2
147160
ldp x29, x30, [sp, #16]
148161
ldp x20, x19, [sp], #32
149162
ret
150-
LBB11_2:
163+
LBB12_2:
151164
Lloh6:
152165
adrp x2, l_anon.[ID].4@PAGE
153166
Lloh7:
@@ -204,6 +217,6 @@ l_anon.[ID].3:
204217
.p2align 3, 0x0
205218
l_anon.[ID].4:
206219
.quad l_anon.[ID].0
207-
.asciz "3\000\000\000\000\000\000\000B\000\000\000\005\000\000"
220+
.asciz "3\000\000\000\000\000\000\000L\000\000\000\005\000\000"
208221

209222
.subsections_via_symbols

crates/test-assembly/crates/test_msg_send_id/expected/apple-armv7s.s

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,20 @@ _handle_autoreleased:
131131
pop {r7, lr}
132132
b _objc_retainAutoreleasedReturnValue
133133

134+
.globl _handle_autoreleased_with_arg
135+
.p2align 2
136+
.code 32
137+
_handle_autoreleased_with_arg:
138+
push {r7, lr}
139+
mov r7, sp
140+
uxtb r2, r2
141+
bl _objc_msgSend
142+
@ InlineAsm Start
143+
mov r7, r7
144+
@ InlineAsm End
145+
pop {r7, lr}
146+
b _objc_retainAutoreleasedReturnValue
147+
134148
.globl _handle_autoreleased_fallible
135149
.p2align 2
136150
.code 32
@@ -146,10 +160,10 @@ _handle_autoreleased_fallible:
146160
bl _objc_retainAutoreleasedReturnValue
147161
cmp r0, #0
148162
popne {r4, r5, r7, pc}
149-
LBB11_1:
150-
movw r2, :lower16:(l_anon.[ID].4-(LPC11_0+8))
151-
movt r2, :upper16:(l_anon.[ID].4-(LPC11_0+8))
152-
LPC11_0:
163+
LBB12_1:
164+
movw r2, :lower16:(l_anon.[ID].4-(LPC12_0+8))
165+
movt r2, :upper16:(l_anon.[ID].4-(LPC12_0+8))
166+
LPC12_0:
153167
add r2, pc, r2
154168
mov r0, r5
155169
mov r1, r4
@@ -200,6 +214,6 @@ l_anon.[ID].3:
200214
.p2align 2, 0x0
201215
l_anon.[ID].4:
202216
.long l_anon.[ID].0
203-
.asciz "3\000\000\000B\000\000\000\005\000\000"
217+
.asciz "3\000\000\000L\000\000\000\005\000\000"
204218

205219
.subsections_via_symbols

crates/test-assembly/crates/test_msg_send_id/expected/apple-x86.s

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,31 @@ _handle_autoreleased:
211211
pop ebp
212212
ret
213213

214+
.globl _handle_autoreleased_with_arg
215+
.p2align 4, 0x90
216+
_handle_autoreleased_with_arg:
217+
push ebp
218+
mov ebp, esp
219+
sub esp, 8
220+
movzx eax, byte ptr [ebp + 16]
221+
sub esp, 4
222+
push eax
223+
push dword ptr [ebp + 12]
224+
push dword ptr [ebp + 8]
225+
call _objc_msgSend
226+
add esp, 16
227+
## InlineAsm Start
228+
229+
mov ebp, ebp
230+
231+
## InlineAsm End
232+
sub esp, 12
233+
push eax
234+
call _objc_retainAutoreleasedReturnValue
235+
add esp, 24
236+
pop ebp
237+
ret
238+
214239
.globl _handle_autoreleased_fallible
215240
.p2align 4, 0x90
216241
_handle_autoreleased_fallible:
@@ -220,8 +245,8 @@ _handle_autoreleased_fallible:
220245
push edi
221246
push esi
222247
sub esp, 12
223-
call L11$pb
224-
L11$pb:
248+
call L12$pb
249+
L12$pb:
225250
pop ebx
226251
mov edi, dword ptr [ebp + 12]
227252
mov esi, dword ptr [ebp + 8]
@@ -240,16 +265,16 @@ L11$pb:
240265
call _objc_retainAutoreleasedReturnValue
241266
add esp, 16
242267
test eax, eax
243-
je LBB11_2
268+
je LBB12_2
244269
add esp, 12
245270
pop esi
246271
pop edi
247272
pop ebx
248273
pop ebp
249274
ret
250-
LBB11_2:
275+
LBB12_2:
251276
sub esp, 4
252-
lea eax, [ebx + l_anon.[ID].4-L11$pb]
277+
lea eax, [ebx + l_anon.[ID].4-L12$pb]
253278
push eax
254279
push edi
255280
push esi
@@ -315,6 +340,6 @@ l_anon.[ID].3:
315340
.p2align 2, 0x0
316341
l_anon.[ID].4:
317342
.long l_anon.[ID].0
318-
.asciz "3\000\000\000B\000\000\000\005\000\000"
343+
.asciz "3\000\000\000L\000\000\000\005\000\000"
319344

320345
.subsections_via_symbols

crates/test-assembly/crates/test_msg_send_id/expected/apple-x86_64.s

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,23 @@ _handle_autoreleased:
150150
pop rbp
151151
ret
152152

153+
.globl _handle_autoreleased_with_arg
154+
.p2align 4, 0x90
155+
_handle_autoreleased_with_arg:
156+
push rbp
157+
mov rbp, rsp
158+
movzx edx, dl
159+
call _objc_msgSend
160+
mov rdi, rax
161+
call _objc_retainAutoreleasedReturnValue
162+
## InlineAsm Start
163+
164+
nop
165+
166+
## InlineAsm End
167+
pop rbp
168+
ret
169+
153170
.globl _handle_autoreleased_fallible
154171
.p2align 4, 0x90
155172
_handle_autoreleased_fallible:
@@ -168,12 +185,12 @@ _handle_autoreleased_fallible:
168185

169186
## InlineAsm End
170187
test rax, rax
171-
je LBB11_2
188+
je LBB12_2
172189
pop rbx
173190
pop r14
174191
pop rbp
175192
ret
176-
LBB11_2:
193+
LBB12_2:
177194
lea rdx, [rip + l_anon.[ID].4]
178195
mov rdi, r14
179196
mov rsi, rbx
@@ -233,6 +250,6 @@ l_anon.[ID].3:
233250
.p2align 3, 0x0
234251
l_anon.[ID].4:
235252
.quad l_anon.[ID].0
236-
.asciz "3\000\000\000\000\000\000\000B\000\000\000\005\000\000"
253+
.asciz "3\000\000\000\000\000\000\000L\000\000\000\005\000\000"
237254

238255
.subsections_via_symbols

crates/test-assembly/crates/test_msg_send_id/expected/gnustep-x86.s

Lines changed: 54 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,45 @@ handle_autoreleased:
411411
.Lfunc_end10:
412412
.size handle_autoreleased, .Lfunc_end10-handle_autoreleased
413413

414+
.section .text.handle_autoreleased_with_arg,"ax",@progbits
415+
.globl handle_autoreleased_with_arg
416+
.p2align 4, 0x90
417+
.type handle_autoreleased_with_arg,@function
418+
handle_autoreleased_with_arg:
419+
push ebp
420+
push ebx
421+
push edi
422+
push esi
423+
sub esp, 12
424+
movzx edi, byte ptr [esp + 40]
425+
mov esi, dword ptr [esp + 32]
426+
mov ebp, dword ptr [esp + 36]
427+
call .L11$pb
428+
.L11$pb:
429+
pop ebx
430+
.Ltmp11:
431+
add ebx, offset _GLOBAL_OFFSET_TABLE_+(.Ltmp11-.L11$pb)
432+
sub esp, 8
433+
push ebp
434+
push esi
435+
call objc_msg_lookup@PLT
436+
add esp, 12
437+
push edi
438+
push ebp
439+
push esi
440+
call eax
441+
add esp, 4
442+
push eax
443+
call objc_retainAutoreleasedReturnValue@PLT
444+
add esp, 28
445+
pop esi
446+
pop edi
447+
pop ebx
448+
pop ebp
449+
ret
450+
.Lfunc_end11:
451+
.size handle_autoreleased_with_arg, .Lfunc_end11-handle_autoreleased_with_arg
452+
414453
.section .text.handle_autoreleased_fallible,"ax",@progbits
415454
.globl handle_autoreleased_fallible
416455
.p2align 4, 0x90
@@ -421,11 +460,11 @@ handle_autoreleased_fallible:
421460
push esi
422461
mov edi, dword ptr [esp + 20]
423462
mov esi, dword ptr [esp + 16]
424-
call .L11$pb
425-
.L11$pb:
463+
call .L12$pb
464+
.L12$pb:
426465
pop ebx
427-
.Ltmp11:
428-
add ebx, offset _GLOBAL_OFFSET_TABLE_+(.Ltmp11-.L11$pb)
466+
.Ltmp12:
467+
add ebx, offset _GLOBAL_OFFSET_TABLE_+(.Ltmp12-.L12$pb)
429468
sub esp, 8
430469
push edi
431470
push esi
@@ -439,12 +478,12 @@ handle_autoreleased_fallible:
439478
call objc_retainAutoreleasedReturnValue@PLT
440479
add esp, 16
441480
test eax, eax
442-
je .LBB11_1
481+
je .LBB12_1
443482
pop esi
444483
pop edi
445484
pop ebx
446485
ret
447-
.LBB11_1:
486+
.LBB12_1:
448487
sub esp, 4
449488
lea eax, [ebx + .Lanon.[ID].4@GOTOFF]
450489
push eax
@@ -453,8 +492,8 @@ handle_autoreleased_fallible:
453492
call SYM(<objc2::__macro_helpers::method_family::RetainSemantics<5_u8> as objc2::__macro_helpers::msg_send_id::MsgSendIdFailed>::failed::GENERATED_ID, 0)@PLT
454493
add esp, 16
455494
ud2
456-
.Lfunc_end11:
457-
.size handle_autoreleased_fallible, .Lfunc_end11-handle_autoreleased_fallible
495+
.Lfunc_end12:
496+
.size handle_autoreleased_fallible, .Lfunc_end12-handle_autoreleased_fallible
458497

459498
.section .text.handle_with_out_param,"ax",@progbits
460499
.globl handle_with_out_param
@@ -469,11 +508,11 @@ handle_with_out_param:
469508
mov ebp, dword ptr [esp + 40]
470509
mov eax, dword ptr [esp + 32]
471510
mov esi, dword ptr [esp + 36]
472-
call .L12$pb
473-
.L12$pb:
511+
call .L13$pb
512+
.L13$pb:
474513
pop ebx
475-
.Ltmp12:
476-
add ebx, offset _GLOBAL_OFFSET_TABLE_+(.Ltmp12-.L12$pb)
514+
.Ltmp13:
515+
add ebx, offset _GLOBAL_OFFSET_TABLE_+(.Ltmp13-.L13$pb)
477516
mov edi, dword ptr [ebp]
478517
mov dword ptr [esp + 4], esi
479518
mov dword ptr [esp], eax
@@ -497,8 +536,8 @@ handle_with_out_param:
497536
pop ebx
498537
pop ebp
499538
ret
500-
.Lfunc_end12:
501-
.size handle_with_out_param, .Lfunc_end12-handle_with_out_param
539+
.Lfunc_end13:
540+
.size handle_with_out_param, .Lfunc_end13-handle_with_out_param
502541

503542
.type .Lanon.[ID].0,@object
504543
.section .rodata..Lanon.[ID].0,"a",@progbits
@@ -535,7 +574,7 @@ handle_with_out_param:
535574
.p2align 2, 0x0
536575
.Lanon.[ID].4:
537576
.long .Lanon.[ID].0
538-
.asciz "3\000\000\000B\000\000\000\005\000\000"
577+
.asciz "3\000\000\000L\000\000\000\005\000\000"
539578
.size .Lanon.[ID].4, 16
540579

541580
.section ".note.GNU-stack","",@progbits

0 commit comments

Comments
 (0)