-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Adding #[track_caller] on #[alloc_error_handler] seems to cause undefined behavior #83430
Comments
|
I don't understand how making the alloc error handler function unsafe helpers here. |
@rustbot label F-track_caller |
At the machine code level the function is expected to be defined with a specific signature. Defining the function with any other signature results in the caller invoking UB. Making it the attribute to imply its unsafe somehow (cf. #82499) would then properly indicate that there are invariants user must satisfy. It seems, however, that we're already checking the signature for correctness in some ways, so the check could be simply adjusted to also disallow any attribute that adjusts the function ABI such as |
after searching for how the alloc error handler is implemented, I see what you're getting at. (I assumed it directly inserted a call to that and didn't go through a bunch of however, I also think it would be worth trying to figure out a solution here, if possible, to make |
The original playground example seems to have stopped working. I think this is a reproducing version in CE, though: https://rust.godbolt.org/z/KWK3vzqqG. |
I'm concious that alloc_error_handler is the last unstable piece of the puzzle for some people getting off nightly. |
The signature of the handler is checked here: rust/compiler/rustc_typeck/src/check/check.rs Lines 372 to 411 in 53cb7b0
We should either find a way to make that code check the effective signature after modifications such as by |
Does this issue still exist? The example doesn't build any more as a bunch of the unstable features changed. I'm not sure what the best way is to even try a no_std binary. I think these days I do wonder, however, if things like |
It seems possible to combine
|
It seems likely that that's useless but harmless, according to my comment that you quoted. |
Playground link: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=c830f805f27e1be14b718b4d7510bf66
Example playground output:
(It seems to print garbage in release mode)
While trying to debug my OS kernel, I slapped
#[track_caller]
on my#[alloc_error_handler]
to try and figure out what was attempting to allocate memory that caused an OoM, however every time I hit that it would hang on an invalid memory access when it went to print the source location for the panic. I was able to reproduce the issue by... sternly talking the playground into producing a#![no_std]
binary and running it with a global allocator that always fails.The text was updated successfully, but these errors were encountered: