-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CFI information to __rust_probestack
In order for GDB to correctly backtrace a stack overflow, it needs CFI information in __rust_probestack. This turns the following backtrace, ``` >> bt #0 0x0000555555576f73 in __rust_probestack () at /cargo/registry/src/github.com-1ecc6299db9ec823/compiler_builtins-0.1.14/src/probestack.rs:55 Backtrace stopped: Cannot access memory at address 0x7fffff7fedf0 ``` To this: ``` >>> bt #0 0x0000555555574e47 in __rust_probestack () #1 0x00005555555595ba in test::main () #2 0x00005555555594f3 in std::rt::lang_start::{{closure}} () #3 0x0000555555561ae3 in std::panicking::try::do_call () #4 0x000055555556595a in __rust_maybe_catch_panic () #5 0x000055555555af9b in std::rt::lang_start_internal () #6 0x00005555555594d5 in std::rt::lang_start () #7 0x000055555555977b in main () ```
- Loading branch information
Showing
6 changed files
with
112 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule libm
updated
from 01bee7 to 0ae442
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// This is the same as x86_64, only translated for 32-bit sizes. Note that on | ||
// Unix we're expected to restore everything as it was, this function basically | ||
// can't tamper with anything. | ||
// | ||
// The ABI here is the same as x86_64, except everything is 32-bits large. | ||
|
||
.text | ||
.globl __rust_probestack | ||
.type __rust_probestack, @function | ||
__rust_probestack: | ||
.cfi_startproc | ||
pushq %ebp | ||
.cfi_def_cfa_offset 8 | ||
.cfi_offset 6, -8 | ||
movq %esp, %ebp | ||
.cfi_def_cfa_register 6 | ||
push %ecx | ||
mov %eax,%ecx | ||
|
||
cmp $0x1000,%ecx | ||
jna 3f | ||
2: | ||
sub $0x1000,%esp | ||
test %esp,8(%esp) | ||
sub $0x1000,%ecx | ||
cmp $0x1000,%ecx | ||
ja 2b | ||
|
||
3: | ||
sub %ecx,%esp | ||
test %esp,8(%esp) | ||
|
||
add %eax,%esp | ||
pop %ecx | ||
leave | ||
.cfi_def_cfa 7, 8 | ||
ret | ||
.cfi_endproc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Our goal here is to touch each page between %rsp+8 and %rsp+8-%rax, | ||
// ensuring that if any pages are unmapped we'll make a page fault. | ||
// | ||
// The ABI here is that the stack frame size is located in `%eax`. Upon | ||
// return we're not supposed to modify `%esp` or `%eax`. | ||
|
||
.text | ||
.p2align 4,,15 | ||
.globl __rust_probestack | ||
.type __rust_probestack, @function | ||
__rust_probestack: | ||
.cfi_startproc | ||
pushq %rbp | ||
.cfi_def_cfa_offset 16 | ||
.cfi_offset 6, -16 | ||
movq %rsp, %rbp | ||
.cfi_def_cfa_register 6 | ||
mov %rax,%r11 | ||
// duplicate %rax as we're clobbering %r11 | ||
|
||
// Main loop, taken in one page increments. We're decrementing rsp by | ||
// a page each time until there's less than a page remaining. We're | ||
// guaranteed that this function isn't called unless there's more than a | ||
// page needed. | ||
// | ||
// Note that we're also testing against `8(%rsp)` to account for the 8 | ||
// bytes pushed on the stack orginally with our return address. Using | ||
// `8(%rsp)` simulates us testing the stack pointer in the caller's | ||
// context. | ||
|
||
// It's usually called when %rax >= 0x1000, but that's not always true. | ||
// Dynamic stack allocation, which is needed to implement unsized | ||
// rvalues, triggers stackprobe even if %rax < 0x1000. | ||
// Thus we have to check %r11 first to avoid segfault. | ||
cmp $0x1000,%r11 | ||
jna 3f | ||
2: | ||
sub $0x1000,%rsp | ||
test %rsp,8(%rsp) | ||
sub $0x1000,%r11 | ||
cmp $0x1000,%r11 | ||
ja 2b | ||
|
||
3: | ||
// Finish up the last remaining stack space requested, getting the last | ||
// bits out of r11 | ||
sub %r11,%rsp | ||
test %rsp,8(%rsp) | ||
|
||
// Restore the stack pointer to what it previously was when entering | ||
// this function. The caller will readjust the stack pointer after we | ||
// return. | ||
add %rax,%rsp | ||
leave | ||
.cfi_def_cfa 7, 8 | ||
ret | ||
.cfi_endproc |