-
Notifications
You must be signed in to change notification settings - Fork 13k
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
EXPERIMENT: support well-nested unwinds #99260
Conversation
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
(rust-highfive has picked a reviewer for you, use r? to override) |
Very much a lang concern as well; tagging so it doesn't get accidentally overlooked. @rustbot modify labels +T-lang |
In #67502 Mark and I worked to make Could you show the disassembly of this code with & without your change? #![feature(c_unwind)]
extern "C-unwind" {
fn happy();
fn unfortunate();
}
#[inline(never)]
#[no_mangle]
pub fn notable_function() -> i32 {
unsafe {
std::panic::catch_unwind(|| {
happy(); 42
}).unwrap_or_else(|e| {
std::mem::forget(e);
unfortunate();
13
})
}
} |
Also this PR doesn't handle interactions with exceptions from other languages. If a C++ exception unwinds through Rust code then the panic count will not have been incremented. Similarly if Rust code is executing within a C++ |
Assembly generated by the above file with
38b7215 (nightly 2022-07-11) .text
.def @feat.00;
.scl 3;
.type 0;
.endef
.globl @feat.00
.set @feat.00, 0
.file "lib.4978488e-cgu.0"
.def notable_function;
.scl 2;
.type 32;
.endef
.section .text,"xr",one_only,notable_function
.globl notable_function
.p2align 4, 0x90
notable_function:
.Lfunc_begin0:
.seh_proc notable_function
.seh_handler __CxxFrameHandler3, @unwind, @except
pushq %rbp
.seh_pushreg %rbp
subq $48, %rsp
.seh_stackalloc 48
leaq 48(%rsp), %rbp
.seh_setframe %rbp, 48
.seh_endprologue
movq $-2, -16(%rbp)
.Ltmp0:
callq happy
.Ltmp1:
movl $42, %eax
.LBB0_5:
addq $48, %rsp
popq %rbp
retq
.LBB0_4:
$ehgcr_0_4:
callq unfortunate
movl $13, %eax
jmp .LBB0_5
.seh_handlerdata
.long ($cppxdata$notable_function)@IMGREL
.section .text,"xr",one_only,notable_function
.seh_endproc
.def "?catch$2@?0?notable_function@4HA";
.scl 3;
.type 32;
.endef
.p2align 4, 0x90
"?catch$2@?0?notable_function@4HA":
.seh_proc "?catch$2@?0?notable_function@4HA"
.seh_handler __CxxFrameHandler3, @unwind, @except
.LBB0_2:
movq %rdx, 16(%rsp)
pushq %rbp
.seh_pushreg %rbp
subq $32, %rsp
.seh_stackalloc 32
leaq 48(%rdx), %rbp
.seh_endprologue
movq -8(%rbp), %rcx
callq _ZN3std9panicking3try7cleanup17h9c87e793fb4cdaabE
leaq .LBB0_4(%rip), %rax
addq $32, %rsp
popq %rbp
retq
.seh_handlerdata
.long ($cppxdata$notable_function)@IMGREL
.section .text,"xr",one_only,notable_function
.seh_endproc
.def "?catch$3@?0?notable_function@4HA";
.scl 3;
.type 32;
.endef
.p2align 4, 0x90
"?catch$3@?0?notable_function@4HA":
.seh_proc "?catch$3@?0?notable_function@4HA"
.seh_handler __CxxFrameHandler3, @unwind, @except
.LBB0_3:
movq %rdx, 16(%rsp)
pushq %rbp
.seh_pushreg %rbp
subq $32, %rsp
.seh_stackalloc 32
leaq 48(%rdx), %rbp
.seh_endprologue
xorl %ecx, %ecx
callq _ZN3std9panicking3try7cleanup17h9c87e793fb4cdaabE
leaq .LBB0_4(%rip), %rax
addq $32, %rsp
popq %rbp
retq
.Lfunc_end0:
.seh_handlerdata
.long ($cppxdata$notable_function)@IMGREL
.section .text,"xr",one_only,notable_function
.seh_endproc
.section .xdata,"dr",associative,notable_function
.p2align 2
$cppxdata$notable_function:
.long 429065506
.long 2
.long ($stateUnwindMap$notable_function)@IMGREL
.long 1
.long ($tryMap$notable_function)@IMGREL
.long 5
.long ($ip2state$notable_function)@IMGREL
.long 32
.long 0
.long 1
$stateUnwindMap$notable_function:
.long -1
.long 0
.long -1
.long 0
$tryMap$notable_function:
.long 0
.long 0
.long 1
.long 2
.long ($handlerMap$0$notable_function)@IMGREL
$handlerMap$0$notable_function:
.long 8
.long __rust_panic_type_info@IMGREL
.long 40
.long "?catch$2@?0?notable_function@4HA"@IMGREL
.long 56
.long 64
.long 0
.long 0
.long "?catch$3@?0?notable_function@4HA"@IMGREL
.long 56
$ip2state$notable_function:
.long .Lfunc_begin0@IMGREL
.long -1
.long .Ltmp0@IMGREL+1
.long 0
.long .Ltmp1@IMGREL+1
.long -1
.long "?catch$2@?0?notable_function@4HA"@IMGREL
.long 1
.long "?catch$3@?0?notable_function@4HA"@IMGREL
.long 1
.section .text,"xr",one_only,notable_function
.section .data,"dw",discard,__rust_panic_type_info
.globl __rust_panic_type_info
.p2align 4
__rust_panic_type_info:
.quad "??_7type_info@@6B@"
.quad 0
.asciz "rust_panic"
.zero 5 9c2f009 (this PR stage1) .text
.def @feat.00;
.scl 3;
.type 0;
.endef
.globl @feat.00
.set @feat.00, 0
.file "lib.68a3e9dc-cgu.0"
.def notable_function;
.scl 2;
.type 32;
.endef
.section .text,"xr",one_only,notable_function
.globl notable_function
.p2align 4, 0x90
notable_function:
.Lfunc_begin0:
.seh_proc notable_function
.seh_handler __CxxFrameHandler3, @unwind, @except
pushq %rbp
.seh_pushreg %rbp
subq $80, %rsp
.seh_stackalloc 80
leaq 80(%rsp), %rbp
.seh_setframe %rbp, 80
.seh_endprologue
movq $-2, -16(%rbp)
movq __imp__ZN3std9panicking11panic_count18GLOBAL_PANIC_COUNT17h832a50073c85f225E(%rip), %rax
movq (%rax), %rax
shlq $1, %rax
testq %rax, %rax
jne .LBB0_2
movl $0, -20(%rbp)
.LBB0_3:
.Ltmp0:
callq happy
.Ltmp1:
movb $1, %al
movq %rax, -32(%rbp)
movl $42, %eax
movq %rax, -40(%rbp)
.LBB0_5:
$ehgcr_0_5:
cmpb $0, -20(%rbp)
je .LBB0_6
callq _ZN3std9panicking11panic_count8increase17h424b40195d3e6f0fE
.LBB0_6:
cmpb $0, -32(%rbp)
movq -40(%rbp), %rax
jne .LBB0_8
callq unfortunate
movl $13, %eax
.LBB0_8:
addq $80, %rsp
popq %rbp
retq
.LBB0_2:
callq _ZN3std9panicking11panic_count22try_decrease_slow_path17hf1721c3fb8e2c7e3E
movl %eax, -20(%rbp)
jmp .LBB0_3
.seh_handlerdata
.long ($cppxdata$notable_function)@IMGREL
.section .text,"xr",one_only,notable_function
.seh_endproc
.def "?catch$9@?0?notable_function@4HA";
.scl 3;
.type 32;
.endef
.p2align 4, 0x90
"?catch$9@?0?notable_function@4HA":
.seh_proc "?catch$9@?0?notable_function@4HA"
.seh_handler __CxxFrameHandler3, @unwind, @except
.LBB0_9:
movq %rdx, 16(%rsp)
pushq %rbp
.seh_pushreg %rbp
subq $32, %rsp
.seh_stackalloc 32
leaq 80(%rdx), %rbp
.seh_endprologue
movq -8(%rbp), %rcx
callq _ZN3std9panicking3try7cleanup17h09cddad23dc8025dE
movq %rax, -40(%rbp)
xorl %eax, %eax
movq %rax, -32(%rbp)
leaq .LBB0_5(%rip), %rax
addq $32, %rsp
popq %rbp
retq
.seh_handlerdata
.long ($cppxdata$notable_function)@IMGREL
.section .text,"xr",one_only,notable_function
.seh_endproc
.def "?catch$10@?0?notable_function@4HA";
.scl 3;
.type 32;
.endef
.p2align 4, 0x90
"?catch$10@?0?notable_function@4HA":
.seh_proc "?catch$10@?0?notable_function@4HA"
.seh_handler __CxxFrameHandler3, @unwind, @except
.LBB0_10:
movq %rdx, 16(%rsp)
pushq %rbp
.seh_pushreg %rbp
subq $32, %rsp
.seh_stackalloc 32
leaq 80(%rdx), %rbp
.seh_endprologue
xorl %eax, %eax
movq %rax, -32(%rbp)
xorl %ecx, %ecx
callq _ZN3std9panicking3try7cleanup17h09cddad23dc8025dE
movq %rax, -40(%rbp)
leaq .LBB0_5(%rip), %rax
addq $32, %rsp
popq %rbp
retq
.Lfunc_end0:
.seh_handlerdata
.long ($cppxdata$notable_function)@IMGREL
.section .text,"xr",one_only,notable_function
.seh_endproc
.section .xdata,"dr",associative,notable_function
.p2align 2
$cppxdata$notable_function:
.long 429065506
.long 2
.long ($stateUnwindMap$notable_function)@IMGREL
.long 1
.long ($tryMap$notable_function)@IMGREL
.long 5
.long ($ip2state$notable_function)@IMGREL
.long 64
.long 0
.long 1
$stateUnwindMap$notable_function:
.long -1
.long 0
.long -1
.long 0
$tryMap$notable_function:
.long 0
.long 0
.long 1
.long 2
.long ($handlerMap$0$notable_function)@IMGREL
$handlerMap$0$notable_function:
.long 8
.long __rust_panic_type_info@IMGREL
.long 72
.long "?catch$9@?0?notable_function@4HA"@IMGREL
.long 56
.long 64
.long 0
.long 0
.long "?catch$10@?0?notable_function@4HA"@IMGREL
.long 56
$ip2state$notable_function:
.long .Lfunc_begin0@IMGREL
.long -1
.long .Ltmp0@IMGREL+1
.long 0
.long .Ltmp1@IMGREL+1
.long -1
.long "?catch$9@?0?notable_function@4HA"@IMGREL
.long 1
.long "?catch$10@?0?notable_function@4HA"@IMGREL
.long 1
.section .text,"xr",one_only,notable_function
.section .data,"dw",discard,__rust_panic_type_info
.globl __rust_panic_type_info
.p2align 4
__rust_panic_type_info:
.quad "??_7type_info@@6B@"
.quad 0
.asciz "rust_panic"
.zero 5 diff nightly..stage1--- nightly.s 2022-07-15 12:57:59.597679100 -0400
+++ stage1.s 2022-07-15 12:57:50.383291800 -0400
@@ -5,7 +5,7 @@
.endef
.globl @feat.00
.set @feat.00, 0
- .file "lib.4978488e-cgu.0"
+ .file "lib.68a3e9dc-cgu.0"
.def notable_function;
.scl 2;
.type 32;
@@ -19,48 +19,71 @@
.seh_handler __CxxFrameHandler3, @unwind, @except
pushq %rbp
.seh_pushreg %rbp
- subq $48, %rsp
- .seh_stackalloc 48
- leaq 48(%rsp), %rbp
- .seh_setframe %rbp, 48
+ subq $80, %rsp
+ .seh_stackalloc 80
+ leaq 80(%rsp), %rbp
+ .seh_setframe %rbp, 80
.seh_endprologue
movq $-2, -16(%rbp)
+ movq __imp__ZN3std9panicking11panic_count18GLOBAL_PANIC_COUNT17h832a50073c85f225E(%rip), %rax
+ movq (%rax), %rax
+ shlq $1, %rax
+ testq %rax, %rax
+ jne .LBB0_2
+ movl $0, -20(%rbp)
+.LBB0_3:
.Ltmp0:
callq happy
.Ltmp1:
+ movb $1, %al
+ movq %rax, -32(%rbp)
movl $42, %eax
+ movq %rax, -40(%rbp)
.LBB0_5:
- addq $48, %rsp
- popq %rbp
- retq
-.LBB0_4:
-$ehgcr_0_4:
+$ehgcr_0_5:
+ cmpb $0, -20(%rbp)
+ je .LBB0_6
+ callq _ZN3std9panicking11panic_count8increase17h424b40195d3e6f0fE
+.LBB0_6:
+ cmpb $0, -32(%rbp)
+ movq -40(%rbp), %rax
+ jne .LBB0_8
callq unfortunate
movl $13, %eax
- jmp .LBB0_5
+.LBB0_8:
+ addq $80, %rsp
+ popq %rbp
+ retq
+.LBB0_2:
+ callq _ZN3std9panicking11panic_count22try_decrease_slow_path17hf1721c3fb8e2c7e3E
+ movl %eax, -20(%rbp)
+ jmp .LBB0_3
.seh_handlerdata
.long ($cppxdata$notable_function)@IMGREL
.section .text,"xr",one_only,notable_function
.seh_endproc
- .def "?catch$2@?0?notable_function@4HA";
+ .def "?catch$9@?0?notable_function@4HA";
.scl 3;
.type 32;
.endef
.p2align 4, 0x90
-"?catch$2@?0?notable_function@4HA":
-.seh_proc "?catch$2@?0?notable_function@4HA"
+"?catch$9@?0?notable_function@4HA":
+.seh_proc "?catch$9@?0?notable_function@4HA"
.seh_handler __CxxFrameHandler3, @unwind, @except
-.LBB0_2:
+.LBB0_9:
movq %rdx, 16(%rsp)
pushq %rbp
.seh_pushreg %rbp
subq $32, %rsp
.seh_stackalloc 32
- leaq 48(%rdx), %rbp
+ leaq 80(%rdx), %rbp
.seh_endprologue
movq -8(%rbp), %rcx
- callq _ZN3std9panicking3try7cleanup17h9c87e793fb4cdaabE
- leaq .LBB0_4(%rip), %rax
+ callq _ZN3std9panicking3try7cleanup17h09cddad23dc8025dE
+ movq %rax, -40(%rbp)
+ xorl %eax, %eax
+ movq %rax, -32(%rbp)
+ leaq .LBB0_5(%rip), %rax
addq $32, %rsp
popq %rbp
retq
@@ -68,25 +91,28 @@
.long ($cppxdata$notable_function)@IMGREL
.section .text,"xr",one_only,notable_function
.seh_endproc
- .def "?catch$3@?0?notable_function@4HA";
+ .def "?catch$10@?0?notable_function@4HA";
.scl 3;
.type 32;
.endef
.p2align 4, 0x90
-"?catch$3@?0?notable_function@4HA":
-.seh_proc "?catch$3@?0?notable_function@4HA"
+"?catch$10@?0?notable_function@4HA":
+.seh_proc "?catch$10@?0?notable_function@4HA"
.seh_handler __CxxFrameHandler3, @unwind, @except
-.LBB0_3:
+.LBB0_10:
movq %rdx, 16(%rsp)
pushq %rbp
.seh_pushreg %rbp
subq $32, %rsp
.seh_stackalloc 32
- leaq 48(%rdx), %rbp
+ leaq 80(%rdx), %rbp
.seh_endprologue
+ xorl %eax, %eax
+ movq %rax, -32(%rbp)
xorl %ecx, %ecx
- callq _ZN3std9panicking3try7cleanup17h9c87e793fb4cdaabE
- leaq .LBB0_4(%rip), %rax
+ callq _ZN3std9panicking3try7cleanup17h09cddad23dc8025dE
+ movq %rax, -40(%rbp)
+ leaq .LBB0_5(%rip), %rax
addq $32, %rsp
popq %rbp
retq
@@ -105,7 +131,7 @@
.long ($tryMap$notable_function)@IMGREL
.long 5
.long ($ip2state$notable_function)@IMGREL
- .long 32
+ .long 64
.long 0
.long 1
$stateUnwindMap$notable_function:
@@ -122,13 +148,13 @@
$handlerMap$0$notable_function:
.long 8
.long __rust_panic_type_info@IMGREL
- .long 40
- .long "?catch$2@?0?notable_function@4HA"@IMGREL
+ .long 72
+ .long "?catch$9@?0?notable_function@4HA"@IMGREL
.long 56
.long 64
.long 0
.long 0
- .long "?catch$3@?0?notable_function@4HA"@IMGREL
+ .long "?catch$10@?0?notable_function@4HA"@IMGREL
.long 56
$ip2state$notable_function:
.long .Lfunc_begin0@IMGREL
@@ -137,9 +163,9 @@
.long 0
.long .Ltmp1@IMGREL+1
.long -1
- .long "?catch$2@?0?notable_function@4HA"@IMGREL
+ .long "?catch$9@?0?notable_function@4HA"@IMGREL
.long 1
- .long "?catch$3@?0?notable_function@4HA"@IMGREL
+ .long "?catch$10@?0?notable_function@4HA"@IMGREL
.long 1
.section .text,"xr",one_only,notable_function
38b7215 (nightly 2022-07-11) .text
.def @feat.00;
.scl 3;
.type 0;
.endef
.globl @feat.00
.set @feat.00, 0
.file "lib.4978488e-cgu.0"
.def notable_function;
.scl 2;
.type 32;
.endef
.section .text,"xr",one_only,notable_function
.globl notable_function
.p2align 4, 0x90
notable_function:
.Lfunc_begin0:
.seh_proc notable_function
.seh_handler __CxxFrameHandler3, @unwind, @except
pushq %rbp
.seh_pushreg %rbp
subq $48, %rsp
.seh_stackalloc 48
leaq 48(%rsp), %rbp
.seh_setframe %rbp, 48
.seh_endprologue
movq $-2, -8(%rbp)
.Ltmp0:
callq happy
.Ltmp1:
movl $42, %eax
addq $48, %rsp
popq %rbp
retq
.seh_handlerdata
.long ($cppxdata$notable_function)@IMGREL
.section .text,"xr",one_only,notable_function
.seh_endproc
.def "?catch$2@?0?notable_function@4HA";
.scl 3;
.type 32;
.endef
.p2align 4, 0x90
"?catch$2@?0?notable_function@4HA":
.seh_proc "?catch$2@?0?notable_function@4HA"
.seh_handler __CxxFrameHandler3, @unwind, @except
.LBB0_2:
movq %rdx, 16(%rsp)
pushq %rbp
.seh_pushreg %rbp
subq $32, %rsp
.seh_stackalloc 32
leaq 48(%rdx), %rbp
.seh_endprologue
callq _ZN4core9panicking15panic_no_unwind17hedc8ed309bafae40E
ud2
.Lfunc_end0:
.seh_handlerdata
.long ($cppxdata$notable_function)@IMGREL
.section .text,"xr",one_only,notable_function
.seh_endproc
.section .xdata,"dr",associative,notable_function
.p2align 2
$cppxdata$notable_function:
.long 429065506
.long 2
.long ($stateUnwindMap$notable_function)@IMGREL
.long 1
.long ($tryMap$notable_function)@IMGREL
.long 4
.long ($ip2state$notable_function)@IMGREL
.long 40
.long 0
.long 1
$stateUnwindMap$notable_function:
.long -1
.long 0
.long -1
.long 0
$tryMap$notable_function:
.long 0
.long 0
.long 1
.long 1
.long ($handlerMap$0$notable_function)@IMGREL
$handlerMap$0$notable_function:
.long 64
.long 0
.long 0
.long "?catch$2@?0?notable_function@4HA"@IMGREL
.long 56
$ip2state$notable_function:
.long .Lfunc_begin0@IMGREL
.long -1
.long .Ltmp0@IMGREL+1
.long 0
.long .Ltmp1@IMGREL+1
.long -1
.long "?catch$2@?0?notable_function@4HA"@IMGREL
.long 1
.section .text,"xr",one_only,notable_function 9c2f009 (this PR stage1) .text
.def @feat.00;
.scl 3;
.type 0;
.endef
.globl @feat.00
.set @feat.00, 0
.file "lib.68a3e9dc-cgu.0"
.def notable_function;
.scl 2;
.type 32;
.endef
.section .text,"xr",one_only,notable_function
.globl notable_function
.p2align 4, 0x90
notable_function:
.Lfunc_begin0:
.seh_proc notable_function
.seh_handler __CxxFrameHandler3, @unwind, @except
pushq %rbp
.seh_pushreg %rbp
pushq %rsi
.seh_pushreg %rsi
subq $40, %rsp
.seh_stackalloc 40
leaq 32(%rsp), %rbp
.seh_setframe %rbp, 32
.seh_endprologue
movq $-2, (%rbp)
movq __imp__ZN3std9panicking11panic_count18GLOBAL_PANIC_COUNT17h832a50073c85f225E(%rip), %rax
movq (%rax), %rax
shlq $1, %rax
testq %rax, %rax
jne .LBB0_2
xorl %esi, %esi
.LBB0_3:
.Ltmp0:
callq happy
.Ltmp1:
testb %sil, %sil
je .LBB0_6
callq _ZN3std9panicking11panic_count8increase17h424b40195d3e6f0fE
.LBB0_6:
movl $42, %eax
addq $40, %rsp
popq %rsi
popq %rbp
retq
.LBB0_2:
callq _ZN3std9panicking11panic_count22try_decrease_slow_path17hf1721c3fb8e2c7e3E
movl %eax, %esi
jmp .LBB0_3
.seh_handlerdata
.long ($cppxdata$notable_function)@IMGREL
.section .text,"xr",one_only,notable_function
.seh_endproc
.def "?catch$7@?0?notable_function@4HA";
.scl 3;
.type 32;
.endef
.p2align 4, 0x90
"?catch$7@?0?notable_function@4HA":
.seh_proc "?catch$7@?0?notable_function@4HA"
.seh_handler __CxxFrameHandler3, @unwind, @except
.LBB0_7:
movq %rdx, 16(%rsp)
pushq %rbp
.seh_pushreg %rbp
pushq %rsi
.seh_pushreg %rsi
subq $40, %rsp
.seh_stackalloc 40
leaq 32(%rdx), %rbp
.seh_endprologue
callq _ZN4core9panicking15panic_no_unwind17h49e55cbf27726099E
ud2
.Lfunc_end0:
.seh_handlerdata
.long ($cppxdata$notable_function)@IMGREL
.section .text,"xr",one_only,notable_function
.seh_endproc
.section .xdata,"dr",associative,notable_function
.p2align 2
$cppxdata$notable_function:
.long 429065506
.long 2
.long ($stateUnwindMap$notable_function)@IMGREL
.long 1
.long ($tryMap$notable_function)@IMGREL
.long 4
.long ($ip2state$notable_function)@IMGREL
.long 32
.long 0
.long 1
$stateUnwindMap$notable_function:
.long -1
.long 0
.long -1
.long 0
$tryMap$notable_function:
.long 0
.long 0
.long 1
.long 1
.long ($handlerMap$0$notable_function)@IMGREL
$handlerMap$0$notable_function:
.long 64
.long 0
.long 0
.long "?catch$7@?0?notable_function@4HA"@IMGREL
.long 72
$ip2state$notable_function:
.long .Lfunc_begin0@IMGREL
.long -1
.long .Ltmp0@IMGREL+1
.long 0
.long .Ltmp1@IMGREL+1
.long -1
.long "?catch$7@?0?notable_function@4HA"@IMGREL
.long 1
.section .text,"xr",one_only,notable_function diff nightly..stage1--- nightly.s 2022-07-15 13:31:36.175628300 -0400
+++ stage1.s 2022-07-15 13:33:55.657374900 -0400
@@ -5,7 +5,7 @@
.endef
.globl @feat.00
.set @feat.00, 0
- .file "lib.4978488e-cgu.0"
+ .file "lib.68a3e9dc-cgu.0"
.def notable_function;
.scl 2;
.type 32;
@@ -19,40 +19,60 @@
.seh_handler __CxxFrameHandler3, @unwind, @except
pushq %rbp
.seh_pushreg %rbp
- subq $48, %rsp
- .seh_stackalloc 48
- leaq 48(%rsp), %rbp
- .seh_setframe %rbp, 48
+ pushq %rsi
+ .seh_pushreg %rsi
+ subq $40, %rsp
+ .seh_stackalloc 40
+ leaq 32(%rsp), %rbp
+ .seh_setframe %rbp, 32
.seh_endprologue
- movq $-2, -8(%rbp)
+ movq $-2, (%rbp)
+ movq __imp__ZN3std9panicking11panic_count18GLOBAL_PANIC_COUNT17h832a50073c85f225E(%rip), %rax
+ movq (%rax), %rax
+ shlq $1, %rax
+ testq %rax, %rax
+ jne .LBB0_2
+ xorl %esi, %esi
+.LBB0_3:
.Ltmp0:
callq happy
.Ltmp1:
+ testb %sil, %sil
+ je .LBB0_6
+ callq _ZN3std9panicking11panic_count8increase17h424b40195d3e6f0fE
+.LBB0_6:
movl $42, %eax
- addq $48, %rsp
+ addq $40, %rsp
+ popq %rsi
popq %rbp
retq
+.LBB0_2:
+ callq _ZN3std9panicking11panic_count22try_decrease_slow_path17hf1721c3fb8e2c7e3E
+ movl %eax, %esi
+ jmp .LBB0_3
.seh_handlerdata
.long ($cppxdata$notable_function)@IMGREL
.section .text,"xr",one_only,notable_function
.seh_endproc
- .def "?catch$2@?0?notable_function@4HA";
+ .def "?catch$7@?0?notable_function@4HA";
.scl 3;
.type 32;
.endef
.p2align 4, 0x90
-"?catch$2@?0?notable_function@4HA":
-.seh_proc "?catch$2@?0?notable_function@4HA"
+"?catch$7@?0?notable_function@4HA":
+.seh_proc "?catch$7@?0?notable_function@4HA"
.seh_handler __CxxFrameHandler3, @unwind, @except
-.LBB0_2:
+.LBB0_7:
movq %rdx, 16(%rsp)
pushq %rbp
.seh_pushreg %rbp
- subq $32, %rsp
- .seh_stackalloc 32
- leaq 48(%rdx), %rbp
+ pushq %rsi
+ .seh_pushreg %rsi
+ subq $40, %rsp
+ .seh_stackalloc 40
+ leaq 32(%rdx), %rbp
.seh_endprologue
- callq _ZN4core9panicking15panic_no_unwind17hedc8ed309bafae40E
+ callq _ZN4core9panicking15panic_no_unwind17h49e55cbf27726099E
ud2
.Lfunc_end0:
.seh_handlerdata
@@ -69,7 +89,7 @@
.long ($tryMap$notable_function)@IMGREL
.long 4
.long ($ip2state$notable_function)@IMGREL
- .long 40
+ .long 32
.long 0
.long 1
$stateUnwindMap$notable_function:
@@ -87,8 +107,8 @@
.long 64
.long 0
.long 0
- .long "?catch$2@?0?notable_function@4HA"@IMGREL
- .long 56
+ .long "?catch$7@?0?notable_function@4HA"@IMGREL
+ .long 72
$ip2state$notable_function:
.long .Lfunc_begin0@IMGREL
.long -1
@@ -96,7 +116,7 @@
.long 0
.long .Ltmp1@IMGREL+1
.long -1
- .long "?catch$2@?0?notable_function@4HA"@IMGREL
+ .long "?catch$7@?0?notable_function@4HA"@IMGREL
.long 1
.section .text,"xr",one_only,notable_function Also clearly useful is comparing the diffs from 38b7215 (nightly 2022-07-11)--- unwind.s 2022-07-15 13:40:23.427159000 -0400
+++ abort.s 2022-07-15 13:40:17.596473500 -0400
@@ -24,20 +24,14 @@
leaq 48(%rsp), %rbp
.seh_setframe %rbp, 48
.seh_endprologue
- movq $-2, -16(%rbp)
+ movq $-2, -8(%rbp)
.Ltmp0:
callq happy
.Ltmp1:
movl $42, %eax
-.LBB0_5:
addq $48, %rsp
popq %rbp
retq
-.LBB0_4:
-$ehgcr_0_4:
- callq unfortunate
- movl $13, %eax
- jmp .LBB0_5
.seh_handlerdata
.long ($cppxdata$notable_function)@IMGREL
.section .text,"xr",one_only,notable_function
@@ -58,38 +52,8 @@
.seh_stackalloc 32
leaq 48(%rdx), %rbp
.seh_endprologue
- movq -8(%rbp), %rcx
- callq _ZN3std9panicking3try7cleanup17h9c87e793fb4cdaabE
- leaq .LBB0_4(%rip), %rax
- addq $32, %rsp
- popq %rbp
- retq
- .seh_handlerdata
- .long ($cppxdata$notable_function)@IMGREL
- .section .text,"xr",one_only,notable_function
- .seh_endproc
- .def "?catch$3@?0?notable_function@4HA";
- .scl 3;
- .type 32;
- .endef
- .p2align 4, 0x90
-"?catch$3@?0?notable_function@4HA":
-.seh_proc "?catch$3@?0?notable_function@4HA"
- .seh_handler __CxxFrameHandler3, @unwind, @except
-.LBB0_3:
- movq %rdx, 16(%rsp)
- pushq %rbp
- .seh_pushreg %rbp
- subq $32, %rsp
- .seh_stackalloc 32
- leaq 48(%rdx), %rbp
- .seh_endprologue
- xorl %ecx, %ecx
- callq _ZN3std9panicking3try7cleanup17h9c87e793fb4cdaabE
- leaq .LBB0_4(%rip), %rax
- addq $32, %rsp
- popq %rbp
- retq
+ callq _ZN4core9panicking15panic_no_unwind17hedc8ed309bafae40E
+ ud2
.Lfunc_end0:
.seh_handlerdata
.long ($cppxdata$notable_function)@IMGREL
@@ -103,9 +67,9 @@
.long ($stateUnwindMap$notable_function)@IMGREL
.long 1
.long ($tryMap$notable_function)@IMGREL
- .long 5
+ .long 4
.long ($ip2state$notable_function)@IMGREL
- .long 32
+ .long 40
.long 0
.long 1
$stateUnwindMap$notable_function:
@@ -117,18 +81,13 @@
.long 0
.long 0
.long 1
- .long 2
+ .long 1
.long ($handlerMap$0$notable_function)@IMGREL
$handlerMap$0$notable_function:
- .long 8
- .long __rust_panic_type_info@IMGREL
- .long 40
- .long "?catch$2@?0?notable_function@4HA"@IMGREL
- .long 56
.long 64
.long 0
.long 0
- .long "?catch$3@?0?notable_function@4HA"@IMGREL
+ .long "?catch$2@?0?notable_function@4HA"@IMGREL
.long 56
$ip2state$notable_function:
.long .Lfunc_begin0@IMGREL
@@ -139,15 +98,4 @@
.long -1
.long "?catch$2@?0?notable_function@4HA"@IMGREL
.long 1
- .long "?catch$3@?0?notable_function@4HA"@IMGREL
- .long 1
.section .text,"xr",one_only,notable_function
-
- .section .data,"dw",discard,__rust_panic_type_info
- .globl __rust_panic_type_info
- .p2align 4
-__rust_panic_type_info:
- .quad "??_7type_info@@6B@"
- .quad 0
- .asciz "rust_panic"
- .zero 5 9c2f009 (this PR stage1)--- unwind.s 2022-07-15 13:41:59.629266400 -0400
+++ abort.s 2022-07-15 13:42:09.911164300 -0400
@@ -19,103 +19,61 @@
.seh_handler __CxxFrameHandler3, @unwind, @except
pushq %rbp
.seh_pushreg %rbp
- subq $80, %rsp
- .seh_stackalloc 80
- leaq 80(%rsp), %rbp
- .seh_setframe %rbp, 80
+ pushq %rsi
+ .seh_pushreg %rsi
+ subq $40, %rsp
+ .seh_stackalloc 40
+ leaq 32(%rsp), %rbp
+ .seh_setframe %rbp, 32
.seh_endprologue
- movq $-2, -16(%rbp)
+ movq $-2, (%rbp)
movq __imp__ZN3std9panicking11panic_count18GLOBAL_PANIC_COUNT17h832a50073c85f225E(%rip), %rax
movq (%rax), %rax
shlq $1, %rax
testq %rax, %rax
jne .LBB0_2
- movl $0, -20(%rbp)
+ xorl %esi, %esi
.LBB0_3:
.Ltmp0:
callq happy
.Ltmp1:
- movb $1, %al
- movq %rax, -32(%rbp)
- movl $42, %eax
- movq %rax, -40(%rbp)
-.LBB0_5:
-$ehgcr_0_5:
- cmpb $0, -20(%rbp)
+ testb %sil, %sil
je .LBB0_6
callq _ZN3std9panicking11panic_count8increase17h424b40195d3e6f0fE
.LBB0_6:
- cmpb $0, -32(%rbp)
- movq -40(%rbp), %rax
- jne .LBB0_8
- callq unfortunate
- movl $13, %eax
-.LBB0_8:
- addq $80, %rsp
+ movl $42, %eax
+ addq $40, %rsp
+ popq %rsi
popq %rbp
retq
.LBB0_2:
callq _ZN3std9panicking11panic_count22try_decrease_slow_path17hf1721c3fb8e2c7e3E
- movl %eax, -20(%rbp)
+ movl %eax, %esi
jmp .LBB0_3
.seh_handlerdata
.long ($cppxdata$notable_function)@IMGREL
.section .text,"xr",one_only,notable_function
.seh_endproc
- .def "?catch$9@?0?notable_function@4HA";
+ .def "?catch$7@?0?notable_function@4HA";
.scl 3;
.type 32;
.endef
.p2align 4, 0x90
-"?catch$9@?0?notable_function@4HA":
-.seh_proc "?catch$9@?0?notable_function@4HA"
+"?catch$7@?0?notable_function@4HA":
+.seh_proc "?catch$7@?0?notable_function@4HA"
.seh_handler __CxxFrameHandler3, @unwind, @except
-.LBB0_9:
+.LBB0_7:
movq %rdx, 16(%rsp)
pushq %rbp
.seh_pushreg %rbp
- subq $32, %rsp
- .seh_stackalloc 32
- leaq 80(%rdx), %rbp
+ pushq %rsi
+ .seh_pushreg %rsi
+ subq $40, %rsp
+ .seh_stackalloc 40
+ leaq 32(%rdx), %rbp
.seh_endprologue
- movq -8(%rbp), %rcx
- callq _ZN3std9panicking3try7cleanup17h09cddad23dc8025dE
- movq %rax, -40(%rbp)
- xorl %eax, %eax
- movq %rax, -32(%rbp)
- leaq .LBB0_5(%rip), %rax
- addq $32, %rsp
- popq %rbp
- retq
- .seh_handlerdata
- .long ($cppxdata$notable_function)@IMGREL
- .section .text,"xr",one_only,notable_function
- .seh_endproc
- .def "?catch$10@?0?notable_function@4HA";
- .scl 3;
- .type 32;
- .endef
- .p2align 4, 0x90
-"?catch$10@?0?notable_function@4HA":
-.seh_proc "?catch$10@?0?notable_function@4HA"
- .seh_handler __CxxFrameHandler3, @unwind, @except
-.LBB0_10:
- movq %rdx, 16(%rsp)
- pushq %rbp
- .seh_pushreg %rbp
- subq $32, %rsp
- .seh_stackalloc 32
- leaq 80(%rdx), %rbp
- .seh_endprologue
- xorl %eax, %eax
- movq %rax, -32(%rbp)
- xorl %ecx, %ecx
- callq _ZN3std9panicking3try7cleanup17h09cddad23dc8025dE
- movq %rax, -40(%rbp)
- leaq .LBB0_5(%rip), %rax
- addq $32, %rsp
- popq %rbp
- retq
+ callq _ZN4core9panicking15panic_no_unwind17h49e55cbf27726099E
+ ud2
.Lfunc_end0:
.seh_handlerdata
.long ($cppxdata$notable_function)@IMGREL
@@ -129,9 +87,9 @@
.long ($stateUnwindMap$notable_function)@IMGREL
.long 1
.long ($tryMap$notable_function)@IMGREL
- .long 5
+ .long 4
.long ($ip2state$notable_function)@IMGREL
- .long 64
+ .long 32
.long 0
.long 1
$stateUnwindMap$notable_function:
@@ -143,19 +101,14 @@
.long 0
.long 0
.long 1
- .long 2
+ .long 1
.long ($handlerMap$0$notable_function)@IMGREL
$handlerMap$0$notable_function:
- .long 8
- .long __rust_panic_type_info@IMGREL
- .long 72
- .long "?catch$9@?0?notable_function@4HA"@IMGREL
- .long 56
.long 64
.long 0
.long 0
- .long "?catch$10@?0?notable_function@4HA"@IMGREL
- .long 56
+ .long "?catch$7@?0?notable_function@4HA"@IMGREL
+ .long 72
$ip2state$notable_function:
.long .Lfunc_begin0@IMGREL
.long -1
@@ -163,17 +116,6 @@
.long 0
.long .Ltmp1@IMGREL+1
.long -1
- .long "?catch$9@?0?notable_function@4HA"@IMGREL
- .long 1
- .long "?catch$10@?0?notable_function@4HA"@IMGREL
+ .long "?catch$7@?0?notable_function@4HA"@IMGREL
.long 1
.section .text,"xr",one_only,notable_function
-
- .section .data,"dw",discard,__rust_panic_type_info
- .globl __rust_panic_type_info
- .p2align 4
-__rust_panic_type_info:
- .quad "??_7type_info@@6B@"
- .quad 0
- .asciz "rust_panic"
- .zero 5 diff diff nightly..stage1 (honestly kinda useless)--- nightly.diff 2022-07-15 13:40:58.546378000 -0400
+++ stage1.diff 2022-07-15 13:42:22.356174500 -0400
@@ -1,34 +1,96 @@
---- unwind.s 2022-07-15 13:40:23.427159000 -0400
-+++ abort.s 2022-07-15 13:40:17.596473500 -0400
-@@ -24,20 +24,14 @@
- leaq 48(%rsp), %rbp
- .seh_setframe %rbp, 48
+--- unwind.s 2022-07-15 13:41:59.629266400 -0400
++++ abort.s 2022-07-15 13:42:09.911164300 -0400
+@@ -19,103 +19,61 @@
+ .seh_handler __CxxFrameHandler3, @unwind, @except
+ pushq %rbp
+ .seh_pushreg %rbp
+- subq $80, %rsp
+- .seh_stackalloc 80
+- leaq 80(%rsp), %rbp
+- .seh_setframe %rbp, 80
++ pushq %rsi
++ .seh_pushreg %rsi
++ subq $40, %rsp
++ .seh_stackalloc 40
++ leaq 32(%rsp), %rbp
++ .seh_setframe %rbp, 32
.seh_endprologue
- movq $-2, -16(%rbp)
-+ movq $-2, -8(%rbp)
++ movq $-2, (%rbp)
+ movq __imp__ZN3std9panicking11panic_count18GLOBAL_PANIC_COUNT17h832a50073c85f225E(%rip), %rax
+ movq (%rax), %rax
+ shlq $1, %rax
+ testq %rax, %rax
+ jne .LBB0_2
+- movl $0, -20(%rbp)
++ xorl %esi, %esi
+ .LBB0_3:
.Ltmp0:
callq happy
.Ltmp1:
- movl $42, %eax
+- movb $1, %al
+- movq %rax, -32(%rbp)
+- movl $42, %eax
+- movq %rax, -40(%rbp)
-.LBB0_5:
- addq $48, %rsp
- popq %rbp
- retq
--.LBB0_4:
--$ehgcr_0_4:
+-$ehgcr_0_5:
+- cmpb $0, -20(%rbp)
++ testb %sil, %sil
+ je .LBB0_6
+ callq _ZN3std9panicking11panic_count8increase17h424b40195d3e6f0fE
+ .LBB0_6:
+- cmpb $0, -32(%rbp)
+- movq -40(%rbp), %rax
+- jne .LBB0_8
- callq unfortunate
- movl $13, %eax
-- jmp .LBB0_5
+-.LBB0_8:
+- addq $80, %rsp
++ movl $42, %eax
++ addq $40, %rsp
++ popq %rsi
+ popq %rbp
+ retq
+ .LBB0_2:
+ callq _ZN3std9panicking11panic_count22try_decrease_slow_path17hf1721c3fb8e2c7e3E
+- movl %eax, -20(%rbp)
++ movl %eax, %esi
+ jmp .LBB0_3
.seh_handlerdata
.long ($cppxdata$notable_function)@IMGREL
.section .text,"xr",one_only,notable_function
-@@ -58,38 +52,8 @@
- .seh_stackalloc 32
- leaq 48(%rdx), %rbp
+ .seh_endproc
+- .def "?catch$9@?0?notable_function@4HA";
++ .def "?catch$7@?0?notable_function@4HA";
+ .scl 3;
+ .type 32;
+ .endef
+ .p2align 4, 0x90
+-"?catch$9@?0?notable_function@4HA":
+-.seh_proc "?catch$9@?0?notable_function@4HA"
++"?catch$7@?0?notable_function@4HA":
++.seh_proc "?catch$7@?0?notable_function@4HA"
+ .seh_handler __CxxFrameHandler3, @unwind, @except
+-.LBB0_9:
++.LBB0_7:
+ movq %rdx, 16(%rsp)
+ pushq %rbp
+ .seh_pushreg %rbp
+- subq $32, %rsp
+- .seh_stackalloc 32
+- leaq 80(%rdx), %rbp
++ pushq %rsi
++ .seh_pushreg %rsi
++ subq $40, %rsp
++ .seh_stackalloc 40
++ leaq 32(%rdx), %rbp
.seh_endprologue
- movq -8(%rbp), %rcx
-- callq _ZN3std9panicking3try7cleanup17h9c87e793fb4cdaabE
-- leaq .LBB0_4(%rip), %rax
+- callq _ZN3std9panicking3try7cleanup17h09cddad23dc8025dE
+- movq %rax, -40(%rbp)
+- xorl %eax, %eax
+- movq %rax, -32(%rbp)
+- leaq .LBB0_5(%rip), %rax
- addq $32, %rsp
- popq %rbp
- retq
@@ -36,46 +98,49 @@
- .long ($cppxdata$notable_function)@IMGREL
- .section .text,"xr",one_only,notable_function
- .seh_endproc
-- .def "?catch$3@?0?notable_function@4HA";
+- .def "?catch$10@?0?notable_function@4HA";
- .scl 3;
- .type 32;
- .endef
- .p2align 4, 0x90
--"?catch$3@?0?notable_function@4HA":
--.seh_proc "?catch$3@?0?notable_function@4HA"
+-"?catch$10@?0?notable_function@4HA":
+-.seh_proc "?catch$10@?0?notable_function@4HA"
- .seh_handler __CxxFrameHandler3, @unwind, @except
--.LBB0_3:
+-.LBB0_10:
- movq %rdx, 16(%rsp)
- pushq %rbp
- .seh_pushreg %rbp
- subq $32, %rsp
- .seh_stackalloc 32
-- leaq 48(%rdx), %rbp
+- leaq 80(%rdx), %rbp
- .seh_endprologue
+- xorl %eax, %eax
+- movq %rax, -32(%rbp)
- xorl %ecx, %ecx
-- callq _ZN3std9panicking3try7cleanup17h9c87e793fb4cdaabE
-- leaq .LBB0_4(%rip), %rax
+- callq _ZN3std9panicking3try7cleanup17h09cddad23dc8025dE
+- movq %rax, -40(%rbp)
+- leaq .LBB0_5(%rip), %rax
- addq $32, %rsp
- popq %rbp
- retq
-+ callq _ZN4core9panicking15panic_no_unwind17hedc8ed309bafae40E
++ callq _ZN4core9panicking15panic_no_unwind17h49e55cbf27726099E
+ ud2
.Lfunc_end0:
.seh_handlerdata
.long ($cppxdata$notable_function)@IMGREL
-@@ -103,9 +67,9 @@
+@@ -129,9 +87,9 @@
.long ($stateUnwindMap$notable_function)@IMGREL
.long 1
.long ($tryMap$notable_function)@IMGREL
- .long 5
+ .long 4
.long ($ip2state$notable_function)@IMGREL
-- .long 32
-+ .long 40
+- .long 64
++ .long 32
.long 0
.long 1
$stateUnwindMap$notable_function:
-@@ -117,18 +81,13 @@
+@@ -143,19 +101,14 @@
.long 0
.long 0
.long 1
@@ -85,23 +150,28 @@
$handlerMap$0$notable_function:
- .long 8
- .long __rust_panic_type_info@IMGREL
-- .long 40
-- .long "?catch$2@?0?notable_function@4HA"@IMGREL
+- .long 72
+- .long "?catch$9@?0?notable_function@4HA"@IMGREL
- .long 56
.long 64
.long 0
.long 0
-- .long "?catch$3@?0?notable_function@4HA"@IMGREL
-+ .long "?catch$2@?0?notable_function@4HA"@IMGREL
- .long 56
+- .long "?catch$10@?0?notable_function@4HA"@IMGREL
+- .long 56
++ .long "?catch$7@?0?notable_function@4HA"@IMGREL
++ .long 72
$ip2state$notable_function:
.long .Lfunc_begin0@IMGREL
-@@ -139,15 +98,4 @@
.long -1
- .long "?catch$2@?0?notable_function@4HA"@IMGREL
- .long 1
-- .long "?catch$3@?0?notable_function@4HA"@IMGREL
+@@ -163,17 +116,6 @@
+ .long 0
+ .long .Ltmp1@IMGREL+1
+ .long -1
+- .long "?catch$9@?0?notable_function@4HA"@IMGREL
- .long 1
+- .long "?catch$10@?0?notable_function@4HA"@IMGREL
++ .long "?catch$7@?0?notable_function@4HA"@IMGREL
+ .long 1
.section .text,"xr",one_only,notable_function
-
- .section .data,"dw",discard,__rust_panic_type_info I tried to install a stage1 cross-compiler to check |
Closing this for now. |
This is deceptively simple... experiment primarily for a perf run to estimate the cost of providing this behavior.
Currently, any panic during an unwind will immediately abort the process. That means that the otherwise inconspicuous code
will run normally in normal code, but if this happens to be called from a drop implementation during unwinding, abort the process.
This behavior is relied upon in the ecosystem for soundness by the way of stack guards which trigger an abort via panic-in-unwind when dropped. This PR does not change the behavior of such drop bombs.
What this PR does is deceptively simple: it makes it so that
catch_unwind
clears the "is panicking" state when running the provided closure. This means that even if we were unwinding before callingcatch_unwind
, the code inside sees a normal non-panicking environment and can run normally, including to panic and unwind to the registeredcatch_unwind
handler.A second panic which is covered by the same
catch_unwind
continues to immediately abort.