Skip to content

Commit a61dd14

Browse files
authored
Merge pull request #224 from madsmtm/stable-assembly-tests
Make assembly tests more stable
2 parents e8602d5 + f17a4f2 commit a61dd14

File tree

21 files changed

+381
-363
lines changed

21 files changed

+381
-363
lines changed

objc2/src/__macro_helpers.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ pub use core::ops::{Deref, DerefMut};
1313
pub use core::option::Option::{self, None, Some};
1414
pub use core::primitive::{bool, str, u8};
1515
pub use core::{compile_error, concat, panic, stringify};
16-
#[cfg(feature = "objc2-proc-macros")]
17-
pub use objc2_proc_macros::__hash_idents;
1816
// TODO: Use `core::cell::LazyCell`
1917
pub use std::sync::Once;
2018

@@ -30,17 +28,17 @@ pub use std::sync::Once;
3028
#[inline]
3129
pub fn alloc() -> Sel {
3230
// SAFETY: Must have NUL byte
33-
__sel_inner!("alloc\0", uniqueIdent)
31+
__sel_inner!("alloc\0", "alloc")
3432
}
3533
#[inline]
3634
pub fn init() -> Sel {
3735
// SAFETY: Must have NUL byte
38-
__sel_inner!("init\0", uniqueIdent)
36+
__sel_inner!("init\0", "init")
3937
}
4038
#[inline]
4139
pub fn new() -> Sel {
4240
// SAFETY: Must have NUL byte
43-
__sel_inner!("new\0", uniqueIdent)
41+
__sel_inner!("new\0", "new")
4442
}
4543

4644
/// Helper for specifying the retain semantics for a given selector family.
@@ -251,6 +249,8 @@ mod tests {
251249

252250
use core::ptr;
253251

252+
#[cfg(feature = "objc2-proc-macros")]
253+
use crate::__hash_idents;
254254
use crate::rc::{Allocated, Owned, RcTestObject, Shared, ThreadTestData};
255255
use crate::runtime::Object;
256256
use crate::{class, msg_send_id};

objc2/src/lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,18 @@ pub use crate::message::{Message, MessageArguments, MessageReceiver};
203203
#[cfg(feature = "malloc")]
204204
pub use crate::verify::VerificationError;
205205

206+
#[cfg(feature = "objc2-proc-macros")]
207+
#[doc(hidden)]
208+
pub use objc2_proc_macros::__hash_idents;
209+
210+
#[cfg(not(feature = "objc2-proc-macros"))]
211+
#[doc(hidden)]
212+
#[macro_export]
213+
macro_rules! __hash_idents {
214+
// Noop; used to make our other macros a bit easier to read
215+
($($x:tt)*) => {$($x)*};
216+
}
217+
206218
#[doc(hidden)]
207219
pub mod __macro_helpers;
208220
mod bool;

objc2/src/macros.rs

Lines changed: 49 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ mod extern_class;
4343
#[macro_export]
4444
macro_rules! class {
4545
($name:ident) => {{
46-
$crate::__class_inner!($name)
46+
$crate::__class_inner!($name, $crate::__hash_idents!($name))
4747
}};
4848
}
4949

5050
#[doc(hidden)]
5151
#[macro_export]
5252
#[cfg(not(feature = "unstable-static-class"))]
5353
macro_rules! __class_inner {
54-
($name:ident) => {{
54+
($name:ident, $_hash:expr) => {{
5555
use $crate::__macro_helpers::{concat, panic, stringify, CachedClass, None, Some};
5656
static CACHED_CLASS: CachedClass = CachedClass::new();
5757
let name = concat!(stringify!($name), '\0');
@@ -191,15 +191,15 @@ macro_rules! sel {
191191
($first:ident $(: $($rest:ident :)*)?) => ({
192192
use $crate::__macro_helpers::{concat, stringify, str};
193193
const SELECTOR_DATA: &str = concat!(stringify!($first), $(':', $(stringify!($rest), ':',)*)? '\0');
194-
$crate::__sel_inner!(SELECTOR_DATA, $first $($($rest)*)?)
194+
$crate::__sel_inner!(SELECTOR_DATA, $crate::__hash_idents!($first $($($rest)*)?))
195195
});
196196
}
197197

198198
#[doc(hidden)]
199199
#[macro_export]
200200
#[cfg(not(feature = "unstable-static-sel"))]
201201
macro_rules! __sel_inner {
202-
($data:expr, $($idents:ident)+) => {{
202+
($data:expr, $_hash:expr) => {{
203203
use $crate::__macro_helpers::CachedSel;
204204
static CACHED_SEL: CachedSel = CachedSel::new();
205205
#[allow(unused_unsafe)]
@@ -229,7 +229,7 @@ macro_rules! __inner_statics_apple_generic {
229229
{
230230
@image_info;
231231
$image_info_section:literal;
232-
$($idents:ident)+
232+
$hash:expr;
233233
} => {
234234
/// We always emit the image info tag, since we need it to:
235235
/// - End up in the same codegen unit as the other statics below.
@@ -241,19 +241,19 @@ macro_rules! __inner_statics_apple_generic {
241241
#[link_section = $image_info_section]
242242
#[export_name = $crate::__macro_helpers::concat!(
243243
"\x01L_OBJC_IMAGE_INFO_",
244-
$crate::__macro_helpers::__hash_idents!($($idents)+),
244+
$hash,
245245
)]
246246
#[used] // Make sure this reaches the linker
247247
static _IMAGE_INFO: $crate::ffi::__ImageInfo = $crate::ffi::__ImageInfo::system();
248248
};
249249
{
250250
@module_info;
251-
$($idents:ident)+
251+
$hash:expr;
252252
} => {
253253
#[link_section = "__TEXT,__cstring,cstring_literals"]
254254
#[export_name = $crate::__macro_helpers::concat!(
255255
"\x01L_OBJC_CLASS_NAME_",
256-
$crate::__macro_helpers::__hash_idents!($($idents)+),
256+
$hash,
257257
"_MODULE_INFO"
258258
)]
259259
static MODULE_INFO_NAME: [$crate::__macro_helpers::u8; 1] = [0];
@@ -265,7 +265,7 @@ macro_rules! __inner_statics_apple_generic {
265265
#[link_section = "__OBJC,__module_info,regular,no_dead_strip"]
266266
#[export_name = $crate::__macro_helpers::concat!(
267267
"\x01L_OBJC_MODULES_",
268-
$crate::__macro_helpers::__hash_idents!($($idents)+)
268+
$hash,
269269
)]
270270
#[used] // Make sure this reaches the linker
271271
static _MODULE_INFO: $crate::__macro_helpers::ModuleInfo = $crate::__macro_helpers::ModuleInfo::new(
@@ -276,8 +276,8 @@ macro_rules! __inner_statics_apple_generic {
276276
@sel;
277277
$var_name_section:literal;
278278
$selector_ref_section:literal;
279-
$data:expr,
280-
$($idents:ident)+
279+
$data:expr;
280+
$hash:expr;
281281
} => {
282282
use $crate::__macro_helpers::{u8, UnsafeCell};
283283
use $crate::runtime::Sel;
@@ -290,7 +290,7 @@ macro_rules! __inner_statics_apple_generic {
290290
#[link_section = $var_name_section]
291291
#[export_name = $crate::__macro_helpers::concat!(
292292
"\x01L_OBJC_METH_VAR_NAME_",
293-
$crate::__macro_helpers::__hash_idents!($($idents)+),
293+
$hash,
294294
)]
295295
static NAME_DATA: [u8; X.len()] = $crate::__inner_statics_apple_generic! {
296296
@string_to_known_length_bytes;
@@ -323,15 +323,16 @@ macro_rules! __inner_statics_apple_generic {
323323
#[link_section = $selector_ref_section]
324324
#[export_name = $crate::__macro_helpers::concat!(
325325
"\x01L_OBJC_SELECTOR_REFERENCES_",
326-
$crate::__macro_helpers::__hash_idents!($($idents)+),
326+
$hash,
327327
)]
328328
static mut REF: UnsafeCell<Sel> = unsafe {
329329
UnsafeCell::new(Sel::__internal_from_ptr(NAME_DATA.as_ptr().cast()))
330330
};
331331
};
332332
{
333333
@class;
334-
$name:ident
334+
$name:ident;
335+
$hash:expr;
335336
} => {
336337
use $crate::__macro_helpers::UnsafeCell;
337338
use $crate::runtime::Class;
@@ -366,15 +367,16 @@ macro_rules! __inner_statics_apple_generic {
366367
#[link_section = "__DATA,__objc_classrefs,regular,no_dead_strip"]
367368
#[export_name = $crate::__macro_helpers::concat!(
368369
"\x01L_OBJC_CLASSLIST_REFERENCES_$_",
369-
$crate::__macro_helpers::__hash_idents!($name),
370+
$crate::__hash_idents!($name),
370371
)]
371372
static mut REF: UnsafeCell<&Class> = unsafe {
372373
UnsafeCell::new(&CLASS)
373374
};
374375
};
375376
{
376377
@class_old;
377-
$name:ident
378+
$name:ident;
379+
$hash:expr;
378380
} => {
379381
use $crate::__macro_helpers::{u8, UnsafeCell};
380382
use $crate::runtime::Class;
@@ -385,7 +387,7 @@ macro_rules! __inner_statics_apple_generic {
385387
#[link_section = "__TEXT,__cstring,cstring_literals"]
386388
#[export_name = $crate::__macro_helpers::concat!(
387389
"\x01L_OBJC_CLASS_NAME_",
388-
$crate::__macro_helpers::__hash_idents!($name),
390+
$crate::__hash_idents!($name),
389391
)]
390392
static NAME_DATA: [u8; X.len()] = $crate::__inner_statics_apple_generic! {
391393
@string_to_known_length_bytes;
@@ -396,7 +398,7 @@ macro_rules! __inner_statics_apple_generic {
396398
#[link_section = "__OBJC,__cls_refs,literal_pointers,no_dead_strip"]
397399
#[export_name = $crate::__macro_helpers::concat!(
398400
"\x01L_OBJC_CLASS_REFERENCES_",
399-
$crate::__macro_helpers::__hash_idents!($name),
401+
$crate::__hash_idents!($name),
400402
)]
401403
static mut REF: UnsafeCell<&Class> = unsafe {
402404
let ptr: *const Class = NAME_DATA.as_ptr().cast();
@@ -410,28 +412,30 @@ macro_rules! __inner_statics_apple_generic {
410412
#[macro_export]
411413
#[cfg(all(feature = "apple", not(all(target_os = "macos", target_arch = "x86"))))]
412414
macro_rules! __inner_statics {
413-
(@image_info $($args:tt)*) => {
415+
(@image_info $hash:expr) => {
414416
$crate::__inner_statics_apple_generic! {
415417
@image_info;
416418
"__DATA,__objc_imageinfo,regular,no_dead_strip";
417-
$($args)*
419+
$hash;
418420
}
419421
};
420-
(@sel $($args:tt)*) => {
422+
(@sel $data:expr, $hash:expr) => {
421423
$crate::__inner_statics_apple_generic! {
422424
@sel;
423425
"__TEXT,__objc_methname,cstring_literals";
424426
// Clang uses `no_dead_strip` in the link section for some reason,
425427
// which other tools (notably some LLVM tools) now assume is
426428
// present, so we have to add it as well.
427429
"__DATA,__objc_selrefs,literal_pointers,no_dead_strip";
428-
$($args)*
430+
$data;
431+
$hash;
429432
}
430433
};
431-
(@class $($args:tt)*) => {
434+
(@class $name:ident, $hash:expr) => {
432435
$crate::__inner_statics_apple_generic! {
433436
@class;
434-
$($args)*
437+
$name;
438+
$hash;
435439
}
436440
};
437441
}
@@ -440,29 +444,31 @@ macro_rules! __inner_statics {
440444
#[macro_export]
441445
#[cfg(all(feature = "apple", target_os = "macos", target_arch = "x86"))]
442446
macro_rules! __inner_statics {
443-
(@image_info $($args:tt)*) => {
447+
(@image_info $hash:expr) => {
444448
$crate::__inner_statics_apple_generic! {
445449
@image_info;
446450
"__OBJC,__image_info,regular";
447-
$($args)*
451+
$hash;
448452
}
449453
};
450-
(@sel $($args:tt)*) => {
454+
(@sel $data:expr, $hash:expr) => {
451455
$crate::__inner_statics_apple_generic! {
452456
@sel;
453457
"__TEXT,__cstring,cstring_literals";
454458
"__OBJC,__message_refs,literal_pointers,no_dead_strip";
455-
$($args)*
459+
$data;
460+
$hash;
456461
}
457462
};
458-
(@class $($args:tt)*) => {
463+
(@class $name:ident, $hash:expr) => {
459464
$crate::__inner_statics_apple_generic! {
460465
@class_old;
461-
$($args)*
466+
$name;
467+
$hash;
462468
}
463469
$crate::__inner_statics_apple_generic! {
464470
@module_info;
465-
$($args)*
471+
$hash;
466472
}
467473
};
468474
}
@@ -495,9 +501,9 @@ macro_rules! __inner_statics {
495501
not(feature = "unstable-static-sel-inlined")
496502
))]
497503
macro_rules! __sel_inner {
498-
($data:expr, $($idents:ident)+) => {{
499-
$crate::__inner_statics!(@image_info $($idents)+);
500-
$crate::__inner_statics!(@sel $data, $($idents)+);
504+
($data:expr, $hash:expr) => {{
505+
$crate::__inner_statics!(@image_info $hash);
506+
$crate::__inner_statics!(@sel $data, $hash);
501507

502508
/// HACK: Wrap the access in a non-generic, `#[inline(never)]`
503509
/// function to make the compiler group it into the same codegen unit
@@ -524,9 +530,9 @@ macro_rules! __sel_inner {
524530
#[macro_export]
525531
#[cfg(all(feature = "unstable-static-sel-inlined"))]
526532
macro_rules! __sel_inner {
527-
($data:expr, $($idents:ident)+) => {{
528-
$crate::__inner_statics!(@image_info $($idents)+);
529-
$crate::__inner_statics!(@sel $data, $($idents)+);
533+
($data:expr, $hash:expr) => {{
534+
$crate::__inner_statics!(@image_info $hash);
535+
$crate::__inner_statics!(@sel $data, $hash);
530536

531537
#[allow(unused_unsafe)]
532538
// SAFETY: See above
@@ -541,9 +547,9 @@ macro_rules! __sel_inner {
541547
not(feature = "unstable-static-class-inlined")
542548
))]
543549
macro_rules! __class_inner {
544-
($name:ident) => {{
545-
$crate::__inner_statics!(@image_info $name);
546-
$crate::__inner_statics!(@class $name);
550+
($name:ident, $hash:expr) => {{
551+
$crate::__inner_statics!(@image_info $hash);
552+
$crate::__inner_statics!(@class $name, $hash);
547553

548554
#[inline(never)]
549555
fn objc_static_workaround() -> &'static Class {
@@ -559,9 +565,9 @@ macro_rules! __class_inner {
559565
#[macro_export]
560566
#[cfg(all(feature = "unstable-static-class-inlined"))]
561567
macro_rules! __class_inner {
562-
($name:ident) => {{
563-
$crate::__inner_statics!(@image_info $name);
564-
$crate::__inner_statics!(@class $name);
568+
($name:ident, $hash:expr) => {{
569+
$crate::__inner_statics!(@image_info $hash);
570+
$crate::__inner_statics!(@class $name, $hash);
565571

566572
#[allow(unused_unsafe)]
567573
// SAFETY: See above

test-assembly/crates/test_msg_send_static_sel/expected/apple-aarch64.s

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ _handle_alloc_init:
1616
stp x29, x30, [sp, #16]
1717
add x29, sp, #16
1818
Lloh2:
19-
adrp x8, L_OBJC_SELECTOR_REFERENCES_a4d24db6a5648d44@GOTPAGE
19+
adrp x8, L_OBJC_SELECTOR_REFERENCES_init@GOTPAGE
2020
Lloh3:
21-
ldr x8, [x8, L_OBJC_SELECTOR_REFERENCES_a4d24db6a5648d44@GOTPAGEOFF]
21+
ldr x8, [x8, L_OBJC_SELECTOR_REFERENCES_init@GOTPAGEOFF]
2222
Lloh4:
2323
ldr x19, [x8]
2424
Lloh5:
25-
adrp x8, L_OBJC_SELECTOR_REFERENCES_234aca269670483c@GOTPAGE
25+
adrp x8, L_OBJC_SELECTOR_REFERENCES_alloc@GOTPAGE
2626
Lloh6:
27-
ldr x8, [x8, L_OBJC_SELECTOR_REFERENCES_234aca269670483c@GOTPAGEOFF]
27+
ldr x8, [x8, L_OBJC_SELECTOR_REFERENCES_alloc@GOTPAGEOFF]
2828
Lloh7:
2929
ldr x1, [x8]
3030
bl _objc_msgSend

test-assembly/crates/test_msg_send_static_sel/expected/apple-armv7.s

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ LPC0_0:
1616
_handle_alloc_init:
1717
push {r4, r7, lr}
1818
add r7, sp, #4
19-
movw r1, :lower16:(LL_OBJC_SELECTOR_REFERENCES_a4d24db6a5648d44$non_lazy_ptr-(LPC1_0+8))
20-
movt r1, :upper16:(LL_OBJC_SELECTOR_REFERENCES_a4d24db6a5648d44$non_lazy_ptr-(LPC1_0+8))
21-
movw r2, :lower16:(LL_OBJC_SELECTOR_REFERENCES_234aca269670483c$non_lazy_ptr-(LPC1_1+8))
22-
movt r2, :upper16:(LL_OBJC_SELECTOR_REFERENCES_234aca269670483c$non_lazy_ptr-(LPC1_1+8))
19+
movw r1, :lower16:(LL_OBJC_SELECTOR_REFERENCES_init$non_lazy_ptr-(LPC1_0+8))
20+
movt r1, :upper16:(LL_OBJC_SELECTOR_REFERENCES_init$non_lazy_ptr-(LPC1_0+8))
21+
movw r2, :lower16:(LL_OBJC_SELECTOR_REFERENCES_alloc$non_lazy_ptr-(LPC1_1+8))
22+
movt r2, :upper16:(LL_OBJC_SELECTOR_REFERENCES_alloc$non_lazy_ptr-(LPC1_1+8))
2323
LPC1_0:
2424
ldr r1, [pc, r1]
2525
LPC1_1:
@@ -156,11 +156,11 @@ L_OBJC_SELECTOR_REFERENCES_e76e01e8b2327e5d:
156156

157157
.section __DATA,__nl_symbol_ptr,non_lazy_symbol_pointers
158158
.p2align 2
159-
LL_OBJC_SELECTOR_REFERENCES_234aca269670483c$non_lazy_ptr:
160-
.indirect_symbol L_OBJC_SELECTOR_REFERENCES_234aca269670483c
159+
LL_OBJC_SELECTOR_REFERENCES_alloc$non_lazy_ptr:
160+
.indirect_symbol L_OBJC_SELECTOR_REFERENCES_alloc
161161
.long 0
162-
LL_OBJC_SELECTOR_REFERENCES_a4d24db6a5648d44$non_lazy_ptr:
163-
.indirect_symbol L_OBJC_SELECTOR_REFERENCES_a4d24db6a5648d44
162+
LL_OBJC_SELECTOR_REFERENCES_init$non_lazy_ptr:
163+
.indirect_symbol L_OBJC_SELECTOR_REFERENCES_init
164164
.long 0
165165

166166
.subsections_via_symbols

0 commit comments

Comments
 (0)