diff --git a/tests/assembly/test_msg_send_zero_cost/expected/aarch64-apple-darwin.s b/tests/assembly/test_msg_send_zero_cost/expected/aarch64-apple-darwin.s deleted file mode 100644 index b195a041a..000000000 --- a/tests/assembly/test_msg_send_zero_cost/expected/aarch64-apple-darwin.s +++ /dev/null @@ -1,7 +0,0 @@ - .section __TEXT,__text,regular,pure_instructions - .globl _handle - .p2align 2 -_handle: - b _objc_msgSend - -.subsections_via_symbols diff --git a/tests/assembly/test_msg_send_zero_cost/expected/aarch64-apple-ios-sim.s b/tests/assembly/test_msg_send_zero_cost/expected/aarch64-apple-ios-sim.s deleted file mode 100644 index d73fd4f2a..000000000 --- a/tests/assembly/test_msg_send_zero_cost/expected/aarch64-apple-ios-sim.s +++ /dev/null @@ -1,11 +0,0 @@ - .section __TEXT,__text,regular,pure_instructions - .globl _handle - .p2align 2 -_handle: - b _objc_msgSend - -; Stripped __LLVM section - -; Stripped __LLVM section - -.subsections_via_symbols diff --git a/tests/assembly/test_msg_send_zero_cost/expected/aarch64-apple-ios.s b/tests/assembly/test_msg_send_zero_cost/expected/aarch64-apple-ios.s deleted file mode 100644 index d73fd4f2a..000000000 --- a/tests/assembly/test_msg_send_zero_cost/expected/aarch64-apple-ios.s +++ /dev/null @@ -1,11 +0,0 @@ - .section __TEXT,__text,regular,pure_instructions - .globl _handle - .p2align 2 -_handle: - b _objc_msgSend - -; Stripped __LLVM section - -; Stripped __LLVM section - -.subsections_via_symbols diff --git a/tests/assembly/test_msg_send_zero_cost/expected/apple-aarch64.s b/tests/assembly/test_msg_send_zero_cost/expected/apple-aarch64.s new file mode 100644 index 000000000..7b25bae3f --- /dev/null +++ b/tests/assembly/test_msg_send_zero_cost/expected/apple-aarch64.s @@ -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 diff --git a/tests/assembly/test_msg_send_zero_cost/expected/apple-armv7.s b/tests/assembly/test_msg_send_zero_cost/expected/apple-armv7.s new file mode 100644 index 000000000..7c0461405 --- /dev/null +++ b/tests/assembly/test_msg_send_zero_cost/expected/apple-armv7.s @@ -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 diff --git a/tests/assembly/test_msg_send_zero_cost/expected/apple-armv7s.s b/tests/assembly/test_msg_send_zero_cost/expected/apple-armv7s.s new file mode 100644 index 000000000..845d4984c --- /dev/null +++ b/tests/assembly/test_msg_send_zero_cost/expected/apple-armv7s.s @@ -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 diff --git a/tests/assembly/test_msg_send_zero_cost/expected/apple-x86.s b/tests/assembly/test_msg_send_zero_cost/expected/apple-x86.s new file mode 100644 index 000000000..abb608b6c --- /dev/null +++ b/tests/assembly/test_msg_send_zero_cost/expected/apple-x86.s @@ -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 diff --git a/tests/assembly/test_msg_send_zero_cost/expected/apple-x86_64.s b/tests/assembly/test_msg_send_zero_cost/expected/apple-x86_64.s new file mode 100644 index 000000000..31578b0e1 --- /dev/null +++ b/tests/assembly/test_msg_send_zero_cost/expected/apple-x86_64.s @@ -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 diff --git a/tests/assembly/test_msg_send_zero_cost/expected/armv7-apple-ios.s b/tests/assembly/test_msg_send_zero_cost/expected/armv7-apple-ios.s deleted file mode 100644 index fe45b82cc..000000000 --- a/tests/assembly/test_msg_send_zero_cost/expected/armv7-apple-ios.s +++ /dev/null @@ -1,9 +0,0 @@ - .section __TEXT,__text,regular,pure_instructions - .syntax unified - .globl _handle - .p2align 2 - .code 32 -_handle: - b _objc_msgSend - -.subsections_via_symbols diff --git a/tests/assembly/test_msg_send_zero_cost/expected/armv7s-apple-ios.s b/tests/assembly/test_msg_send_zero_cost/expected/armv7s-apple-ios.s deleted file mode 100644 index abb037871..000000000 --- a/tests/assembly/test_msg_send_zero_cost/expected/armv7s-apple-ios.s +++ /dev/null @@ -1,12 +0,0 @@ - .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} - -.subsections_via_symbols diff --git a/tests/assembly/test_msg_send_zero_cost/expected/i386-apple-ios.s b/tests/assembly/test_msg_send_zero_cost/expected/i386-apple-ios.s deleted file mode 100644 index f20f298e7..000000000 --- a/tests/assembly/test_msg_send_zero_cost/expected/i386-apple-ios.s +++ /dev/null @@ -1,11 +0,0 @@ - .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 - -.subsections_via_symbols diff --git a/tests/assembly/test_msg_send_zero_cost/expected/i686-apple-darwin.s b/tests/assembly/test_msg_send_zero_cost/expected/i686-apple-darwin.s deleted file mode 100644 index f20f298e7..000000000 --- a/tests/assembly/test_msg_send_zero_cost/expected/i686-apple-darwin.s +++ /dev/null @@ -1,11 +0,0 @@ - .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 - -.subsections_via_symbols diff --git a/tests/assembly/test_msg_send_zero_cost/expected/x86_64-apple-darwin.s b/tests/assembly/test_msg_send_zero_cost/expected/x86_64-apple-darwin.s deleted file mode 100644 index cd046e70f..000000000 --- a/tests/assembly/test_msg_send_zero_cost/expected/x86_64-apple-darwin.s +++ /dev/null @@ -1,11 +0,0 @@ - .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 - -.subsections_via_symbols diff --git a/tests/assembly/test_msg_send_zero_cost/expected/x86_64-apple-ios.s b/tests/assembly/test_msg_send_zero_cost/expected/x86_64-apple-ios.s deleted file mode 100644 index cd046e70f..000000000 --- a/tests/assembly/test_msg_send_zero_cost/expected/x86_64-apple-ios.s +++ /dev/null @@ -1,11 +0,0 @@ - .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 - -.subsections_via_symbols diff --git a/tests/assembly/test_msg_send_zero_cost/lib.rs b/tests/assembly/test_msg_send_zero_cost/lib.rs index faf37d5cb..b175345d7 100644 --- a/tests/assembly/test_msg_send_zero_cost/lib.rs +++ b/tests/assembly/test_msg_send_zero_cost/lib.rs @@ -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; @@ -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() } +} diff --git a/tests/assembly/test_retain_autoreleased/expected/aarch64-apple-ios-sim.s b/tests/assembly/test_retain_autoreleased/expected/aarch64-apple-ios-sim.s deleted file mode 100644 index 42c336539..000000000 --- a/tests/assembly/test_retain_autoreleased/expected/aarch64-apple-ios-sim.s +++ /dev/null @@ -1,18 +0,0 @@ - .section __TEXT,__text,regular,pure_instructions - .globl _handle - .p2align 2 -_handle: - stp x29, x30, [sp, #-16]! - mov x29, sp - bl _objc_msgSend - ; InlineAsm Start - mov x29, x29 - ; InlineAsm End - ldp x29, x30, [sp], #16 - b _objc_retainAutoreleasedReturnValue - -; Stripped __LLVM section - -; Stripped __LLVM section - -.subsections_via_symbols diff --git a/tests/assembly/test_retain_autoreleased/expected/aarch64-apple-ios.s b/tests/assembly/test_retain_autoreleased/expected/aarch64-apple-ios.s deleted file mode 100644 index 42c336539..000000000 --- a/tests/assembly/test_retain_autoreleased/expected/aarch64-apple-ios.s +++ /dev/null @@ -1,18 +0,0 @@ - .section __TEXT,__text,regular,pure_instructions - .globl _handle - .p2align 2 -_handle: - stp x29, x30, [sp, #-16]! - mov x29, sp - bl _objc_msgSend - ; InlineAsm Start - mov x29, x29 - ; InlineAsm End - ldp x29, x30, [sp], #16 - b _objc_retainAutoreleasedReturnValue - -; Stripped __LLVM section - -; Stripped __LLVM section - -.subsections_via_symbols diff --git a/tests/assembly/test_retain_autoreleased/expected/aarch64-apple-darwin.s b/tests/assembly/test_retain_autoreleased/expected/apple-aarch64.s similarity index 100% rename from tests/assembly/test_retain_autoreleased/expected/aarch64-apple-darwin.s rename to tests/assembly/test_retain_autoreleased/expected/apple-aarch64.s diff --git a/tests/assembly/test_retain_autoreleased/expected/armv7-apple-ios.s b/tests/assembly/test_retain_autoreleased/expected/apple-armv7.s similarity index 100% rename from tests/assembly/test_retain_autoreleased/expected/armv7-apple-ios.s rename to tests/assembly/test_retain_autoreleased/expected/apple-armv7.s diff --git a/tests/assembly/test_retain_autoreleased/expected/armv7s-apple-ios.s b/tests/assembly/test_retain_autoreleased/expected/apple-armv7s.s similarity index 100% rename from tests/assembly/test_retain_autoreleased/expected/armv7s-apple-ios.s rename to tests/assembly/test_retain_autoreleased/expected/apple-armv7s.s diff --git a/tests/assembly/test_retain_autoreleased/expected/i386-apple-ios.s b/tests/assembly/test_retain_autoreleased/expected/apple-x86.s similarity index 100% rename from tests/assembly/test_retain_autoreleased/expected/i386-apple-ios.s rename to tests/assembly/test_retain_autoreleased/expected/apple-x86.s diff --git a/tests/assembly/test_retain_autoreleased/expected/x86_64-apple-darwin.s b/tests/assembly/test_retain_autoreleased/expected/apple-x86_64.s similarity index 100% rename from tests/assembly/test_retain_autoreleased/expected/x86_64-apple-darwin.s rename to tests/assembly/test_retain_autoreleased/expected/apple-x86_64.s diff --git a/tests/assembly/test_retain_autoreleased/expected/i686-apple-darwin.s b/tests/assembly/test_retain_autoreleased/expected/i686-apple-darwin.s deleted file mode 100644 index b2ebee241..000000000 --- a/tests/assembly/test_retain_autoreleased/expected/i686-apple-darwin.s +++ /dev/null @@ -1,25 +0,0 @@ - .section __TEXT,__text,regular,pure_instructions - .intel_syntax noprefix - .globl _handle - .p2align 4, 0x90 -_handle: - push ebp - mov ebp, esp - sub esp, 8 - mov eax, dword ptr [ebp + 8] - mov ecx, dword ptr [ebp + 12] - mov dword ptr [esp + 4], ecx - mov dword ptr [esp], eax - call _objc_msgSend - ## InlineAsm Start - - mov ebp, ebp - - ## InlineAsm End - mov dword ptr [esp], eax - call _objc_retainAutoreleasedReturnValue - add esp, 8 - pop ebp - ret - -.subsections_via_symbols diff --git a/tests/assembly/test_retain_autoreleased/expected/x86_64-apple-ios.s b/tests/assembly/test_retain_autoreleased/expected/x86_64-apple-ios.s deleted file mode 100644 index bdec662f9..000000000 --- a/tests/assembly/test_retain_autoreleased/expected/x86_64-apple-ios.s +++ /dev/null @@ -1,19 +0,0 @@ - .section __TEXT,__text,regular,pure_instructions - .intel_syntax noprefix - .globl _handle - .p2align 4, 0x90 -_handle: - push rbp - mov rbp, rsp - call _objc_msgSend - mov rdi, rax - call _objc_retainAutoreleasedReturnValue - ## InlineAsm Start - - nop - - ## InlineAsm End - pop rbp - ret - -.subsections_via_symbols diff --git a/tests/src/bin/test_assembly.rs b/tests/src/bin/test_assembly.rs index ae7549b08..66d8032a7 100644 --- a/tests/src/bin/test_assembly.rs +++ b/tests/src/bin/test_assembly.rs @@ -5,7 +5,6 @@ use cargo_metadata::Message; use std::env; use std::env::args; -use std::fmt::Write; use std::fs; use std::io; use std::path::Path; @@ -23,13 +22,10 @@ fn strip_section(data: &str, section: &str) -> String { let mut in_removed_section = false; for line in data.lines() { // This only works for the __LLVM sections we're interested in - if line == "" { - in_removed_section = false; - } if line.trim().starts_with(".section") { if line.contains(section) { in_removed_section = true; - write!(res, "; Stripped {section} section\n").unwrap(); + println!("Stripped {section} section"); } else { in_removed_section = false; } @@ -38,6 +34,9 @@ fn strip_section(data: &str, section: &str) -> String { res.push_str(line); res.push('\n'); } + if line == "" { + in_removed_section = false; + } } res } @@ -88,6 +87,7 @@ fn main() { .arg("--message-format=json-render-diagnostics") .arg("--") .arg("--emit=asm") + // .arg("-Zplt=no") .arg("-Cllvm-args=--x86-asm-syntax=intel") .stdout(Stdio::piped()) .stderr(Stdio::inherit()) @@ -123,8 +123,17 @@ fn main() { .unwrap_or(host); println!("Target {target}."); + let architecture = target.split_once("-").unwrap().0; + let architecture = if matches!(architecture, "i386" | "i686") { + "x86" + } else { + architecture + }; + println!("Architecture {architecture}."); - let expected_file = package_path.join("expected").join(format!("{target}.s")); + let expected_file = package_path + .join("expected") + .join(format!("apple-{architecture}.s")); let actual = read_assembly(&artifact).unwrap(); if should_overwrite { @@ -135,7 +144,10 @@ fn main() { panic!("Expected and actual did not match."); } } else { - panic!("Missing assembly output for target {}:\n{}", target, actual); + panic!( + "Missing assembly output for architecture {}:\n{}", + architecture, actual + ); } } }