diff --git a/objc2/src/macros.rs b/objc2/src/macros.rs index b2f19f5be..33c2a25de 100644 --- a/objc2/src/macros.rs +++ b/objc2/src/macros.rs @@ -76,6 +76,9 @@ macro_rules! sel { #[used] static _IMAGE_TAG: [u32; 2] = [0, 0]; + // Marked with `unnamed_addr` in Objective-C's LLVM. + // See rust-lang/rust#18297 + // Should only be an optimization (?) #[link_section = "__TEXT,__objc_methname,cstring_literals"] #[export_name = concat!("\x01L_OBJC_METH_VAR_NAME_", $crate::__proc_macros::hash_idents!($($idents)+))] static NAME: [u8; X.len()] = { @@ -89,6 +92,8 @@ macro_rules! sel { }; // Place the constant value in the correct section. + // + // Clang uses `no_dead_strip` here for some reason? #[link_section = "__DATA,__objc_selrefs,literal_pointers"] #[export_name = concat!("\x01L_OBJC_SELECTOR_REFERENCES_", $crate::__proc_macros::hash_idents!($($idents)+))] static mut REF: &[u8; X.len()] = &NAME; @@ -97,6 +102,9 @@ macro_rules! sel { // loaded, so we need to use a volatile read to prevent the // optimizer from thinking it can circumvent the read through REF. // + // Clang avoids this by marking `REF` with LLVM's + // `externally_initialized`. + // // TODO: `::core` here could be replaced with some more // sophisticated logic so we don't rely on downstream users having // this setup.