Skip to content

Commit

Permalink
Add protocol assembly tests
Browse files Browse the repository at this point in the history
  • Loading branch information
madsmtm committed Jan 27, 2023
1 parent 882cdaa commit cf15592
Show file tree
Hide file tree
Showing 10 changed files with 398 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions crates/test-assembly/crates/test_extern_protocol/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[package]
name = "test_extern_protocol"
version = "0.1.0"
edition = "2021"
publish = false

[lib]
path = "lib.rs"

[dependencies]
objc2 = { path = "../../../objc2", default-features = false, optional = true }

[features]
default = ["apple", "std"]
std = ["objc2?/std"]
# Runtime
apple = ["objc2", "objc2?/apple"]
gnustep-1-7 = ["objc2?/gnustep-1-7"]
gnustep-1-8 = ["gnustep-1-7", "objc2?/gnustep-1-8"]
gnustep-1-9 = ["gnustep-1-8", "objc2?/gnustep-1-9"]
gnustep-2-0 = ["gnustep-1-9", "objc2?/gnustep-2-0"]
gnustep-2-1 = ["gnustep-2-0", "objc2?/gnustep-2-1"]

# Hack to prevent the feature flag from being enabled in the entire project
assembly-features = ["objc2?/unstable-static-sel-inlined"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
.section __TEXT,__text,regular,pure_instructions
.globl _get_protocol
.p2align 2
_get_protocol:
Lloh0:
adrp x0, l_anon.[ID].0@PAGE
Lloh1:
add x0, x0, l_anon.[ID].0@PAGEOFF
mov w1, #10
b SYM(objc2::runtime::Protocol::get::GENERATED_ID, 0)
.loh AdrpAdd Lloh0, Lloh1

.globl _dyn_call
.p2align 2
_dyn_call:
Lloh2:
adrp x8, L_OBJC_SELECTOR_REFERENCES_016b57e4e6a36961@PAGE
Lloh3:
ldr x1, [x8, L_OBJC_SELECTOR_REFERENCES_016b57e4e6a36961@PAGEOFF]
b _objc_msgSend
.loh AdrpLdr Lloh2, Lloh3

.globl _dyn_consume
.p2align 2
_dyn_consume:
stp x20, x19, [sp, #-32]!
stp x29, x30, [sp, #16]
add x29, sp, #16
mov x19, x0
Lloh4:
adrp x8, L_OBJC_SELECTOR_REFERENCES_016b57e4e6a36961@PAGE
Lloh5:
ldr x1, [x8, L_OBJC_SELECTOR_REFERENCES_016b57e4e6a36961@PAGEOFF]
bl _objc_msgSend
mov x0, x19
ldp x29, x30, [sp, #16]
ldp x20, x19, [sp], #32
b _objc_release
.loh AdrpLdr Lloh4, Lloh5

.section __TEXT,__const
l_anon.[ID].0:
.ascii "MyProtocol"

.section __DATA,__objc_imageinfo,regular,no_dead_strip
.globl L_OBJC_IMAGE_INFO_016b57e4e6a36961
.p2align 2
L_OBJC_IMAGE_INFO_016b57e4e6a36961:
.asciz "\000\000\000\000@\000\000"

.section __TEXT,__objc_methname,cstring_literals
.globl L_OBJC_METH_VAR_NAME_016b57e4e6a36961
L_OBJC_METH_VAR_NAME_016b57e4e6a36961:
.asciz "aMethod"

.section __DATA,__objc_selrefs,literal_pointers,no_dead_strip
.globl L_OBJC_SELECTOR_REFERENCES_016b57e4e6a36961
.p2align 3
L_OBJC_SELECTOR_REFERENCES_016b57e4e6a36961:
.quad L_OBJC_METH_VAR_NAME_016b57e4e6a36961

.subsections_via_symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
.section __TEXT,__text,regular,pure_instructions
.syntax unified
.globl _get_protocol
.p2align 2
.code 32
_get_protocol:
movw r0, :lower16:(l_anon.[ID].0-(LPC0_0+8))
mov r1, #10
movt r0, :upper16:(l_anon.[ID].0-(LPC0_0+8))
LPC0_0:
add r0, pc, r0
b SYM(objc2::runtime::Protocol::get::GENERATED_ID, 0)

.globl _dyn_call
.p2align 2
.code 32
_dyn_call:
movw r1, :lower16:(L_OBJC_SELECTOR_REFERENCES_016b57e4e6a36961-(LPC1_0+8))
movt r1, :upper16:(L_OBJC_SELECTOR_REFERENCES_016b57e4e6a36961-(LPC1_0+8))
LPC1_0:
ldr r1, [pc, r1]
b _objc_msgSend

.globl _dyn_consume
.p2align 2
.code 32
_dyn_consume:
push {r4, r7, lr}
add r7, sp, #4
movw r1, :lower16:(L_OBJC_SELECTOR_REFERENCES_016b57e4e6a36961-(LPC2_0+8))
mov r4, r0
movt r1, :upper16:(L_OBJC_SELECTOR_REFERENCES_016b57e4e6a36961-(LPC2_0+8))
LPC2_0:
ldr r1, [pc, r1]
bl _objc_msgSend
mov r0, r4
pop {r4, r7, lr}
b _objc_release

.section __TEXT,__const
l_anon.[ID].0:
.ascii "MyProtocol"

.section __DATA,__objc_imageinfo,regular,no_dead_strip
.globl L_OBJC_IMAGE_INFO_016b57e4e6a36961
.p2align 2
L_OBJC_IMAGE_INFO_016b57e4e6a36961:
.asciz "\000\000\000\000@\000\000"

.section __TEXT,__objc_methname,cstring_literals
.globl L_OBJC_METH_VAR_NAME_016b57e4e6a36961
L_OBJC_METH_VAR_NAME_016b57e4e6a36961:
.asciz "aMethod"

.section __DATA,__objc_selrefs,literal_pointers,no_dead_strip
.globl L_OBJC_SELECTOR_REFERENCES_016b57e4e6a36961
.p2align 2
L_OBJC_SELECTOR_REFERENCES_016b57e4e6a36961:
.long L_OBJC_METH_VAR_NAME_016b57e4e6a36961

.subsections_via_symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
.section __TEXT,__text,regular,pure_instructions
.syntax unified
.globl _get_protocol
.p2align 2
.code 32
_get_protocol:
push {r7, lr}
mov r7, sp
movw r0, :lower16:(l_anon.[ID].0-(LPC0_0+8))
mov r1, #10
movt r0, :upper16:(l_anon.[ID].0-(LPC0_0+8))
LPC0_0:
add r0, pc, r0
bl SYM(objc2::runtime::Protocol::get::GENERATED_ID, 0)
pop {r7, pc}

.globl _dyn_call
.p2align 2
.code 32
_dyn_call:
push {r7, lr}
mov r7, sp
movw r1, :lower16:(L_OBJC_SELECTOR_REFERENCES_016b57e4e6a36961-(LPC1_0+8))
movt r1, :upper16:(L_OBJC_SELECTOR_REFERENCES_016b57e4e6a36961-(LPC1_0+8))
LPC1_0:
ldr r1, [pc, r1]
bl _objc_msgSend
pop {r7, pc}

.globl _dyn_consume
.p2align 2
.code 32
_dyn_consume:
push {r4, r7, lr}
add r7, sp, #4
movw r1, :lower16:(L_OBJC_SELECTOR_REFERENCES_016b57e4e6a36961-(LPC2_0+8))
mov r4, r0
movt r1, :upper16:(L_OBJC_SELECTOR_REFERENCES_016b57e4e6a36961-(LPC2_0+8))
LPC2_0:
ldr r1, [pc, r1]
bl _objc_msgSend
mov r0, r4
bl _objc_release
pop {r4, r7, pc}

.section __TEXT,__const
l_anon.[ID].0:
.ascii "MyProtocol"

.section __DATA,__objc_imageinfo,regular,no_dead_strip
.globl L_OBJC_IMAGE_INFO_016b57e4e6a36961
.p2align 2
L_OBJC_IMAGE_INFO_016b57e4e6a36961:
.asciz "\000\000\000\000@\000\000"

.section __TEXT,__objc_methname,cstring_literals
.globl L_OBJC_METH_VAR_NAME_016b57e4e6a36961
L_OBJC_METH_VAR_NAME_016b57e4e6a36961:
.asciz "aMethod"

.section __DATA,__objc_selrefs,literal_pointers,no_dead_strip
.globl L_OBJC_SELECTOR_REFERENCES_016b57e4e6a36961
.p2align 2
L_OBJC_SELECTOR_REFERENCES_016b57e4e6a36961:
.long L_OBJC_METH_VAR_NAME_016b57e4e6a36961

.subsections_via_symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
.section __TEXT,__text,regular,pure_instructions
.intel_syntax noprefix
.globl _get_protocol
.p2align 4, 0x90
_get_protocol:
push ebp
mov ebp, esp
sub esp, 8
call L0$pb
L0$pb:
pop eax
sub esp, 8
lea eax, [eax + l_anon.[ID].0-L0$pb]
push 10
push eax
call SYM(objc2::runtime::Protocol::get::GENERATED_ID, 0)
add esp, 24
pop ebp
ret

.globl _dyn_call
.p2align 4, 0x90
_dyn_call:
push ebp
mov ebp, esp
sub esp, 8
call L1$pb
L1$pb:
pop eax
sub esp, 8
push dword ptr [eax + L_OBJC_SELECTOR_REFERENCES_016b57e4e6a36961-L1$pb]
push dword ptr [ebp + 8]
call _objc_msgSend
add esp, 24
pop ebp
ret

.globl _dyn_consume
.p2align 4, 0x90
_dyn_consume:
push ebp
mov ebp, esp
sub esp, 8
call L2$pb
L2$pb:
pop eax
sub esp, 8
push dword ptr [eax + L_OBJC_SELECTOR_REFERENCES_016b57e4e6a36961-L2$pb]
push dword ptr [ebp + 8]
call _objc_msgSend
add esp, 24
pop ebp
jmp _objc_release

.section __TEXT,__const
l_anon.[ID].0:
.ascii "MyProtocol"

.section __OBJC,__image_info
.globl L_OBJC_IMAGE_INFO_016b57e4e6a36961
.p2align 2
L_OBJC_IMAGE_INFO_016b57e4e6a36961:
.asciz "\000\000\000\000@\000\000"

.section __TEXT,__cstring,cstring_literals
.globl L_OBJC_METH_VAR_NAME_016b57e4e6a36961
L_OBJC_METH_VAR_NAME_016b57e4e6a36961:
.asciz "aMethod"

.section __OBJC,__message_refs,literal_pointers,no_dead_strip
.globl L_OBJC_SELECTOR_REFERENCES_016b57e4e6a36961
.p2align 2
L_OBJC_SELECTOR_REFERENCES_016b57e4e6a36961:
.long L_OBJC_METH_VAR_NAME_016b57e4e6a36961

.subsections_via_symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
.section __TEXT,__text,regular,pure_instructions
.intel_syntax noprefix
.globl _get_protocol
.p2align 4, 0x90
_get_protocol:
push rbp
mov rbp, rsp
lea rdi, [rip + l_anon.[ID].0]
mov esi, 10
pop rbp
jmp SYM(objc2::runtime::Protocol::get::GENERATED_ID, 0)

.globl _dyn_call
.p2align 4, 0x90
_dyn_call:
push rbp
mov rbp, rsp
mov rsi, qword ptr [rip + L_OBJC_SELECTOR_REFERENCES_016b57e4e6a36961]
pop rbp
jmp _objc_msgSend

.globl _dyn_consume
.p2align 4, 0x90
_dyn_consume:
push rbp
mov rbp, rsp
push rbx
push rax
mov rbx, rdi
mov rsi, qword ptr [rip + L_OBJC_SELECTOR_REFERENCES_016b57e4e6a36961]
call _objc_msgSend
mov rdi, rbx
add rsp, 8
pop rbx
pop rbp
jmp _objc_release

.section __TEXT,__const
l_anon.[ID].0:
.ascii "MyProtocol"

.section __DATA,__objc_imageinfo,regular,no_dead_strip
.globl L_OBJC_IMAGE_INFO_016b57e4e6a36961
.p2align 2
L_OBJC_IMAGE_INFO_016b57e4e6a36961:
.asciz "\000\000\000\000@\000\000"

.section __TEXT,__objc_methname,cstring_literals
.globl L_OBJC_METH_VAR_NAME_016b57e4e6a36961
L_OBJC_METH_VAR_NAME_016b57e4e6a36961:
.asciz "aMethod"

.section __DATA,__objc_selrefs,literal_pointers,no_dead_strip
.globl L_OBJC_SELECTOR_REFERENCES_016b57e4e6a36961
.p2align 3
L_OBJC_SELECTOR_REFERENCES_016b57e4e6a36961:
.quad L_OBJC_METH_VAR_NAME_016b57e4e6a36961

.subsections_via_symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.text
.intel_syntax noprefix
.section ".note.GNU-stack","",@progbits
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.text
.intel_syntax noprefix
.section ".note.GNU-stack","",@progbits
Loading

0 comments on commit cf15592

Please sign in to comment.