Skip to content

Commit c0127e4

Browse files
committed
Auto merge of rust-lang#77292 - lzutao:std_asm, r=Amanieu
Prefer asm! in std - all in sgx module Similar to the change in rust-lang#76669 but all `llvm_asm!` is gate in x86/x86_64 target. Godbolt: - https://rust.godbolt.org/z/h7nG1h - https://rust.godbolt.org/z/xx39hW
2 parents 6ac6c67 + d477201 commit c0127e4

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

library/std/src/sys/sgx/abi/mem.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,15 @@ extern "C" {
2121
#[inline(always)]
2222
#[unstable(feature = "sgx_platform", issue = "56975")]
2323
pub fn image_base() -> u64 {
24-
let base;
25-
unsafe { llvm_asm!("lea IMAGE_BASE(%rip),$0":"=r"(base)) };
24+
let base: u64;
25+
unsafe {
26+
asm!(
27+
"lea IMAGE_BASE(%rip), {}",
28+
lateout(reg) base,
29+
// NOTE(#76738): ATT syntax is used to support LLVM 8 and 9.
30+
options(att_syntax, nostack, preserves_flags, nomem, pure),
31+
)
32+
};
2633
base
2734
}
2835

library/std/src/sys/sgx/ext/arch.rs

+15-14
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ pub fn egetkey(request: &Align512<[u8; 512]>) -> Result<Align16<[u8; 16]>, u32>
3131
let mut out = MaybeUninit::uninit();
3232
let error;
3333

34-
llvm_asm!(
35-
"enclu"
36-
: "={eax}"(error)
37-
: "{eax}"(ENCLU_EGETKEY),
38-
"{rbx}"(request),
39-
"{rcx}"(out.as_mut_ptr())
40-
: "flags"
34+
asm!(
35+
"enclu",
36+
inlateout("eax") ENCLU_EGETKEY => error,
37+
in("rbx") request,
38+
in("rcx") out.as_mut_ptr(),
39+
// NOTE(#76738): ATT syntax is used to support LLVM 8 and 9.
40+
options(att_syntax, nostack),
4141
);
4242

4343
match error {
@@ -60,13 +60,14 @@ pub fn ereport(
6060
unsafe {
6161
let mut report = MaybeUninit::uninit();
6262

63-
llvm_asm!(
64-
"enclu"
65-
: /* no output registers */
66-
: "{eax}"(ENCLU_EREPORT),
67-
"{rbx}"(targetinfo),
68-
"{rcx}"(reportdata),
69-
"{rdx}"(report.as_mut_ptr())
63+
asm!(
64+
"enclu",
65+
in("eax") ENCLU_EREPORT,
66+
in("rbx") targetinfo,
67+
in("rcx") reportdata,
68+
in("rdx") report.as_mut_ptr(),
69+
// NOTE(#76738): ATT syntax is used to support LLVM 8 and 9.
70+
options(att_syntax, preserves_flags, nostack),
7071
);
7172

7273
report.assume_init()

0 commit comments

Comments
 (0)