Skip to content

Commit 5064ce0

Browse files
authored
Avoid using ebx as an asm! operand (rust-lang#1121)
It is sometimes reserved by LLVM.
1 parent bc1ce17 commit 5064ce0

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

crates/core_arch/src/x86/cpuid.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,28 +56,29 @@ pub unsafe fn __cpuid_count(leaf: u32, sub_leaf: u32) -> CpuidResult {
5656
let ecx;
5757
let edx;
5858

59+
// LLVM sometimes reserves `ebx` for its internal use, we so we need to use
60+
// a scratch register for it instead.
5961
#[cfg(target_arch = "x86")]
6062
{
6163
asm!(
64+
"mov {0}, ebx",
6265
"cpuid",
66+
"xchg {0}, ebx",
67+
lateout(reg) ebx,
6368
inlateout("eax") leaf => eax,
64-
lateout("ebx") ebx,
6569
inlateout("ecx") sub_leaf => ecx,
6670
lateout("edx") edx,
6771
options(nostack, preserves_flags),
6872
);
6973
}
7074
#[cfg(target_arch = "x86_64")]
7175
{
72-
// x86-64 uses `rbx` as the base register, so preserve it.
73-
// This works around a bug in LLVM with ASAN enabled:
74-
// https://bugs.llvm.org/show_bug.cgi?id=17907
7576
asm!(
76-
"mov rsi, rbx",
77+
"mov {0:r}, rbx",
7778
"cpuid",
78-
"xchg rsi, rbx",
79+
"xchg {0:r}, rbx",
80+
lateout(reg) ebx,
7981
inlateout("eax") leaf => eax,
80-
lateout("esi") ebx,
8182
inlateout("ecx") sub_leaf => ecx,
8283
lateout("edx") edx,
8384
options(nostack, preserves_flags),

0 commit comments

Comments
 (0)