]> git.lizzy.rs Git - rust.git/blob - src/test/assembly/static-relocation-model.rs
Auto merge of #85994 - tmiasko:monomorphic-needs-drop, r=RalfJung
[rust.git] / src / test / assembly / static-relocation-model.rs
1 // min-llvm-version: 12.0.0
2 // needs-llvm-components: aarch64 x86 powerpc
3 // revisions: x64 A64 ppc64le
4 // assembly-output: emit-asm
5 // [x64] compile-flags: --target x86_64-unknown-linux-gnu -Crelocation-model=static
6 // [A64] compile-flags: --target aarch64-unknown-linux-gnu -Crelocation-model=static
7 // [ppc64le] compile-flags: --target powerpc64le-unknown-linux-gnu -Crelocation-model=static
8
9 #![feature(no_core, lang_items)]
10 #![no_core]
11 #![crate_type="rlib"]
12
13 #[lang="sized"]
14 trait Sized {}
15
16 #[lang="copy"]
17 trait Copy {}
18
19 #[lang="sync"]
20 trait Sync {}
21
22 #[lang = "drop_in_place"]
23 fn drop_in_place<T>(_: *mut T) {}
24
25 impl Copy for u8 {}
26 impl Sync for u8 {}
27
28 #[no_mangle]
29 pub static PIERIS: u8 = 42;
30
31 extern "C" {
32     static EXOCHORDA: *mut u8;
33
34     fn chaenomeles();
35 }
36
37 // CHECK-LABEL: banana:
38 // x64: movb   chaenomeles{{(\(%[a-z0-9]+\))?}}, %{{[a-z0-9]+}}
39 // A64:      adrp    [[REG:[a-z0-9]+]], chaenomeles
40 // A64-NEXT: ldrb    {{[a-z0-9]+}}, {{\[}}[[REG]], :lo12:chaenomeles]
41 #[no_mangle]
42 pub fn banana() -> u8 {
43     unsafe {
44         *(chaenomeles as *mut u8)
45     }
46 }
47
48 // CHECK-LABEL: peach:
49 // x64: movb    banana{{(\(%[a-z0-9]+\))?}}, %{{[a-z0-9]+}}
50 // A64:      adrp    [[REG2:[a-z0-9]+]], banana
51 // A64-NEXT: ldrb    {{[a-z0-9]+}}, {{\[}}[[REG2]], :lo12:banana]
52 #[no_mangle]
53 pub fn peach() -> u8 {
54     unsafe {
55         *(banana as *mut u8)
56     }
57 }
58
59 // CHECK-LABEL: mango:
60 // x64:      movq    EXOCHORDA{{(\(%[a-z0-9]+\))?}}, %[[REG:[a-z0-9]+]]
61 // x64-NEXT: movb    (%[[REG]]), %{{[a-z0-9]+}}
62 // A64:      adrp    [[REG2:[a-z0-9]+]], EXOCHORDA
63 // A64-NEXT: ldr     {{[a-z0-9]+}}, {{\[}}[[REG2]], :lo12:EXOCHORDA]
64 #[no_mangle]
65 pub fn mango() -> u8 {
66     unsafe {
67         *EXOCHORDA
68     }
69 }
70
71 // CHECK-LABEL: orange:
72 // x64: mov{{l|absq}}    $PIERIS, %{{[a-z0-9]+}}
73 // A64:      adrp    [[REG2:[a-z0-9]+]], PIERIS
74 // A64-NEXT: add     {{[a-z0-9]+}}, [[REG2]], :lo12:PIERIS
75 #[no_mangle]
76 pub fn orange() -> &'static u8 {
77     &PIERIS
78 }
79
80 // For ppc64 we need to make sure to generate TOC entries even with the static relocation model
81 // ppc64le: .tc chaenomeles[TC],chaenomeles
82 // ppc64le: .tc banana[TC],banana
83 // ppc64le: .tc EXOCHORDA[TC],EXOCHORDA
84 // ppc64le: .tc PIERIS[TC],PIERIS