5 #![feature(asm, thread_local)]
7 extern "C" fn f1() -> i32 {
11 // The compiler will generate a shim to hide the caller location parameter.
21 asm!("bl {}", sym $func,
23 out("x20") _, out("x21") _, out("x22") _,
24 out("x23") _, out("x24") _, out("x25") _,
25 out("x26") _, out("x27") _, out("x28") _,
32 macro_rules! static_addr {
35 let result: *const u32;
37 // ADRP gives the address of a 4KB page from a PC-relative address
39 // We then add the remaining lower 12 bits
40 "add {out}, {out}, #:lo12:{sym}",
41 out = out(reg) result,
47 macro_rules! static_tls_addr {
50 let result: *const u32;
52 // Load the thread pointer register
53 "mrs {out}, TPIDR_EL0",
54 // Add the top 12 bits of the symbol's offset
55 "add {out}, {out}, :tprel_hi12:{sym}",
56 // And the bottom 12 bits
57 "add {out}, {out}, :tprel_lo12_nc:{sym}",
58 out = out(reg) result,
71 assert_eq!(call!(f1), 111);
72 assert_eq!(call!(f2), 222);
73 assert_eq!(static_addr!(S1), &S1 as *const u32);
74 assert_eq!(static_tls_addr!(S2), &S2 as *const u32);
75 std::thread::spawn(|| {
76 assert_eq!(static_addr!(S1), &S1 as *const u32);
77 assert_eq!(static_tls_addr!(S2), &S2 as *const u32);