Skip to content

Use EII for #[panic_handler] - #159016

Draft
bjorn3 wants to merge 7 commits into
rust-lang:mainfrom
bjorn3:eii_panic_handler
Draft

bjorn3 wants to merge 7 commits into
rust-lang:mainfrom
bjorn3:eii_panic_handler

Conversation

@bjorn3

@bjorn3 bjorn3 commented Jul 9, 2026 •

Copy link
Copy Markdown
Member

While we can't yet use EIIs for things like the global allocator due to missing platform support, we can safely use it for #[panic_handler] as that doesn't require any object file format features. Just matching symbol names.

This gets rid of one of the two remaining weak lang items.

TODO

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) A-test-infra-minicore Area: `minicore` test auxiliary and `//@ add-minicore` S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jul 9, 2026
@bjorn3

bjorn3 commented Jul 9, 2026

Copy link
Copy Markdown
Member Author

cc @jdonszelmann

@rust-log-analyzer

This comment has been minimized.

@rust-bors

This comment has been minimized.

@bjorn3
bjorn3 force-pushed the eii_panic_handler branch from ecd1f4c to 2f001d2 Compare July 24, 2026 09:48

/// Attribute macro applied to a function to register it as a panic handler.
///
/// See also [`core::panic::PanicInfo`](crate::panic::PanicInfo).

@bjorn3 bjorn3 Jul 24, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are probably better pages to link to.

View changes since the review

@rust-log-analyzer

This comment has been minimized.

@rust-bors

This comment has been minimized.

@bjorn3
bjorn3 force-pushed the eii_panic_handler branch from 6f7844f to 43f6678 Compare August 4, 2026 13:31
@rust-log-analyzer

This comment has been minimized.

@rust-bors

This comment has been minimized.

The only way it was possible to skip needing to declare #[panic_handler]
is using #![no_core], which is unstable anyway. Always requiring
\#[panic_handler] makes things more consistent and avoids having to
special case several MIR optimizations for the absence of #[panic_handler].
@bjorn3
bjorn3 force-pushed the eii_panic_handler branch from 43f6678 to efeefa8 Compare November 6, 2026 16:07
@rustbot rustbot added the A-panic Area: Panicking machinery label Nov 6, 2026
@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

The job test-aarch64-gnu-llvm-22-2 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
[AOT] mini_core_hello_world
error: requires `panic_null_reference_constructed` lang_item
##[error]   --> example/mini_core_hello_world.rs:362:24
    |
362 |     let _a = (unsafe { &*fp })[0];
    |                        ^^^^

error: aborting due to 1 previous error

"/checkout/obj/build/aarch64-unknown-linux-gnu/stage2-codegen/cg_clif/dist/rustc-clif" "-Zannotate-moves" "-Zrandomize-layout" "-Zunstable-options" "--check-cfg=cfg(bootstrap)" "-Zmacro-backtrace" "-Csplit-debuginfo=off" "-Clink-arg=-L/usr/lib/llvm-22/lib" "-Cllvm-args=-import-instr-limit=10" "-Clink-args=-Wl,-z,origin" "-Clink-args=-Wl,-rpath,$ORIGIN/../lib" "-Alinker-messages" "-L" "crate=/checkout/obj/build/aarch64-unknown-linux-gnu/stage2-codegen/cg_clif/build/example" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2-codegen/cg_clif/build/example" "-Cdebuginfo=2" "--target" "aarch64-unknown-linux-gnu" "-Cpanic=abort" "--check-cfg=cfg(jit)" "--check-cfg=cfg(target_has_reliable_f128)" "--edition=2024" "-Zforce-unstable-if-unmarked" "example/mini_core_hello_world.rs" exited with status ExitStatus(unix_wait_status(256, "exit status: 1"))
Command `/checkout/obj/build/aarch64-unknown-linux-gnu/stage0/bin/cargo run --target aarch64-unknown-linux-gnu -Zbinary-dep-depinfo -j 4 -Zroot-dir=/checkout -Zembed-metadata=no --locked --color=always --profile=release --manifest-path /checkout/compiler/rustc_codegen_cranelift/build_system/Cargo.toml -- test --download-dir /checkout/obj/build/cg_clif_download --out-dir /checkout/obj/build/aarch64-unknown-linux-gnu/stage2-codegen/cg_clif --no-unstable-features --use-backend cranelift --sysroot llvm --skip-test testsuite.extended_sysroot [workdir=/checkout/compiler/rustc_codegen_cranelift]` failed with exit code 1
Created at: src/bootstrap/src/core/build_steps/test.rs:4612:25
Executed at: src/bootstrap/src/core/build_steps/test.rs:4656:26

Command has failed. Rerun with -v to see more details.
Bootstrap failed while executing `--stage 2 test --skip tidy --skip tests --skip library --skip tidyselftest`
Currently active steps:
test::CodegenCranelift { compilers: RustcPrivateCompilers { build_compiler: Compiler { stage: 1, host: aarch64-unknown-linux-gnu, forced_compiler: false }, target_compiler: Compiler { stage: 2, host: aarch64-unknown-linux-gnu, forced_compiler: false } }, target: aarch64-unknown-linux-gnu } at src/bootstrap/src/core/build_steps/test.rs:4598
Build completed unsuccessfully in 0:24:13
  local time: Fri Nov  6 16:35:27 UTC 2026

@rust-bors

rust-bors Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #165579) made this pull request unmergeable. Please resolve the merge conflicts by rebasing.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) A-panic Area: Panicking machinery A-test-infra-minicore Area: `minicore` test auxiliary and `//@ add-minicore` S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants