rustc: Implement stack probes for x86 by alexcrichton · Pull Request #42816 · rust-lang/rust (original) (raw)

To illustrate. Let's say we translate this LLVM IR:

declare void @use([40096 x i8]*)

define i32 @test(i32 %a, i32 %b, i32 %c, i32 %d) "probe-stack"="__probestack" { %array = alloca [40096 x i8], align 16 call void @use([40096 x i8]* %array) ret i32 %d }

This results in the following assembly:

test:                                   # @test
        pushq   %rbx
        movl    $40096, %eax            # imm = 0x9CA0
        callq   __probestack
        subq    %rax, %rsp
        movl    %ecx, %ebx
        movq    %rsp, %rdi
        callq   use
        movl    %ebx, %eax
        addq    $40096, %rsp            # imm = 0x9CA0
        popq    %rbx
        retq

As you can see %ecx is not saved around the __probestack call. You have to save it there.