Skip to content

Better assembly tests #171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

This file was deleted.

This file was deleted.

28 changes: 28 additions & 0 deletions tests/assembly/test_msg_send_zero_cost/expected/apple-aarch64.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
.section __TEXT,__text,regular,pure_instructions
.globl _handle
.p2align 2
_handle:
b _objc_msgSend

.globl _handle_with_sel
.p2align 2
_handle_with_sel:
Lloh0:
adrp x8, _SEL_REF@PAGE
Lloh1:
ldr x1, [x8, _SEL_REF@PAGEOFF]
b _objc_msgSend
.loh AdrpLdr Lloh0, Lloh1

.section __TEXT,__const
.globl _SEL
_SEL:
.asciz "someSelector"

.section __DATA,__const
.globl _SEL_REF
.p2align 3
_SEL_REF:
.quad _SEL

.subsections_via_symbols
30 changes: 30 additions & 0 deletions tests/assembly/test_msg_send_zero_cost/expected/apple-armv7.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
.section __TEXT,__text,regular,pure_instructions
.syntax unified
.globl _handle
.p2align 2
.code 32
_handle:
b _objc_msgSend

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

.section __TEXT,__const
.globl _SEL
_SEL:
.asciz "someSelector"

.section __DATA,__const
.globl _SEL_REF
.p2align 2
_SEL_REF:
.long _SEL

.subsections_via_symbols
36 changes: 36 additions & 0 deletions tests/assembly/test_msg_send_zero_cost/expected/apple-armv7s.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
.section __TEXT,__text,regular,pure_instructions
.syntax unified
.globl _handle
.p2align 2
.code 32
_handle:
push {r7, lr}
mov r7, sp
bl _objc_msgSend
pop {r7, pc}

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

.section __TEXT,__const
.globl _SEL
_SEL:
.asciz "someSelector"

.section __DATA,__const
.globl _SEL_REF
.p2align 2
_SEL_REF:
.long _SEL

.subsections_via_symbols
39 changes: 39 additions & 0 deletions tests/assembly/test_msg_send_zero_cost/expected/apple-x86.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
.section __TEXT,__text,regular,pure_instructions
.intel_syntax noprefix
.globl _handle
.p2align 4, 0x90
_handle:
push ebp
mov ebp, esp
pop ebp
jmp _objc_msgSend

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

.section __TEXT,__const
.globl _SEL
_SEL:
.asciz "someSelector"

.section __DATA,__const
.globl _SEL_REF
.p2align 2
_SEL_REF:
.long _SEL

.subsections_via_symbols
31 changes: 31 additions & 0 deletions tests/assembly/test_msg_send_zero_cost/expected/apple-x86_64.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
.section __TEXT,__text,regular,pure_instructions
.intel_syntax noprefix
.globl _handle
.p2align 4, 0x90
_handle:
push rbp
mov rbp, rsp
pop rbp
jmp _objc_msgSend

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

.section __TEXT,__const
.globl _SEL
_SEL:
.asciz "someSelector"

.section __DATA,__const
.globl _SEL_REF
.p2align 3
_SEL_REF:
.quad _SEL

.subsections_via_symbols

This file was deleted.

12 changes: 0 additions & 12 deletions tests/assembly/test_msg_send_zero_cost/expected/armv7s-apple-ios.s

This file was deleted.

11 changes: 0 additions & 11 deletions tests/assembly/test_msg_send_zero_cost/expected/i386-apple-ios.s

This file was deleted.

This file was deleted.

This file was deleted.

11 changes: 0 additions & 11 deletions tests/assembly/test_msg_send_zero_cost/expected/x86_64-apple-ios.s

This file was deleted.

18 changes: 18 additions & 0 deletions tests/assembly/test_msg_send_zero_cost/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
//! Test that the inner part of msg_send! is inlined into an objc_msgSend
use core::mem;
use core::ptr;

use objc2::runtime::{Object, Sel};
use objc2::MessageReceiver;
Expand All @@ -7,3 +9,19 @@ use objc2::MessageReceiver;
pub fn handle(obj: &Object, sel: Sel) -> *mut Object {
unsafe { MessageReceiver::send_message(obj, sel, ()).unwrap() }
}

// This will definitely not work, but is useful for making the assembly look
// closer to real-world.
#[no_mangle]
static SEL: [u8; 13] = *b"someSelector\0";
#[no_mangle]
static SEL_REF: Sel = unsafe { mem::transmute(SEL.as_ptr()) };

fn selector() -> Sel {
unsafe { ptr::read_volatile(&SEL_REF) }
}

#[no_mangle]
pub fn handle_with_sel(obj: &Object) -> *mut Object {
unsafe { MessageReceiver::send_message(obj, selector(), ()).unwrap() }
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading