about summary refs log tree commit diff
path: root/tests/assembly-llvm/static-relocation-model.rs
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2025-07-21 14:22:51 +0200
committerGuillaume Gomez <guillaume1.gomez@gmail.com>2025-07-22 14:27:48 +0200
commited93c1783b404d728d4809973a0550eb33cd293f (patch)
tree2b62aab8b2482fcde1f9128ff53be8cd66bde847 /tests/assembly-llvm/static-relocation-model.rs
parentc0b282f0ccdab7523cdb8dfa41b23bed5573da76 (diff)
downloadrust-ed93c1783b404d728d4809973a0550eb33cd293f.tar.gz
rust-ed93c1783b404d728d4809973a0550eb33cd293f.zip
Rename `tests/assembly` into `tests/assembly-llvm`
Diffstat (limited to 'tests/assembly-llvm/static-relocation-model.rs')
-rw-r--r--tests/assembly-llvm/static-relocation-model.rs69
1 files changed, 69 insertions, 0 deletions
diff --git a/tests/assembly-llvm/static-relocation-model.rs b/tests/assembly-llvm/static-relocation-model.rs
new file mode 100644
index 00000000000..35ad94133b2
--- /dev/null
+++ b/tests/assembly-llvm/static-relocation-model.rs
@@ -0,0 +1,69 @@
+//@ add-core-stubs
+//@ revisions: x64 A64 ppc64le
+//@ assembly-output: emit-asm
+//@ [x64] compile-flags: --target x86_64-unknown-linux-gnu -Crelocation-model=static
+//@ [x64] needs-llvm-components: x86
+//@ [A64] compile-flags: --target aarch64-unknown-linux-gnu -Crelocation-model=static
+//@ [A64] needs-llvm-components: aarch64
+//@ [ppc64le] compile-flags: --target powerpc64le-unknown-linux-gnu -Crelocation-model=static
+//@ [ppc64le] needs-llvm-components: powerpc
+
+#![feature(no_core, lang_items)]
+#![no_core]
+#![crate_type = "rlib"]
+
+extern crate minicore;
+use minicore::*;
+
+#[no_mangle]
+pub static PIERIS: u8 = 42;
+
+extern "C" {
+    static EXOCHORDA: *mut u8;
+
+    fn chaenomeles();
+}
+
+// CHECK-LABEL: banana:
+// LLVM may produce either kind of `mov` here, depending on version and optimization level.
+// x64: {{movb|movzbl}}   chaenomeles{{(\(%[a-z0-9]+\))?}}, %{{[a-z0-9]+}}
+// A64:      adrp    [[REG:[a-z0-9]+]], chaenomeles
+// A64-NEXT: ldrb    {{[a-z0-9]+}}, {{\[}}[[REG]], :lo12:chaenomeles]
+#[no_mangle]
+pub fn banana() -> u8 {
+    unsafe { *(chaenomeles as *mut u8) }
+}
+
+// CHECK-LABEL: peach:
+// x64: {{movb|movzbl}}    banana{{(\(%[a-z0-9]+\))?}}, %{{[a-z0-9]+}}
+// A64:      adrp    [[REG2:[a-z0-9]+]], banana
+// A64-NEXT: ldrb    {{[a-z0-9]+}}, {{\[}}[[REG2]], :lo12:banana]
+#[no_mangle]
+pub fn peach() -> u8 {
+    unsafe { *(banana as *mut u8) }
+}
+
+// CHECK-LABEL: mango:
+// x64:      movq    EXOCHORDA{{(\(%[a-z0-9]+\))?}}, %[[REG:[a-z0-9]+]]
+// x64-NEXT: {{movb|movzbl}}   (%[[REG]]), %{{[a-z0-9]+}}
+// A64:      adrp    [[REG2:[a-z0-9]+]], EXOCHORDA
+// A64-NEXT: ldr     {{[a-z0-9]+}}, {{\[}}[[REG2]], :lo12:EXOCHORDA]
+#[no_mangle]
+pub fn mango() -> u8 {
+    unsafe { *EXOCHORDA }
+}
+
+// CHECK-LABEL: orange:
+// x64: mov{{l|absq}}    $PIERIS, %{{[a-z0-9]+}}
+// A64:      adrp    [[REG2:[a-z0-9]+]], PIERIS
+// A64-NEXT: add     {{[a-z0-9]+}}, [[REG2]], :lo12:PIERIS
+#[no_mangle]
+pub fn orange() -> &'static u8 {
+    &PIERIS
+}
+
+// For ppc64 we need to make sure to generate TOC entries even with the static relocation model
+// ppc64le: .tc chaenomeles[TC],chaenomeles
+// ppc64le: .tc banana[TC],banana
+// ppc64le: .tc EXOCHORDA[TC],EXOCHORDA
+// ppc64le: .tc PIERIS[TC],PIERIS