-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
__CxxFrameHandler3
still referenced even though panic=abort
#101134
Comments
@BatmanAoD I think this suggests that panic's unwind structs are being included even when panic=abort? Whereas before it wasn't? |
I don't think this is true, the |
Hm, then why did it only start needing it with 1.60? |
probably a bisection could help understanding when this started @rustbot label e-needs-bisection t-compiler |
Probably because there was a fix in 1.60. There are currently some effort that are being done to fix the unsoundness around the |
Regression was in nightly-2022-01-19. I'm still attempting to narrow it down:
|
Most likely candidate: #92877 |
I can understand wanting to add exception handlers in some cases. But I don't understand using |
Yes, that must be the one. It even say in the PR description:
This is unfortunately outside my knowledge, sorry. |
Ok, it does surprise me. For platform details see here. This handler can choose not to handle the exception (which may mean the program continues to unwind) or it may explicitly continue unwinding. I would (perhaps naively?) expect Rust to always abort instead of maybe abort or maybe unwind. And it just seems like an unnecessary dependency. I could implement |
@Amanieu Does #92845 change this? I'm not really able to answer any of @ChrisDenton's questions above, but it seems like we should now be linking a personality function in std rather than |
This is due to an LLVM limitation. LLVM selects the unwinding metadata format (DWARF, SJLJ, SEH, etc) based on the name of the personality function. So we have to use
No, that PR only affects platforms using DWARF unwinding since we provide our own personality function there. For SEH we link to @ChrisDenton Does |
Ah, I tried:
And |
@ChrisDenton Does that solve your issue, or do you still consider this a bug? |
Yes, I have a workflow that works and I don't think this issue is tracking anything useful. So I'll close this now. |
Hi, I encountered this issue today. While I understand the cause and the available workaround, it is still a nightly-only solution (you can't have rebuild core flag on stable yet). Should we reopen this issue till a better solution is created? I also want to note that
|
@wwylele Sorry, I'm a bit out of my depth here, but:
|
I modified the example code from this issue to have a simple I'm not sure what would be needed to fix this issue for apps using |
@BatmanAoD I am using rust project:
#![no_std]
#[panic_handler]
fn panic(_info: &core::panic::PanicInfo) -> ! {
loop {}
}
#[export_name = "foo"]
pub extern "C" fn foo(a: i32, b: i32) -> i32 {
a + b // has overflow check in debug build
} Then in Visual Studio 2019, with WDK installed, create a default kernel mode driver (KMDF) project. Switch to x64 (same as the rust library). First build the solution to make sure the vanilla default code builds. Then add the following code in int foo(int, int);
...
DriverEntry(
_In_ PDRIVER_OBJECT DriverObject,
_In_ PUNICODE_STRING RegistryPath
)
{
...
foo(1,1);
...
} And also add library output from rust to the dependency in the visual studio project (Project/Properties/Linker/General/Additional Library Diretories, then ...Linker/Input/Additional Dependencies), then build. The error is:
(bonus: the floating point dependency |
It won't surprise me that the default Windows driver project doesn't link to the normal msvcrt.lib |
I believe core is pre-built with panic-unwind (thus using that exception handler) which is why they need to be rebuilt with Maybe the stable solution is to have a separate target? |
Based on https://learn.microsoft.com/en-us/windows-hardware/drivers/kernel/handling-exceptions I believe for Windows kernel code
Definitely. |
|
And that is not the correct behavior. In Rust it is UB to unwind past stack frames without running destructors. It should either abort when crossing the ABI boundary (which happens for C++ exceptions in userspace, but I don't know if this happens for SEH exceptions) or it should run destructors anyway. Aborting is not an option inside a kernel driver, (especially as I think it is possible to cause a kernel SEH exception from userspace) so we have to run destructors on SEJ exceptions anyway. This is effectively the same as wrapping every function call with a |
@bjorn3 I think that depends on whether the SEH exception is forced, i.e. a But if we're talking about a context where |
In windows kernel drivers C++ exceptions aren't allowed and as such |
Huh...that's definitely not what I would have expected! So unwinding (with user-defined cleanup operations) is permissible, but it's incompatible with C++ exceptions. That does sound like it warrants being defined as a separate platform. |
Code
I tried this code:
With this section in
Cargo.toml
:And also disabled msvcrt.lib. Unfortunately rust does not have a good way to do this so I used a build script to add a libs directory that contains an empty msvcrt.lib:
For a full example see: https://github.com/ChrisDenton/panic-abort
I expected to see this happen: When running
cargo build --release
, the symbol__CxxFrameHandler3
is not referenced at all. Because withpanic=abort
there should be no panic code.Instead, this happened:
__CxxFrameHandler3
is referenced. This causes the following linker error because I disabled msvcrt.lib:Version it worked on
It most recently worked on: 1.59
rustc +1.59 --version --verbose
Version with regression
rustc +1.60 --version --verbose
:@rustbot modify labels: +regression-from-stable-to-stable -regression-untriaged
The text was updated successfully, but these errors were encountered: