diff --git a/crates/objc2/src/__macro_helpers/os_version.rs b/crates/objc2/src/__macro_helpers/os_version.rs index 0b1655f06..fa7e6474b 100644 --- a/crates/objc2/src/__macro_helpers/os_version.rs +++ b/crates/objc2/src/__macro_helpers/os_version.rs @@ -150,6 +150,20 @@ impl OSVersion { let (major, minor, patch) = (self.major as u32, self.minor as u32, self.patch as u32); (major << 16) | (minor << 8) | patch } + + /// Construct the version from a `u32`. + #[inline] + pub const fn from_u32(version: u32) -> Self { + // See comments in `OSVersion`, this should compile down to nothing. + let major = (version >> 16) as u16; + let minor = (version >> 8) as u8; + let patch = version as u8; + Self { + major, + minor, + patch, + } + } } impl PartialEq for OSVersion { @@ -402,4 +416,14 @@ mod tests { assert!(available!(tvos = 1.2, ..)); } } + + #[test] + fn test_u32_roundtrip() { + let version = OSVersion { + major: 1000, + minor: 100, + patch: 200, + }; + assert_eq!(version, OSVersion::from_u32(version.to_u32())); + } } diff --git a/crates/objc2/src/__macro_helpers/os_version/apple.rs b/crates/objc2/src/__macro_helpers/os_version/apple.rs index f57ef07ed..ef88e7f23 100644 --- a/crates/objc2/src/__macro_helpers/os_version/apple.rs +++ b/crates/objc2/src/__macro_helpers/os_version/apple.rs @@ -1,8 +1,9 @@ use core::ffi::{c_char, c_uint, c_void}; +use core::num::NonZeroU32; use core::ptr; +use core::sync::atomic::{AtomicU32, Ordering}; use std::os::unix::ffi::OsStrExt; use std::path::PathBuf; -use std::sync::OnceLock; use super::OSVersion; use crate::rc::{autoreleasepool, Allocated, Retained}; @@ -97,14 +98,25 @@ pub(crate) const DEPLOYMENT_TARGET: OSVersion = { pub(crate) fn current_version() -> OSVersion { // Cache the lookup for performance. // - // TODO: Maybe just use atomics, a `Once` seems like overkill, it doesn't - // matter if two threads end up racing to read the version? - static CURRENT_VERSION: OnceLock = OnceLock::new(); + // We assume that 0.0.0 is never gonna be a valid version, + // and use that as our sentinel value. + static CURRENT_VERSION: AtomicU32 = AtomicU32::new(0); - *CURRENT_VERSION.get_or_init(lookup_version) + // We use relaxed atomics, it doesn't matter if two threads end up racing + // to read or write the version. + let version = CURRENT_VERSION.load(Ordering::Relaxed); + OSVersion::from_u32(if version == 0 { + // TODO: Consider using `std::panic::abort_unwind` here for code-size? + let version = lookup_version().get(); + CURRENT_VERSION.store(version, Ordering::Relaxed); + version + } else { + version + }) } -fn lookup_version() -> OSVersion { +#[cold] +fn lookup_version() -> NonZeroU32 { // Since macOS 10.15, libSystem has provided the undocumented // `_availability_version_check` via `libxpc` for doing this version // lookup, though it's usage may be a bit dangerous, see: @@ -114,7 +126,10 @@ fn lookup_version() -> OSVersion { // So instead, we use the safer approach of reading from `sysctl`, and // if that fails, we fall back to the property list (this is what // `_availability_version_check` does internally). - version_from_sysctl().unwrap_or_else(version_from_plist) + let version = version_from_sysctl().unwrap_or_else(version_from_plist); + // Use `NonZeroU32` to try to make it clearer to the optimizer that this + // will never return 0. + NonZeroU32::new(version.to_u32()).expect("version cannot be 0.0.0") } /// Read the version from `kern.osproductversion` or `kern.iossupportversion`. diff --git a/crates/test-assembly/crates/test_available/expected/apple-aarch64.s b/crates/test-assembly/crates/test_available/expected/apple-aarch64.s index 4f6719ec8..7491d52cb 100644 --- a/crates/test-assembly/crates/test_available/expected/apple-aarch64.s +++ b/crates/test-assembly/crates/test_available/expected/apple-aarch64.s @@ -1,85 +1,4 @@ .section __TEXT,__text,regular,pure_instructions - .p2align 2 -SYM(>::initialize::<>::get_or_init::{closure#0}, !>, 0): -Lloh0: - adrp x0, SYM(objc2::__macro_helpers::os_version::apple::current_version::CURRENT_VERSION::GENERATED_ID, 0)@GOTPAGE -Lloh1: - ldr x0, [x0, SYM(objc2::__macro_helpers::os_version::apple::current_version::CURRENT_VERSION::GENERATED_ID, 0)@GOTPAGEOFF] - ldapr x8, [x0] - cmp x8, #3 - b.ne LBB0_2 - ret -LBB0_2: - sub sp, sp, #48 - stp x29, x30, [sp, #32] - add x29, sp, #32 - add x8, x0, #8 - sub x9, x29, #1 - stp x8, x9, [sp] - mov x8, sp - str x8, [sp, #16] -Lloh2: - adrp x3, l_anon.[ID].0@PAGE -Lloh3: - add x3, x3, l_anon.[ID].0@PAGEOFF -Lloh4: - adrp x4, l_anon.[ID].2@PAGE -Lloh5: - add x4, x4, l_anon.[ID].2@PAGEOFF - add x2, sp, #16 - mov w1, #1 - bl SYM(std::sys::sync::once::queue::Once::call::GENERATED_ID, 0) - ldp x29, x30, [sp, #32] - add sp, sp, #48 - ret - .loh AdrpLdrGot Lloh0, Lloh1 - .loh AdrpAdd Lloh4, Lloh5 - .loh AdrpAdd Lloh2, Lloh3 - - .p2align 2 -SYM(::call_once_force::<>::initialize<>::get_or_init::{closure#0}, !>::{closure#0}>::{closure#0}, 0): - stp x20, x19, [sp, #-32]! - stp x29, x30, [sp, #16] - add x29, sp, #16 - ldr x8, [x0] - ldr x19, [x8] - str xzr, [x8] - cbz x19, LBB1_2 - bl SYM(objc2::__macro_helpers::os_version::apple::lookup_version::GENERATED_ID, 0) - str w0, [x19] - ldp x29, x30, [sp, #16] - ldp x20, x19, [sp], #32 - ret -LBB1_2: -Lloh6: - adrp x0, l_anon.[ID].3@PAGE -Lloh7: - add x0, x0, l_anon.[ID].3@PAGEOFF - bl SYM(core::option::unwrap_failed::GENERATED_ID, 0) - .loh AdrpAdd Lloh6, Lloh7 - - .p2align 2 -SYM(<::call_once_force<>::initialize<>::get_or_init::{closure#0}, !>::{closure#0}>::{closure#0} as core[CRATE_ID]::ops::function::FnOnce<(&std[CRATE_ID]::sync::once::OnceState,)>>::call_once::{shim:vtable#0}, 0): - stp x20, x19, [sp, #-32]! - stp x29, x30, [sp, #16] - add x29, sp, #16 - ldr x8, [x0] - ldr x19, [x8] - str xzr, [x8] - cbz x19, LBB2_2 - bl SYM(objc2::__macro_helpers::os_version::apple::lookup_version::GENERATED_ID, 0) - str w0, [x19] - ldp x29, x30, [sp, #16] - ldp x20, x19, [sp], #32 - ret -LBB2_2: -Lloh8: - adrp x0, l_anon.[ID].3@PAGE -Lloh9: - add x0, x0, l_anon.[ID].3@PAGEOFF - bl SYM(core::option::unwrap_failed::GENERATED_ID, 0) - .loh AdrpAdd Lloh8, Lloh9 - .globl _always .p2align 2 _always: @@ -104,24 +23,24 @@ _high: stp x20, x19, [sp, #-32]! stp x29, x30, [sp, #16] add x29, sp, #16 -Lloh10: +Lloh0: adrp x19, SYM(objc2::__macro_helpers::os_version::apple::current_version::CURRENT_VERSION::GENERATED_ID, 0)@GOTPAGE -Lloh11: +Lloh1: ldr x19, [x19, SYM(objc2::__macro_helpers::os_version::apple::current_version::CURRENT_VERSION::GENERATED_ID, 0)@GOTPAGEOFF] - ldapr x8, [x19] - cmp x8, #3 - b.ne LBB6_2 -LBB6_1: - ldrh w8, [x19, #10] + ldr w0, [x19] + cbz w0, LBB3_2 +LBB3_1: + lsr w8, w0, #16 cmp w8, #14 cset w0, hi ldp x29, x30, [sp, #16] ldp x20, x19, [sp], #32 ret -LBB6_2: - bl SYM(>::initialize::<>::get_or_init::{closure#0}, !>, 0) - b LBB6_1 - .loh AdrpLdrGot Lloh10, Lloh11 +LBB3_2: + bl SYM(objc2::__macro_helpers::os_version::apple::lookup_version::GENERATED_ID, 0) + str w0, [x19] + b LBB3_1 + .loh AdrpLdrGot Lloh0, Lloh1 .globl _only_ios .p2align 2 @@ -135,56 +54,34 @@ _two_checks: stp x20, x19, [sp, #-32]! stp x29, x30, [sp, #16] add x29, sp, #16 -Lloh12: - adrp x19, SYM(objc2::__macro_helpers::os_version::apple::current_version::CURRENT_VERSION::GENERATED_ID, 0)@GOTPAGE -Lloh13: - ldr x19, [x19, SYM(objc2::__macro_helpers::os_version::apple::current_version::CURRENT_VERSION::GENERATED_ID, 0)@GOTPAGEOFF] - ldapr x8, [x19] - cmp x8, #3 - b.ne LBB8_3 - ldrh w20, [x19, #10] - ldapr x8, [x19] - cmp x8, #3 - b.ne LBB8_4 -LBB8_2: - cmp w20, #13 - ldrh w8, [x19, #10] - ccmp w8, #14, #0, hi +Lloh2: + adrp x20, SYM(objc2::__macro_helpers::os_version::apple::current_version::CURRENT_VERSION::GENERATED_ID, 0)@GOTPAGE +Lloh3: + ldr x20, [x20, SYM(objc2::__macro_helpers::os_version::apple::current_version::CURRENT_VERSION::GENERATED_ID, 0)@GOTPAGEOFF] + ldr w19, [x20] + cbz w19, LBB5_3 + ldr w0, [x20] + cbz w0, LBB5_4 +LBB5_2: + lsr w8, w19, #17 + cmp w8, #6 + mov w8, #917503 + add w8, w8, #16, lsl #12 + ccmp w0, w8, #0, hi cset w0, hi ldp x29, x30, [sp, #16] ldp x20, x19, [sp], #32 ret -LBB8_3: - bl SYM(>::initialize::<>::get_or_init::{closure#0}, !>, 0) - ldrh w20, [x19, #10] - ldapr x8, [x19] - cmp x8, #3 - b.eq LBB8_2 -LBB8_4: - bl SYM(>::initialize::<>::get_or_init::{closure#0}, !>, 0) - b LBB8_2 - .loh AdrpLdrGot Lloh12, Lloh13 - - .section __DATA,__const - .p2align 3, 0x0 -l_anon.[ID].0: - .asciz "\000\000\000\000\000\000\000\000\b\000\000\000\000\000\000\000\b\000\000\000\000\000\000" - .quad SYM(<::call_once_force<>::initialize<>::get_or_init::{closure#0}, !>::{closure#0}>::{closure#0} as core[CRATE_ID]::ops::function::FnOnce<(&std[CRATE_ID]::sync::once::OnceState,)>>::call_once::{shim:vtable#0}, 0) - .quad SYM(::call_once_force::<>::initialize<>::get_or_init::{closure#0}, !>::{closure#0}>::{closure#0}, 0) - - .section __TEXT,__const -l_anon.[ID].1: - .ascii "$RUSTC/library/std/src/sync/once.rs" - - .section __DATA,__const - .p2align 3, 0x0 -l_anon.[ID].2: - .quad l_anon.[ID].1 - .asciz "p\000\000\000\000\000\000\000\331\000\000\000\024\000\000" - - .p2align 3, 0x0 -l_anon.[ID].3: - .quad l_anon.[ID].1 - .asciz "p\000\000\000\000\000\000\000\331\000\000\0001\000\000" +LBB5_3: + bl SYM(objc2::__macro_helpers::os_version::apple::lookup_version::GENERATED_ID, 0) + mov x19, x0 + str w0, [x20] + ldr w0, [x20] + cbnz w0, LBB5_2 +LBB5_4: + bl SYM(objc2::__macro_helpers::os_version::apple::lookup_version::GENERATED_ID, 0) + str w0, [x20] + b LBB5_2 + .loh AdrpLdrGot Lloh2, Lloh3 .subsections_via_symbols diff --git a/crates/test-assembly/crates/test_available/expected/apple-armv7s.s b/crates/test-assembly/crates/test_available/expected/apple-armv7s.s index 309aafe4f..12bdebc57 100644 --- a/crates/test-assembly/crates/test_available/expected/apple-armv7s.s +++ b/crates/test-assembly/crates/test_available/expected/apple-armv7s.s @@ -1,91 +1,5 @@ .section __TEXT,__text,regular,pure_instructions .syntax unified - .p2align 2 - .code 32 -SYM(>::initialize::<>::get_or_init::{closure#0}, !>, 0): - ldr r0, LCPI0_0 -LPC0_0: - ldr r0, [pc, r0] - ldr r1, [r0] - dmb ish - cmp r1, #3 - bxeq lr -LBB0_1: - push {r2, r3, r4, r5, r6, r7, lr} - add r7, sp, #20 - add r1, r0, #4 - str r1, [sp, #4] - sub r1, r7, #1 - str r1, [sp, #8] - add r1, sp, #4 - str r1, [r7, #-8] - ldr r1, LCPI0_1 -LPC0_1: - add r1, pc, r1 - ldr r3, LCPI0_2 -LPC0_2: - add r3, pc, r3 - str r1, [sp] - sub r2, r7, #8 - mov r1, #1 - bl SYM(std::sys::sync::once::queue::Once::call::GENERATED_ID, 0) - mov sp, r7 - pop {r7, lr} - bx lr - .p2align 2 - .data_region -LCPI0_0: - .long LSYM(objc2::__macro_helpers::os_version::apple::current_version::CURRENT_VERSION::GENERATED_ID, 0)$non_lazy_ptr-(LPC0_0+8) -LCPI0_1: - .long l_anon.[ID].2-(LPC0_1+8) -LCPI0_2: - .long l_anon.[ID].0-(LPC0_2+8) - .end_data_region - - .p2align 2 - .code 32 -SYM(::call_once_force::<>::initialize<>::get_or_init::{closure#0}, !>::{closure#0}>::{closure#0}, 0): - push {r4, r7, lr} - add r7, sp, #4 - ldr r0, [r0] - ldr r4, [r0] - mov r1, #0 - str r1, [r0] - cmp r4, #0 - beq LBB1_2 - bl SYM(objc2::__macro_helpers::os_version::apple::lookup_version::GENERATED_ID, 0) - str r0, [r4] - pop {r4, r7, pc} -LBB1_2: - movw r0, :lower16:(l_anon.[ID].3-(LPC1_0+8)) - movt r0, :upper16:(l_anon.[ID].3-(LPC1_0+8)) -LPC1_0: - add r0, pc, r0 - mov lr, pc - b SYM(core::option::unwrap_failed::GENERATED_ID, 0) - - .p2align 2 - .code 32 -SYM(<::call_once_force<>::initialize<>::get_or_init::{closure#0}, !>::{closure#0}>::{closure#0} as core[CRATE_ID]::ops::function::FnOnce<(&std[CRATE_ID]::sync::once::OnceState,)>>::call_once::{shim:vtable#0}, 0): - push {r4, r7, lr} - add r7, sp, #4 - ldr r0, [r0] - ldr r4, [r0] - mov r1, #0 - str r1, [r0] - cmp r4, #0 - beq LBB2_2 - bl SYM(objc2::__macro_helpers::os_version::apple::lookup_version::GENERATED_ID, 0) - str r0, [r4] - pop {r4, r7, pc} -LBB2_2: - movw r0, :lower16:(l_anon.[ID].3-(LPC2_0+8)) - movt r0, :upper16:(l_anon.[ID].3-(LPC2_0+8)) -LPC2_0: - add r0, pc, r0 - mov lr, pc - b SYM(core::option::unwrap_failed::GENERATED_ID, 0) - .globl _always .p2align 2 .code 32 @@ -113,23 +27,23 @@ _low: _high: push {r4, r7, lr} add r7, sp, #4 - movw r4, :lower16:(LSYM(objc2::__macro_helpers::os_version::apple::current_version::CURRENT_VERSION::GENERATED_ID, 0)$non_lazy_ptr-(LPC6_0+8)) - movt r4, :upper16:(LSYM(objc2::__macro_helpers::os_version::apple::current_version::CURRENT_VERSION::GENERATED_ID, 0)$non_lazy_ptr-(LPC6_0+8)) -LPC6_0: + movw r4, :lower16:(LSYM(objc2::__macro_helpers::os_version::apple::current_version::CURRENT_VERSION::GENERATED_ID, 0)$non_lazy_ptr-(LPC3_0+8)) + movt r4, :upper16:(LSYM(objc2::__macro_helpers::os_version::apple::current_version::CURRENT_VERSION::GENERATED_ID, 0)$non_lazy_ptr-(LPC3_0+8)) +LPC3_0: ldr r4, [pc, r4] ldr r0, [r4] - dmb ish - cmp r0, #3 - bne LBB6_2 -LBB6_1: - ldrh r1, [r4, #6] + cmp r0, #0 + beq LBB3_2 +LBB3_1: + lsr r1, r0, #17 mov r0, #0 - cmp r1, #17 + cmp r1, #8 movwhi r0, #1 pop {r4, r7, pc} -LBB6_2: - bl SYM(>::initialize::<>::get_or_init::{closure#0}, !>, 0) - b LBB6_1 +LBB3_2: + bl SYM(objc2::__macro_helpers::os_version::apple::lookup_version::GENERATED_ID, 0) + str r0, [r4] + b LBB3_1 .globl _only_ios .p2align 2 @@ -144,58 +58,40 @@ _only_ios: _two_checks: push {r4, r5, r7, lr} add r7, sp, #8 - movw r4, :lower16:(LSYM(objc2::__macro_helpers::os_version::apple::current_version::CURRENT_VERSION::GENERATED_ID, 0)$non_lazy_ptr-(LPC8_0+8)) - movt r4, :upper16:(LSYM(objc2::__macro_helpers::os_version::apple::current_version::CURRENT_VERSION::GENERATED_ID, 0)$non_lazy_ptr-(LPC8_0+8)) -LPC8_0: - ldr r4, [pc, r4] - ldr r0, [r4] - dmb ish - cmp r0, #3 - bne LBB8_3 -LBB8_1: - ldrh r5, [r4, #6] - ldr r0, [r4] - dmb ish - cmp r0, #3 - bne LBB8_4 -LBB8_2: - mov r0, #0 - cmp r5, #16 + movw r5, :lower16:(LSYM(objc2::__macro_helpers::os_version::apple::current_version::CURRENT_VERSION::GENERATED_ID, 0)$non_lazy_ptr-(LPC5_0+8)) + movt r5, :upper16:(LSYM(objc2::__macro_helpers::os_version::apple::current_version::CURRENT_VERSION::GENERATED_ID, 0)$non_lazy_ptr-(LPC5_0+8)) +LPC5_0: + ldr r5, [pc, r5] + ldr r4, [r5] + cmp r4, #0 + beq LBB5_3 + ldr r0, [r5] + cmp r0, #0 + beq LBB5_4 +LBB5_2: + lsr r1, r4, #16 + mov r2, #0 + cmp r1, #16 mov r1, #0 movwhi r1, #1 - ldrh r2, [r4, #6] - cmp r2, #17 - movwhi r0, #1 - and r0, r1, r0 + movw r3, #65535 + movt r3, #16 + orr r3, r3, #65536 + cmp r0, r3 + movwhi r2, #1 + and r0, r1, r2 pop {r4, r5, r7, pc} -LBB8_3: - bl SYM(>::initialize::<>::get_or_init::{closure#0}, !>, 0) - b LBB8_1 -LBB8_4: - bl SYM(>::initialize::<>::get_or_init::{closure#0}, !>, 0) - b LBB8_2 - - .section __DATA,__const - .p2align 2, 0x0 -l_anon.[ID].0: - .asciz "\000\000\000\000\004\000\000\000\004\000\000" - .long SYM(<::call_once_force<>::initialize<>::get_or_init::{closure#0}, !>::{closure#0}>::{closure#0} as core[CRATE_ID]::ops::function::FnOnce<(&std[CRATE_ID]::sync::once::OnceState,)>>::call_once::{shim:vtable#0}, 0) - .long SYM(::call_once_force::<>::initialize<>::get_or_init::{closure#0}, !>::{closure#0}>::{closure#0}, 0) - - .section __TEXT,__const -l_anon.[ID].1: - .ascii "$RUSTC/library/std/src/sync/once.rs" - - .section __DATA,__const - .p2align 2, 0x0 -l_anon.[ID].2: - .long l_anon.[ID].1 - .asciz "p\000\000\000\331\000\000\000\024\000\000" - - .p2align 2, 0x0 -l_anon.[ID].3: - .long l_anon.[ID].1 - .asciz "p\000\000\000\331\000\000\0001\000\000" +LBB5_3: + bl SYM(objc2::__macro_helpers::os_version::apple::lookup_version::GENERATED_ID, 0) + mov r4, r0 + str r0, [r5] + ldr r0, [r5] + cmp r0, #0 + bne LBB5_2 +LBB5_4: + bl SYM(objc2::__macro_helpers::os_version::apple::lookup_version::GENERATED_ID, 0) + str r0, [r5] + b LBB5_2 .section __DATA,__nl_symbol_ptr,non_lazy_symbol_pointers .p2align 2, 0x0 diff --git a/crates/test-assembly/crates/test_available/expected/apple-old-x86.s b/crates/test-assembly/crates/test_available/expected/apple-old-x86.s index b5cd3c8d3..69fb84aaa 100644 --- a/crates/test-assembly/crates/test_available/expected/apple-old-x86.s +++ b/crates/test-assembly/crates/test_available/expected/apple-old-x86.s @@ -1,94 +1,5 @@ .section __TEXT,__text,regular,pure_instructions .intel_syntax noprefix -SYM(>::initialize::<>::get_or_init::{closure#0}, !>, 0): - push ebp - mov ebp, esp - push esi - sub esp, 20 - call L0$pb -L0$pb: - pop ecx - mov eax, dword ptr [ecx + LSYM(objc2::__macro_helpers::os_version::apple::current_version::CURRENT_VERSION::GENERATED_ID, 0)$non_lazy_ptr-L0$pb] - mov edx, dword ptr [eax] - cmp edx, 3 - jne LBB0_1 -LBB0_2: - add esp, 20 - pop esi - pop ebp - ret -LBB0_1: - lea edx, [eax + 4] - lea esi, [ebp - 20] - mov dword ptr [esi], edx - lea edx, [ebp - 5] - mov dword ptr [esi + 4], edx - lea edx, [ebp - 12] - mov dword ptr [edx], esi - sub esp, 12 - lea esi, [ecx + l_anon.[ID].2-L0$pb] - lea ecx, [ecx + l_anon.[ID].0-L0$pb] - push esi - push ecx - push edx - push 1 - push eax - call SYM(std::sys::sync::once::queue::Once::call::GENERATED_ID, 0) - add esp, 32 - jmp LBB0_2 - - .p2align 4, 0x90 -SYM(::call_once_force::<>::initialize<>::get_or_init::{closure#0}, !>::{closure#0}>::{closure#0}, 0): - push ebp - mov ebp, esp - push esi - push eax - call L1$pb -L1$pb: - pop eax - mov ecx, dword ptr [ebp + 8] - mov ecx, dword ptr [ecx] - mov esi, dword ptr [ecx] - mov dword ptr [ecx], 0 - test esi, esi - je LBB1_2 - call SYM(objc2::__macro_helpers::os_version::apple::lookup_version::GENERATED_ID, 0) - mov dword ptr [esi], eax - add esp, 4 - pop esi - pop ebp - ret -LBB1_2: - lea eax, [eax + l_anon.[ID].3-L1$pb] - mov dword ptr [esp], eax - call SYM(core::option::unwrap_failed::GENERATED_ID, 0) - - .p2align 4, 0x90 -SYM(<::call_once_force<>::initialize<>::get_or_init::{closure#0}, !>::{closure#0}>::{closure#0} as core[CRATE_ID]::ops::function::FnOnce<(&std[CRATE_ID]::sync::once::OnceState,)>>::call_once::{shim:vtable#0}, 0): - push ebp - mov ebp, esp - push esi - push eax - call L2$pb -L2$pb: - pop eax - mov ecx, dword ptr [ebp + 8] - mov ecx, dword ptr [ecx] - mov esi, dword ptr [ecx] - mov dword ptr [ecx], 0 - test esi, esi - je LBB2_2 - call SYM(objc2::__macro_helpers::os_version::apple::lookup_version::GENERATED_ID, 0) - mov dword ptr [esi], eax - add esp, 4 - pop esi - pop ebp - ret -LBB2_2: - lea eax, [eax + l_anon.[ID].3-L2$pb] - mov dword ptr [esp], eax - call SYM(core::option::unwrap_failed::GENERATED_ID, 0) - .globl _always .p2align 4, 0x90 _always: @@ -123,23 +34,24 @@ _high: mov ebp, esp push esi push eax - call L6$pb -L6$pb: + call L3$pb +L3$pb: pop eax - mov esi, dword ptr [eax + LSYM(objc2::__macro_helpers::os_version::apple::current_version::CURRENT_VERSION::GENERATED_ID, 0)$non_lazy_ptr-L6$pb] + mov esi, dword ptr [eax + LSYM(objc2::__macro_helpers::os_version::apple::current_version::CURRENT_VERSION::GENERATED_ID, 0)$non_lazy_ptr-L3$pb] mov eax, dword ptr [esi] - cmp eax, 3 - jne LBB6_1 -LBB6_2: - cmp word ptr [esi + 6], 15 + test eax, eax + je LBB3_1 +LBB3_2: + cmp eax, 983040 setae al add esp, 4 pop esi pop ebp ret -LBB6_1: - call SYM(>::initialize::<>::get_or_init::{closure#0}, !>, 0) - jmp LBB6_2 +LBB3_1: + call SYM(objc2::__macro_helpers::os_version::apple::lookup_version::GENERATED_ID, 0) + mov dword ptr [esi], eax + jmp LBB3_2 .globl _only_ios .p2align 4, 0x90 @@ -157,58 +69,37 @@ _two_checks: mov ebp, esp push edi push esi - call L8$pb -L8$pb: + call L5$pb +L5$pb: pop eax - mov esi, dword ptr [eax + LSYM(objc2::__macro_helpers::os_version::apple::current_version::CURRENT_VERSION::GENERATED_ID, 0)$non_lazy_ptr-L8$pb] - mov eax, dword ptr [esi] - cmp eax, 3 - jne LBB8_1 - movzx edi, word ptr [esi + 6] - mov eax, dword ptr [esi] - cmp eax, 3 - jne LBB8_3 -LBB8_4: - cmp di, 14 + mov edi, dword ptr [eax + LSYM(objc2::__macro_helpers::os_version::apple::current_version::CURRENT_VERSION::GENERATED_ID, 0)$non_lazy_ptr-L5$pb] + mov esi, dword ptr [edi] + test esi, esi + je LBB5_1 + mov eax, dword ptr [edi] + test eax, eax + je LBB5_3 +LBB5_4: + cmp esi, 917504 setae cl - cmp word ptr [esi + 6], 15 + cmp eax, 983040 setae al and al, cl pop esi pop edi pop ebp ret -LBB8_1: - call SYM(>::initialize::<>::get_or_init::{closure#0}, !>, 0) - movzx edi, word ptr [esi + 6] - mov eax, dword ptr [esi] - cmp eax, 3 - je LBB8_4 -LBB8_3: - call SYM(>::initialize::<>::get_or_init::{closure#0}, !>, 0) - jmp LBB8_4 - - .section __DATA,__const - .p2align 2, 0x0 -l_anon.[ID].0: - .asciz "\000\000\000\000\004\000\000\000\004\000\000" - .long SYM(<::call_once_force<>::initialize<>::get_or_init::{closure#0}, !>::{closure#0}>::{closure#0} as core[CRATE_ID]::ops::function::FnOnce<(&std[CRATE_ID]::sync::once::OnceState,)>>::call_once::{shim:vtable#0}, 0) - .long SYM(::call_once_force::<>::initialize<>::get_or_init::{closure#0}, !>::{closure#0}>::{closure#0}, 0) - - .section __TEXT,__const -l_anon.[ID].1: - .ascii "$RUSTC/library/std/src/sync/once.rs" - - .section __DATA,__const - .p2align 2, 0x0 -l_anon.[ID].2: - .long l_anon.[ID].1 - .asciz "p\000\000\000\331\000\000\000\024\000\000" - - .p2align 2, 0x0 -l_anon.[ID].3: - .long l_anon.[ID].1 - .asciz "p\000\000\000\331\000\000\0001\000\000" +LBB5_1: + call SYM(objc2::__macro_helpers::os_version::apple::lookup_version::GENERATED_ID, 0) + mov esi, eax + mov dword ptr [edi], eax + mov eax, dword ptr [edi] + test eax, eax + jne LBB5_4 +LBB5_3: + call SYM(objc2::__macro_helpers::os_version::apple::lookup_version::GENERATED_ID, 0) + mov dword ptr [edi], eax + jmp LBB5_4 .section __IMPORT,__pointers,non_lazy_symbol_pointers LSYM(objc2::__macro_helpers::os_version::apple::current_version::CURRENT_VERSION::GENERATED_ID, 0)$non_lazy_ptr: diff --git a/crates/test-assembly/crates/test_available/expected/apple-x86.s b/crates/test-assembly/crates/test_available/expected/apple-x86.s index eeb248c01..d275f2378 100644 --- a/crates/test-assembly/crates/test_available/expected/apple-x86.s +++ b/crates/test-assembly/crates/test_available/expected/apple-x86.s @@ -1,94 +1,5 @@ .section __TEXT,__text,regular,pure_instructions .intel_syntax noprefix -SYM(>::initialize::<>::get_or_init::{closure#0}, !>, 0): - push ebp - mov ebp, esp - push esi - sub esp, 20 - call L0$pb -L0$pb: - pop ecx - mov eax, dword ptr [ecx + LSYM(objc2::__macro_helpers::os_version::apple::current_version::CURRENT_VERSION::GENERATED_ID, 0)$non_lazy_ptr-L0$pb] - mov edx, dword ptr [eax] - cmp edx, 3 - jne LBB0_1 -LBB0_2: - add esp, 20 - pop esi - pop ebp - ret -LBB0_1: - lea edx, [eax + 4] - lea esi, [ebp - 20] - mov dword ptr [esi], edx - lea edx, [ebp - 5] - mov dword ptr [esi + 4], edx - lea edx, [ebp - 12] - mov dword ptr [edx], esi - sub esp, 12 - lea esi, [ecx + l_anon.[ID].2-L0$pb] - lea ecx, [ecx + l_anon.[ID].0-L0$pb] - push esi - push ecx - push edx - push 1 - push eax - call SYM(std::sys::sync::once::queue::Once::call::GENERATED_ID, 0) - add esp, 32 - jmp LBB0_2 - - .p2align 4, 0x90 -SYM(::call_once_force::<>::initialize<>::get_or_init::{closure#0}, !>::{closure#0}>::{closure#0}, 0): - push ebp - mov ebp, esp - push esi - push eax - call L1$pb -L1$pb: - pop eax - mov ecx, dword ptr [ebp + 8] - mov ecx, dword ptr [ecx] - mov esi, dword ptr [ecx] - mov dword ptr [ecx], 0 - test esi, esi - je LBB1_2 - call SYM(objc2::__macro_helpers::os_version::apple::lookup_version::GENERATED_ID, 0) - mov dword ptr [esi], eax - add esp, 4 - pop esi - pop ebp - ret -LBB1_2: - lea eax, [eax + l_anon.[ID].3-L1$pb] - mov dword ptr [esp], eax - call SYM(core::option::unwrap_failed::GENERATED_ID, 0) - - .p2align 4, 0x90 -SYM(<::call_once_force<>::initialize<>::get_or_init::{closure#0}, !>::{closure#0}>::{closure#0} as core[CRATE_ID]::ops::function::FnOnce<(&std[CRATE_ID]::sync::once::OnceState,)>>::call_once::{shim:vtable#0}, 0): - push ebp - mov ebp, esp - push esi - push eax - call L2$pb -L2$pb: - pop eax - mov ecx, dword ptr [ebp + 8] - mov ecx, dword ptr [ecx] - mov esi, dword ptr [ecx] - mov dword ptr [ecx], 0 - test esi, esi - je LBB2_2 - call SYM(objc2::__macro_helpers::os_version::apple::lookup_version::GENERATED_ID, 0) - mov dword ptr [esi], eax - add esp, 4 - pop esi - pop ebp - ret -LBB2_2: - lea eax, [eax + l_anon.[ID].3-L2$pb] - mov dword ptr [esp], eax - call SYM(core::option::unwrap_failed::GENERATED_ID, 0) - .globl _always .p2align 4, 0x90 _always: @@ -123,23 +34,24 @@ _high: mov ebp, esp push esi push eax - call L6$pb -L6$pb: + call L3$pb +L3$pb: pop eax - mov esi, dword ptr [eax + LSYM(objc2::__macro_helpers::os_version::apple::current_version::CURRENT_VERSION::GENERATED_ID, 0)$non_lazy_ptr-L6$pb] + mov esi, dword ptr [eax + LSYM(objc2::__macro_helpers::os_version::apple::current_version::CURRENT_VERSION::GENERATED_ID, 0)$non_lazy_ptr-L3$pb] mov eax, dword ptr [esi] - cmp eax, 3 - jne LBB6_1 -LBB6_2: - cmp word ptr [esi + 6], 18 + test eax, eax + je LBB3_1 +LBB3_2: + cmp eax, 1179648 setae al add esp, 4 pop esi pop ebp ret -LBB6_1: - call SYM(>::initialize::<>::get_or_init::{closure#0}, !>, 0) - jmp LBB6_2 +LBB3_1: + call SYM(objc2::__macro_helpers::os_version::apple::lookup_version::GENERATED_ID, 0) + mov dword ptr [esi], eax + jmp LBB3_2 .globl _only_ios .p2align 4, 0x90 @@ -157,58 +69,37 @@ _two_checks: mov ebp, esp push edi push esi - call L8$pb -L8$pb: + call L5$pb +L5$pb: pop eax - mov esi, dword ptr [eax + LSYM(objc2::__macro_helpers::os_version::apple::current_version::CURRENT_VERSION::GENERATED_ID, 0)$non_lazy_ptr-L8$pb] - mov eax, dword ptr [esi] - cmp eax, 3 - jne LBB8_1 - movzx edi, word ptr [esi + 6] - mov eax, dword ptr [esi] - cmp eax, 3 - jne LBB8_3 -LBB8_4: - cmp di, 17 + mov edi, dword ptr [eax + LSYM(objc2::__macro_helpers::os_version::apple::current_version::CURRENT_VERSION::GENERATED_ID, 0)$non_lazy_ptr-L5$pb] + mov esi, dword ptr [edi] + test esi, esi + je LBB5_1 + mov eax, dword ptr [edi] + test eax, eax + je LBB5_3 +LBB5_4: + cmp esi, 1114112 setae cl - cmp word ptr [esi + 6], 18 + cmp eax, 1179648 setae al and al, cl pop esi pop edi pop ebp ret -LBB8_1: - call SYM(>::initialize::<>::get_or_init::{closure#0}, !>, 0) - movzx edi, word ptr [esi + 6] - mov eax, dword ptr [esi] - cmp eax, 3 - je LBB8_4 -LBB8_3: - call SYM(>::initialize::<>::get_or_init::{closure#0}, !>, 0) - jmp LBB8_4 - - .section __DATA,__const - .p2align 2, 0x0 -l_anon.[ID].0: - .asciz "\000\000\000\000\004\000\000\000\004\000\000" - .long SYM(<::call_once_force<>::initialize<>::get_or_init::{closure#0}, !>::{closure#0}>::{closure#0} as core[CRATE_ID]::ops::function::FnOnce<(&std[CRATE_ID]::sync::once::OnceState,)>>::call_once::{shim:vtable#0}, 0) - .long SYM(::call_once_force::<>::initialize<>::get_or_init::{closure#0}, !>::{closure#0}>::{closure#0}, 0) - - .section __TEXT,__const -l_anon.[ID].1: - .ascii "$RUSTC/library/std/src/sync/once.rs" - - .section __DATA,__const - .p2align 2, 0x0 -l_anon.[ID].2: - .long l_anon.[ID].1 - .asciz "p\000\000\000\331\000\000\000\024\000\000" - - .p2align 2, 0x0 -l_anon.[ID].3: - .long l_anon.[ID].1 - .asciz "p\000\000\000\331\000\000\0001\000\000" +LBB5_1: + call SYM(objc2::__macro_helpers::os_version::apple::lookup_version::GENERATED_ID, 0) + mov esi, eax + mov dword ptr [edi], eax + mov eax, dword ptr [edi] + test eax, eax + jne LBB5_4 +LBB5_3: + call SYM(objc2::__macro_helpers::os_version::apple::lookup_version::GENERATED_ID, 0) + mov dword ptr [edi], eax + jmp LBB5_4 .section __IMPORT,__pointers,non_lazy_symbol_pointers LSYM(objc2::__macro_helpers::os_version::apple::current_version::CURRENT_VERSION::GENERATED_ID, 0)$non_lazy_ptr: diff --git a/crates/test-assembly/crates/test_available/expected/apple-x86_64.s b/crates/test-assembly/crates/test_available/expected/apple-x86_64.s index a09c89aff..36c4ee1fe 100644 --- a/crates/test-assembly/crates/test_available/expected/apple-x86_64.s +++ b/crates/test-assembly/crates/test_available/expected/apple-x86_64.s @@ -1,73 +1,5 @@ .section __TEXT,__text,regular,pure_instructions .intel_syntax noprefix -SYM(>::initialize::<>::get_or_init::{closure#0}, !>, 0): - mov rdi, qword ptr [rip + SYM(objc2::__macro_helpers::os_version::apple::current_version::CURRENT_VERSION::GENERATED_ID, 0)@GOTPCREL] - mov rax, qword ptr [rdi] - cmp rax, 3 - jne LBB0_1 - ret -LBB0_1: - push rbp - mov rbp, rsp - sub rsp, 32 - lea rax, [rdi + 8] - lea rcx, [rbp - 32] - mov qword ptr [rcx], rax - lea rax, [rbp - 1] - mov qword ptr [rcx + 8], rax - lea rdx, [rbp - 16] - mov qword ptr [rdx], rcx - lea rcx, [rip + l_anon.[ID].0] - lea r8, [rip + l_anon.[ID].2] - push 1 - pop rsi - call SYM(std::sys::sync::once::queue::Once::call::GENERATED_ID, 0) - add rsp, 32 - pop rbp - ret - - .p2align 4, 0x90 -SYM(::call_once_force::<>::initialize<>::get_or_init::{closure#0}, !>::{closure#0}>::{closure#0}, 0): - push rbp - mov rbp, rsp - push rbx - push rax - mov rax, qword ptr [rdi] - mov rbx, qword ptr [rax] - mov qword ptr [rax], 0 - test rbx, rbx - je LBB1_2 - call SYM(objc2::__macro_helpers::os_version::apple::lookup_version::GENERATED_ID, 0) - mov dword ptr [rbx], eax - add rsp, 8 - pop rbx - pop rbp - ret -LBB1_2: - lea rdi, [rip + l_anon.[ID].3] - call SYM(core::option::unwrap_failed::GENERATED_ID, 0) - - .p2align 4, 0x90 -SYM(<::call_once_force<>::initialize<>::get_or_init::{closure#0}, !>::{closure#0}>::{closure#0} as core[CRATE_ID]::ops::function::FnOnce<(&std[CRATE_ID]::sync::once::OnceState,)>>::call_once::{shim:vtable#0}, 0): - push rbp - mov rbp, rsp - push rbx - push rax - mov rax, qword ptr [rdi] - mov rbx, qword ptr [rax] - mov qword ptr [rax], 0 - test rbx, rbx - je LBB2_2 - call SYM(objc2::__macro_helpers::os_version::apple::lookup_version::GENERATED_ID, 0) - mov dword ptr [rbx], eax - add rsp, 8 - pop rbx - pop rbp - ret -LBB2_2: - lea rdi, [rip + l_anon.[ID].3] - call SYM(core::option::unwrap_failed::GENERATED_ID, 0) - .globl _always .p2align 4, 0x90 _always: @@ -103,19 +35,20 @@ _high: push rbx push rax mov rbx, qword ptr [rip + SYM(objc2::__macro_helpers::os_version::apple::current_version::CURRENT_VERSION::GENERATED_ID, 0)@GOTPCREL] - mov rax, qword ptr [rbx] - cmp rax, 3 - jne LBB6_1 -LBB6_2: - cmp word ptr [rbx + 10], 15 + mov eax, dword ptr [rbx] + test eax, eax + je LBB3_1 +LBB3_2: + cmp eax, 983040 setae al add rsp, 8 pop rbx pop rbp ret -LBB6_1: - call SYM(>::initialize::<>::get_or_init::{closure#0}, !>, 0) - jmp LBB6_2 +LBB3_1: + call SYM(objc2::__macro_helpers::os_version::apple::lookup_version::GENERATED_ID, 0) + mov dword ptr [rbx], eax + jmp LBB3_2 .globl _only_ios .p2align 4, 0x90 @@ -133,54 +66,33 @@ _two_checks: mov rbp, rsp push r14 push rbx - mov rbx, qword ptr [rip + SYM(objc2::__macro_helpers::os_version::apple::current_version::CURRENT_VERSION::GENERATED_ID, 0)@GOTPCREL] - mov rax, qword ptr [rbx] - cmp rax, 3 - jne LBB8_1 - movzx r14d, word ptr [rbx + 10] - mov rax, qword ptr [rbx] - cmp rax, 3 - jne LBB8_3 -LBB8_4: - cmp r14w, 14 + mov r14, qword ptr [rip + SYM(objc2::__macro_helpers::os_version::apple::current_version::CURRENT_VERSION::GENERATED_ID, 0)@GOTPCREL] + mov ebx, dword ptr [r14] + test ebx, ebx + je LBB5_1 + mov eax, dword ptr [r14] + test eax, eax + je LBB5_3 +LBB5_4: + cmp ebx, 917504 setae cl - cmp word ptr [rbx + 10], 15 + cmp eax, 983040 setae al and al, cl pop rbx pop r14 pop rbp ret -LBB8_1: - call SYM(>::initialize::<>::get_or_init::{closure#0}, !>, 0) - movzx r14d, word ptr [rbx + 10] - mov rax, qword ptr [rbx] - cmp rax, 3 - je LBB8_4 -LBB8_3: - call SYM(>::initialize::<>::get_or_init::{closure#0}, !>, 0) - jmp LBB8_4 - - .section __DATA,__const - .p2align 3, 0x0 -l_anon.[ID].0: - .asciz "\000\000\000\000\000\000\000\000\b\000\000\000\000\000\000\000\b\000\000\000\000\000\000" - .quad SYM(<::call_once_force<>::initialize<>::get_or_init::{closure#0}, !>::{closure#0}>::{closure#0} as core[CRATE_ID]::ops::function::FnOnce<(&std[CRATE_ID]::sync::once::OnceState,)>>::call_once::{shim:vtable#0}, 0) - .quad SYM(::call_once_force::<>::initialize<>::get_or_init::{closure#0}, !>::{closure#0}>::{closure#0}, 0) - - .section __TEXT,__const -l_anon.[ID].1: - .ascii "$RUSTC/library/std/src/sync/once.rs" - - .section __DATA,__const - .p2align 3, 0x0 -l_anon.[ID].2: - .quad l_anon.[ID].1 - .asciz "p\000\000\000\000\000\000\000\331\000\000\000\024\000\000" - - .p2align 3, 0x0 -l_anon.[ID].3: - .quad l_anon.[ID].1 - .asciz "p\000\000\000\000\000\000\000\331\000\000\0001\000\000" +LBB5_1: + call SYM(objc2::__macro_helpers::os_version::apple::lookup_version::GENERATED_ID, 0) + mov ebx, eax + mov dword ptr [r14], eax + mov eax, dword ptr [r14] + test eax, eax + jne LBB5_4 +LBB5_3: + call SYM(objc2::__macro_helpers::os_version::apple::lookup_version::GENERATED_ID, 0) + mov dword ptr [r14], eax + jmp LBB5_4 .subsections_via_symbols