Skip to content

Conversation

@jstarks
Copy link
Member

@jstarks jstarks commented Jan 30, 2026

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.

…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.
@jstarks jstarks requested review from a team as code owners January 30, 2026 21:15
Copilot AI review requested due to automatic review settings January 30, 2026 21:15
@github-actions github-actions bot added the unsafe Related to unsafe code label Jan 30, 2026
@github-actions
Copy link

⚠️ Unsafe Code Detected

This PR modifies files containing unsafe Rust code. Extra scrutiny is required during review.

For more on why we check whole files, instead of just diffs, check out the Rustonomicon

Copy link
Contributor

Copilot AI left a 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_reloc crate, documented it as the relocation implementation, and wired it into the workspace.
  • Updated minimal_rt to depend on and re-export minimal_rt_reloc as its reloc module.
  • Adjusted workspace profiles to optimize minimal_rt_reloc with debug-assertions = false in dev and extended the cfg(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_reloc is a standalone crate and is being added as a workspace member/dependency, the panic_no_relocs! macro below still calls crate::arch::fault(), but this crate has no arch module 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 by minimal_rt) instead of referring to minimal_rt’s arch module via crate::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 link std if available, which is inconsistent with minimal_rt’s #![no_std] model and could introduce unwanted dependencies or linking failures in kernel-mode / early-boot builds; consider marking this crate no_std as well (and keeping its code restricted to core).

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

Labels

unsafe Related to unsafe code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants