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