File tree 6 files changed +132
-0
lines changed
tests/assembly/test_msg_send_zero_cost 6 files changed +132
-0
lines changed Original file line number Diff line number Diff line change 4
4
_handle:
5
5
b _objc_msgSend
6
6
7
+ .globl _handle_with_sel
8
+ .p2align 2
9
+ _handle_with_sel:
10
+ Lloh0:
11
+ adrp x8, _SEL_REF@PAGE
12
+ Lloh1:
13
+ ldr x1, [x8, _SEL_REF@PAGEOFF]
14
+ b _objc_msgSend
15
+ .loh AdrpLdr Lloh0, Lloh1
16
+
17
+ .section __TEXT,__const
18
+ .globl _SEL
19
+ _SEL:
20
+ .asciz "someSelector"
21
+
22
+ .section __DATA,__const
23
+ .globl _SEL_REF
24
+ .p2align 3
25
+ _SEL_REF:
26
+ .quad _SEL
27
+
7
28
.subsections_via_symbols
Original file line number Diff line number Diff line change 6
6
_handle:
7
7
b _objc_msgSend
8
8
9
+ .globl _handle_with_sel
10
+ .p2align 2
11
+ .code 32
12
+ _handle_with_sel:
13
+ movw r1, :lower16:(_SEL_REF-(LPC1_0+8 ))
14
+ movt r1, :upper16:(_SEL_REF-(LPC1_0+8 ))
15
+ LPC1_0:
16
+ ldr r1, [pc, r1]
17
+ b _objc_msgSend
18
+
19
+ .section __TEXT,__const
20
+ .globl _SEL
21
+ _SEL:
22
+ .asciz "someSelector"
23
+
24
+ .section __DATA,__const
25
+ .globl _SEL_REF
26
+ .p2align 2
27
+ _SEL_REF:
28
+ .long _SEL
29
+
9
30
.subsections_via_symbols
Original file line number Diff line number Diff line change @@ -9,4 +9,28 @@ _handle:
9
9
bl _objc_msgSend
10
10
pop {r7 , pc}
11
11
12
+ .globl _handle_with_sel
13
+ .p2align 2
14
+ .code 32
15
+ _handle_with_sel:
16
+ push {r7 , lr}
17
+ mov r7 , sp
18
+ movw r1 , :lower16:(_SEL_REF - (LPC1_0 + 8 ))
19
+ movt r1 , :upper16:(_SEL_REF - (LPC1_0 + 8 ))
20
+ LPC1_0:
21
+ ldr r1 , [ pc , r1 ]
22
+ bl _objc_msgSend
23
+ pop {r7 , pc}
24
+
25
+ . section __TEXT , __const
26
+ .globl _SEL
27
+ _SEL:
28
+ .asciz "someSelector"
29
+
30
+ . section __DATA , __const
31
+ .globl _SEL_REF
32
+ .p2align 2
33
+ _SEL_REF:
34
+ .long _SEL
35
+
12
36
.subsections_via_symbols
Original file line number Diff line number Diff line change @@ -8,4 +8,32 @@ _handle:
8
8
pop ebp
9
9
jmp _objc_msgSend
10
10
11
+ .globl _handle_with_sel
12
+ .p2align 4 , 0x90
13
+ _handle_with_sel:
14
+ push ebp
15
+ mov ebp , esp
16
+ sub esp , 8
17
+ call L1 $ pb
18
+ L1 $ pb:
19
+ pop eax
20
+ sub esp , 8
21
+ push dword ptr [ eax + _SEL_REF - L1 $ pb ]
22
+ push dword ptr [ ebp + 8 ]
23
+ call _objc_msgSend
24
+ add esp , 24
25
+ pop ebp
26
+ ret
27
+
28
+ . section __TEXT , __const
29
+ .globl _SEL
30
+ _SEL:
31
+ .asciz "someSelector"
32
+
33
+ . section __DATA , __const
34
+ .globl _SEL_REF
35
+ .p2align 2
36
+ _SEL_REF:
37
+ .long _SEL
38
+
11
39
.subsections_via_symbols
Original file line number Diff line number Diff line change @@ -8,4 +8,24 @@ _handle:
8
8
pop rbp
9
9
jmp _objc_msgSend
10
10
11
+ .globl _handle_with_sel
12
+ .p2align 4 , 0x90
13
+ _handle_with_sel:
14
+ push rbp
15
+ mov rbp , rsp
16
+ mov rsi , qword ptr [ rip + _SEL_REF ]
17
+ pop rbp
18
+ jmp _objc_msgSend
19
+
20
+ . section __TEXT , __const
21
+ .globl _SEL
22
+ _SEL:
23
+ .asciz "someSelector"
24
+
25
+ . section __DATA , __const
26
+ .globl _SEL_REF
27
+ .p2align 3
28
+ _SEL_REF:
29
+ .quad _SEL
30
+
11
31
.subsections_via_symbols
Original file line number Diff line number Diff line change 1
1
//! Test that the inner part of msg_send! is inlined into an objc_msgSend
2
+ use core:: mem;
3
+ use core:: ptr;
2
4
3
5
use objc2:: runtime:: { Object , Sel } ;
4
6
use objc2:: MessageReceiver ;
@@ -7,3 +9,19 @@ use objc2::MessageReceiver;
7
9
pub fn handle ( obj : & Object , sel : Sel ) -> * mut Object {
8
10
unsafe { MessageReceiver :: send_message ( obj, sel, ( ) ) . unwrap ( ) }
9
11
}
12
+
13
+ // This will definitely not work, but is useful for making the assembly look
14
+ // closer to real-world.
15
+ #[ no_mangle]
16
+ static SEL : [ u8 ; 13 ] = * b"someSelector\0 " ;
17
+ #[ no_mangle]
18
+ static SEL_REF : Sel = unsafe { mem:: transmute ( SEL . as_ptr ( ) ) } ;
19
+
20
+ fn selector ( ) -> Sel {
21
+ unsafe { ptr:: read_volatile ( & SEL_REF ) }
22
+ }
23
+
24
+ #[ no_mangle]
25
+ pub fn handle_with_sel ( obj : & Object ) -> * mut Object {
26
+ unsafe { MessageReceiver :: send_message ( obj, selector ( ) , ( ) ) . unwrap ( ) }
27
+ }
You can’t perform that action at this time.
0 commit comments