Skip to content

Commit 182a19e

Browse files
committed
use minicore for fortanix assembly tests
1 parent 29a5872 commit 182a19e

File tree

3 files changed

+46
-27
lines changed

3 files changed

+46
-27
lines changed

tests/assembly-llvm/x86_64-fortanix-unknown-sgx-lvi-generic-load.rs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
1-
// Test LVI load hardening on SGX enclave code
1+
// Test LVI load hardening on SGX enclave code, specifically that `ret` is rewritten.
22

3+
//@ add-core-stubs
34
//@ assembly-output: emit-asm
4-
//@ compile-flags: --crate-type staticlib
5-
//@ only-x86_64-fortanix-unknown-sgx
5+
//@ compile-flags: --target x86_64-fortanix-unknown-sgx -Copt-level=0
6+
//@ needs-llvm-components: x86
7+
8+
#![feature(no_core, lang_items, f16)]
9+
#![crate_type = "lib"]
10+
#![no_core]
11+
12+
extern crate minicore;
13+
use minicore::*;
614

715
#[no_mangle]
8-
pub extern "C" fn plus_one(r: &mut u64) {
9-
*r = *r + 1;
16+
pub extern "C" fn dereference(a: &mut u64) -> u64 {
17+
// CHECK-LABEL: dereference
18+
// CHECK: lfence
19+
// CHECK: mov
20+
// CHECK: popq [[REGISTER:%[a-z]+]]
21+
// CHECK-NEXT: lfence
22+
// CHECK-NEXT: jmpq *[[REGISTER]]
23+
*a
1024
}
11-
12-
// CHECK: plus_one
13-
// CHECK: lfence
14-
// CHECK-NEXT: incq
15-
// CHECK: popq [[REGISTER:%[a-z]+]]
16-
// CHECK-NEXT: lfence
17-
// CHECK-NEXT: jmpq *[[REGISTER]]
Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
// Test LVI ret hardening on generic rust code
22

3+
//@ add-core-stubs
34
//@ assembly-output: emit-asm
4-
//@ compile-flags: --crate-type staticlib
5-
//@ only-x86_64-fortanix-unknown-sgx
5+
//@ compile-flags: --target x86_64-fortanix-unknown-sgx
6+
//@ needs-llvm-components: x86
7+
8+
#![feature(no_core, lang_items, f16)]
9+
#![crate_type = "lib"]
10+
#![no_core]
11+
12+
extern crate minicore;
13+
use minicore::*;
614

715
#[no_mangle]
816
pub extern "C" fn myret() {}
9-
// CHECK: myret:
17+
// CHECK-LABEL: myret:
1018
// CHECK: popq [[REGISTER:%[a-z]+]]
1119
// CHECK-NEXT: lfence
1220
// CHECK-NEXT: jmpq *[[REGISTER]]

tests/assembly-llvm/x86_64-fortanix-unknown-sgx-lvi-inline-assembly.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
// Test LVI load hardening on SGX inline assembly code
22

3+
//@ add-core-stubs
34
//@ assembly-output: emit-asm
4-
//@ compile-flags: --crate-type staticlib
5-
//@ only-x86_64-fortanix-unknown-sgx
5+
//@ compile-flags: --target x86_64-fortanix-unknown-sgx
6+
//@ needs-llvm-components: x86
67

7-
use std::arch::asm;
8+
#![feature(no_core, lang_items, f16)]
9+
#![crate_type = "lib"]
10+
#![no_core]
11+
12+
extern crate minicore;
13+
use minicore::*;
814

915
#[no_mangle]
1016
pub extern "C" fn get(ptr: *const u64) -> u64 {
17+
// CHECK-LABEL: get
18+
// CHECK: movq
19+
// CHECK-NEXT: lfence
1120
let value: u64;
1221
unsafe {
1322
asm!("mov {}, [{}]",
@@ -17,18 +26,13 @@ pub extern "C" fn get(ptr: *const u64) -> u64 {
1726
value
1827
}
1928

20-
// CHECK: get
21-
// CHECK: movq
22-
// CHECK-NEXT: lfence
23-
2429
#[no_mangle]
2530
pub extern "C" fn myret() {
31+
// CHECK-LABEL: myret
32+
// CHECK: shlq $0, (%rsp)
33+
// CHECK-NEXT: lfence
34+
// CHECK-NEXT: retq
2635
unsafe {
2736
asm!("ret");
2837
}
2938
}
30-
31-
// CHECK: myret
32-
// CHECK: shlq $0, (%rsp)
33-
// CHECK-NEXT: lfence
34-
// CHECK-NEXT: retq

0 commit comments

Comments
 (0)