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