Skip to content

Commit e4fee1c

Browse files
committed
Remove AT&T syntax from the check stack functions
1 parent a0df7aa commit e4fee1c

File tree

2 files changed

+26
-28
lines changed

2 files changed

+26
-28
lines changed

compiler-builtins/src/x86.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,25 @@ intrinsics! {
2828
pub unsafe extern "C" fn _alloca() {
2929
// __chkstk and _alloca are the same function
3030
core::arch::naked_asm!(
31-
"push %ecx",
32-
"cmp $0x1000,%eax",
33-
"lea 8(%esp),%ecx", // esp before calling this routine -> ecx
31+
"push ecx",
32+
"cmp eax, 0x1000",
33+
"lea ecx, [esp + 8]", // esp before calling this routine -> ecx
3434
"jb 1f",
3535
"2:",
36-
"sub $0x1000,%ecx",
37-
"test %ecx,(%ecx)",
38-
"sub $0x1000,%eax",
39-
"cmp $0x1000,%eax",
36+
"sub ecx, 0x1000",
37+
"test [ecx], ecx",
38+
"sub eax, 0x1000",
39+
"cmp eax, 0x1000",
4040
"ja 2b",
4141
"1:",
42-
"sub %eax,%ecx",
43-
"test %ecx,(%ecx)",
44-
"lea 4(%esp),%eax", // load pointer to the return address into eax
45-
"mov %ecx,%esp", // install the new top of stack pointer into esp
46-
"mov -4(%eax),%ecx", // restore ecx
47-
"push (%eax)", // push return address onto the stack
48-
"sub %esp,%eax", // restore the original value in eax
42+
"sub ecx, eax",
43+
"test [ecx], ecx",
44+
"lea eax, [esp + 4]", // load pointer to the return address into eax
45+
"mov esp, ecx", // install the new top of stack pointer into esp
46+
"mov ecx, [eax - 4]", // restore ecx
47+
"push [eax]", // push return address onto the stack
48+
"sub eax, esp", // restore the original value in eax
4949
"ret",
50-
options(att_syntax)
5150
);
5251
}
5352
}

compiler-builtins/src/x86_64.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,23 @@ intrinsics! {
1919
))]
2020
pub unsafe extern "C" fn ___chkstk_ms() {
2121
core::arch::naked_asm!(
22-
"push %rcx",
23-
"push %rax",
24-
"cmp $0x1000,%rax",
25-
"lea 24(%rsp),%rcx",
22+
"push rcx",
23+
"push rax",
24+
"cmp rax, 0x1000",
25+
"lea rcx, [rsp + 24]",
2626
"jb 1f",
2727
"2:",
28-
"sub $0x1000,%rcx",
29-
"test %rcx,(%rcx)",
30-
"sub $0x1000,%rax",
31-
"cmp $0x1000,%rax",
28+
"sub rcx, 0x1000",
29+
"test [rcx], rcx",
30+
"sub rax, 0x1000",
31+
"cmp rax, 0x1000",
3232
"ja 2b",
3333
"1:",
34-
"sub %rax,%rcx",
35-
"test %rcx,(%rcx)",
36-
"pop %rax",
37-
"pop %rcx",
34+
"sub rcx, rax",
35+
"test [rcx], rcx",
36+
"pop rax",
37+
"pop rcx",
3838
"ret",
39-
options(att_syntax)
4039
);
4140
}
4241
}

0 commit comments

Comments
 (0)