-
Notifications
You must be signed in to change notification settings - Fork 164
minimal_rt: split reloc code to new crate without debug asserts #2719
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
base: main
Are you sure you want to change the base?
Conversation
…ertions In Rust 1.93, if debug assertions are enabled in the relocation code as it's written today, then LLVM will generate code that contains relocations. This, of course, will fail to run before relocations are applied. Fix this by separating the relocation code to a new crate and disabling debug assertions just for that crate via profile overrides in Cargo.toml. Ultimately, perhaps we should use global asm to perform relocations so that we can be sure there are no relocations at all. But for now, just work around this with compiler settings.
|
This PR modifies files containing For more on why we check whole files, instead of just diffs, check out the Rustonomicon |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR isolates the relocation logic used by minimal_rt into a dedicated minimal_rt_reloc crate so that Rust 1.93 debug-assertion behavior cannot introduce relocations into code that must run before relocation. Debug assertions are disabled and optimization is enabled specifically for this new crate via profile overrides.
Changes:
- Added a new
minimal_rt_reloccrate, documented it as the relocation implementation, and wired it into the workspace. - Updated
minimal_rtto depend on and re-exportminimal_rt_relocas itsrelocmodule. - Adjusted workspace profiles to optimize
minimal_rt_relocwithdebug-assertions = falsein dev and extended thecfg(target_arch)house-rule exemption to include the new crate.
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
xtask/src/tasks/fmt/house_rules/cfg_target_arch.rs |
Extends the cfg(target_arch) lint exemption list to cover openhcl/minimal_rt_reloc, allowing arch-specific code in the new crate. |
openhcl/minimal_rt_reloc/src/lib.rs |
Hosts the relocation logic in a separate crate and updates docs to explain the split and the build-profile override scope. |
openhcl/minimal_rt_reloc/Cargo.toml |
Defines the new minimal_rt_reloc package and hooks it into workspace edition/rust-version/lints. |
openhcl/minimal_rt/src/lib.rs |
Removes the in-crate reloc module and instead re-exports the minimal_rt_reloc crate as reloc. |
openhcl/minimal_rt/Cargo.toml |
Adds minimal_rt_reloc as a dependency of minimal_rt. |
Cargo.toml |
Registers minimal_rt_reloc as a workspace member and adds a [profile.dev.package.minimal_rt_reloc] override to optimize and disable debug assertions for that crate. |
Cargo.lock |
Records the new minimal_rt_reloc package and its inclusion as a dependency of minimal_rt. |
Comments suppressed due to low confidence (2)
openhcl/minimal_rt_reloc/src/lib.rs:12
- Now that
minimal_rt_relocis a standalone crate and is being added as a workspace member/dependency, thepanic_no_relocs!macro below still callscrate::arch::fault(), but this crate has noarchmodule and no dependency that provides one. As soon as this crate is built, this will be a compile-time error (use of undeclared crate or module 'arch'), so the relocation error path needs to be wired to a symbol that actually exists in this crate (for example, a minimal per-arch shim within this crate or a callback provided byminimal_rt) instead of referring tominimal_rt’sarchmodule viacrate::arch.
openhcl/minimal_rt_reloc/src/lib.rs:8 - This crate is intended to run "in an environment without a runtime" and now serves as the relocation logic that is pulled into
minimal_rt, but it does not declare#![no_std]. That means it will linkstdif available, which is inconsistent withminimal_rt’s#![no_std]model and could introduce unwanted dependencies or linking failures in kernel-mode / early-boot builds; consider marking this crateno_stdas well (and keeping its code restricted tocore).
In Rust 1.93, if debug assertions are enabled in the relocation code as it's written today, then LLVM will generate code that contains relocations. This, of course, will fail to run before relocations are applied.
Fix this by separating the relocation code to a new crate and disabling debug assertions just for that crate via profile overrides in Cargo.toml.
Ultimately, perhaps we should use global asm to perform relocations so that we can be sure there are no relocations at all. But for now, just work around this with compiler settings.