]> git.proxmox.com Git - rustc.git/blob - src/test/assembly/static-relocation-model.rs
New upstream version 1.58.1+dfsg1
[rustc.git] / src / test / 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 // x64: movb chaenomeles{{(\(%[a-z0-9]+\))?}}, %{{[a-z0-9]+}}
40 // A64: adrp [[REG:[a-z0-9]+]], chaenomeles
41 // A64-NEXT: ldrb {{[a-z0-9]+}}, {{\[}}[[REG]], :lo12:chaenomeles]
42 #[no_mangle]
43 pub fn banana() -> u8 {
44 unsafe {
45 *(chaenomeles as *mut u8)
46 }
47 }
48
49 // CHECK-LABEL: peach:
50 // x64: movb banana{{(\(%[a-z0-9]+\))?}}, %{{[a-z0-9]+}}
51 // A64: adrp [[REG2:[a-z0-9]+]], banana
52 // A64-NEXT: ldrb {{[a-z0-9]+}}, {{\[}}[[REG2]], :lo12:banana]
53 #[no_mangle]
54 pub fn peach() -> u8 {
55 unsafe {
56 *(banana as *mut u8)
57 }
58 }
59
60 // CHECK-LABEL: mango:
61 // x64: movq EXOCHORDA{{(\(%[a-z0-9]+\))?}}, %[[REG:[a-z0-9]+]]
62 // x64-NEXT: movb (%[[REG]]), %{{[a-z0-9]+}}
63 // A64: adrp [[REG2:[a-z0-9]+]], EXOCHORDA
64 // A64-NEXT: ldr {{[a-z0-9]+}}, {{\[}}[[REG2]], :lo12:EXOCHORDA]
65 #[no_mangle]
66 pub fn mango() -> u8 {
67 unsafe {
68 *EXOCHORDA
69 }
70 }
71
72 // CHECK-LABEL: orange:
73 // x64: mov{{l|absq}} $PIERIS, %{{[a-z0-9]+}}
74 // A64: adrp [[REG2:[a-z0-9]+]], PIERIS
75 // A64-NEXT: add {{[a-z0-9]+}}, [[REG2]], :lo12:PIERIS
76 #[no_mangle]
77 pub fn orange() -> &'static u8 {
78 &PIERIS
79 }
80
81 // For ppc64 we need to make sure to generate TOC entries even with the static relocation model
82 // ppc64le: .tc chaenomeles[TC],chaenomeles
83 // ppc64le: .tc banana[TC],banana
84 // ppc64le: .tc EXOCHORDA[TC],EXOCHORDA
85 // ppc64le: .tc PIERIS[TC],PIERIS