about summary refs log tree commit diff
path: root/src/test/assembly
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2021-10-01 09:18:16 -0700
committerGitHub <noreply@github.com>2021-10-01 09:18:16 -0700
commit6f1e93058137eb606cbee5ef778d30b379903f7c (patch)
tree1840b8bb51958a08a03e4a76d5ce698ff07d58c6 /src/test/assembly
parent37df2753fc52ff80625430aa7e8cdcdc6f16e362 (diff)
parent198d90786b9fb429928d70c423bad5d65374a532 (diff)
Rollup merge of #88820 - hlopko:add_pie_relocation_model, r=petrochenkov
Add `pie` as another `relocation-model` value

MCP: https://github.com/rust-lang/compiler-team/issues/461
Diffstat (limited to 'src/test/assembly')
-rw-r--r--src/test/assembly/pic-relocation-model.rs35
-rw-r--r--src/test/assembly/pie-relocation-model.rs38
2 files changed, 73 insertions, 0 deletions
diff --git a/src/test/assembly/pic-relocation-model.rs b/src/test/assembly/pic-relocation-model.rs
new file mode 100644
index 00000000000..72471ffcdb0
--- /dev/null
+++ b/src/test/assembly/pic-relocation-model.rs
@@ -0,0 +1,35 @@
+// revisions: x64
+// assembly-output: emit-asm
+// [x64] compile-flags: --target x86_64-unknown-linux-gnu -Crelocation-model=pic
+// [x64] needs-llvm-components: x86
+
+
+#![feature(no_core, lang_items)]
+#![no_core]
+#![crate_type="rlib"]
+
+#[lang = "sized"]
+trait Sized {}
+#[lang = "copy"]
+trait Copy {}
+
+// CHECK-LABEL: call_other_fn:
+// CHECK:       {{(jmpq|callq)}} *other_fn@GOTPCREL(%rip)
+#[no_mangle]
+pub fn call_other_fn() -> u8 {
+    unsafe {
+        other_fn()
+    }
+}
+
+// CHECK-LABEL: other_fn:
+// CHECK:       callq *foreign_fn@GOTPCREL(%rip)
+#[no_mangle]
+#[inline(never)]
+pub fn other_fn() -> u8 {
+    unsafe {
+        foreign_fn()
+    }
+}
+
+extern "C" {fn foreign_fn() -> u8;}
diff --git a/src/test/assembly/pie-relocation-model.rs b/src/test/assembly/pie-relocation-model.rs
new file mode 100644
index 00000000000..e40797e038d
--- /dev/null
+++ b/src/test/assembly/pie-relocation-model.rs
@@ -0,0 +1,38 @@
+// revisions: x64
+// assembly-output: emit-asm
+// [x64] compile-flags: --target x86_64-unknown-linux-gnu -Crelocation-model=pie
+// [x64] needs-llvm-components: x86
+
+
+#![feature(no_core, lang_items)]
+#![no_core]
+#![crate_type="rlib"]
+
+#[lang = "sized"]
+trait Sized {}
+#[lang = "copy"]
+trait Copy {}
+
+// CHECK-LABEL: call_other_fn:
+// With PIE local functions are called "directly".
+// CHECK:       {{(jmp|callq)}} other_fn
+#[no_mangle]
+pub fn call_other_fn() -> u8 {
+    unsafe {
+        other_fn()
+    }
+}
+
+// CHECK-LABEL: other_fn:
+// External functions are still called through GOT, since we don't know if the symbol
+// is defined in the binary or in the shared library.
+// CHECK:       callq *foreign_fn@GOTPCREL(%rip)
+#[no_mangle]
+#[inline(never)]
+pub fn other_fn() -> u8 {
+    unsafe {
+        foreign_fn()
+    }
+}
+
+extern "C" {fn foreign_fn() -> u8;}