Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

probe-stack=inline-asm will produce invalid uwtables #48944

Open
nagisa opened this issue Mar 16, 2021 · 3 comments
Open

probe-stack=inline-asm will produce invalid uwtables #48944

nagisa opened this issue Mar 16, 2021 · 3 comments
Labels
backend:X86 bugzilla Issues migrated from bugzilla

Comments

@nagisa
Copy link
Member

nagisa commented Mar 16, 2021

Bugzilla Link 49600
Version trunk
OS All
CC @topperc,@RKSimon,@phoebewang,@rotateright

Extended Description

Given a function as such

; RUN: llc < %s
define void @​big_stack() "probe-stack"="inline-asm" uwtable {
start:
%_two_page_stack = alloca [8192 x i8], align 1
ret void
}

the following assembly will be generated:

big_stack:
.cfi_startproc
subq $4096, %rsp
movq $0, (%rsp)
subq $3968, %rsp
.cfi_def_cfa_offset 8072
addq $8064, %rsp
.cfi_def_cfa_offset 8
retq

Here the unwind tables are not accurate while stack probing is ongoing – the rsp is adjusted, but not the cfa_offsets. And so attempts to obtain a stack trace will fail if the current instruction is somewhere in between the instructions implementing the stack probing.

This also occurs with the non-unrolled implementation of the stack probing:

; RUN: llc < %s
define void @​big_stack() "probe-stack"="inline-asm" uwtable {
start:
%_two_page_stack = alloca [64000 x i8], align 1
ret void
}

--->

big_stack:
.cfi_startproc
movq %rsp, %r11
subq $61440, %r11
.LBB0_1:
subq $4096, %rsp
movq $0, (%rsp)
cmpq %r11, %rsp
jne .LBB0_1
subq $2432, %rsp
.cfi_def_cfa_offset 63880
addq $63872, %rsp
.cfi_def_cfa_offset 8
retq

however in the loop case the solution needs to involve allocation of a separate register as insertion of .cfi directives in a loop won't help in any way.

@nagisa
Copy link
Member Author

nagisa commented Mar 16, 2021

The correct assembly for the unrolled case would probably look a lot like this:

big_stack:
.cfi_startproc
subq $4096, %rsp
.cfi_def_cfa_offset 4096
movq $0, (%rsp)
subq $3968, %rsp
.cfi_def_cfa_offset 8072
addq $8064, %rsp
.cfi_def_cfa_offset 8
retq

or an equivalent using .cfi_adjust_cfa_offset directives.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 11, 2021
@erikdesjardins
Copy link
Member

Update: the unrolled/inline case was fixed in https://reviews.llvm.org/D99579 / 1c268a8.

The loop case is still unfixed.

@erikdesjardins
Copy link
Member

erikdesjardins commented Jan 7, 2022

Loop case fixed by https://reviews.llvm.org/D116628 / a8ac117.

I believe this can now be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:X86 bugzilla Issues migrated from bugzilla
Projects
None yet
Development

No branches or pull requests

2 participants