Skip to content

Remove asm toolchain#629

Open
wt wants to merge 6 commits intorust-embedded:masterfrom
wt:update_asm_toolchain
Open

Remove asm toolchain#629
wt wants to merge 6 commits intorust-embedded:masterfrom
wt:update_asm_toolchain

Conversation

@wt
Copy link
Contributor

@wt wt commented Mar 11, 2026

This is a draft for updating the asm toolchain. It's based on my #628, so it shouldn't be landed before that is.

@wt wt force-pushed the update_asm_toolchain branch 4 times, most recently from 0fe3a7c to 2abb7dd Compare March 12, 2026 21:06
@wt wt marked this pull request as ready for review March 12, 2026 21:06
@wt wt force-pushed the update_asm_toolchain branch 4 times, most recently from ec6c7ef to 667de8f Compare March 12, 2026 23:46
@wt wt marked this pull request as draft March 12, 2026 23:46
@wt wt force-pushed the update_asm_toolchain branch 8 times, most recently from b9cb8b5 to 74e91d2 Compare March 13, 2026 02:01
wt added 4 commits March 12, 2026 20:03
The `cm7-r0p1` feature only works with the plateform feature `armv7em`.
I added a compile error to help someone figure that out more redily if
they accidentally combine those features.
This will allow getting all the asm in shape for edition 2024.
@wt wt force-pushed the update_asm_toolchain branch 8 times, most recently from 9cad22a to 256dc0f Compare March 13, 2026 04:09
@wt wt force-pushed the update_asm_toolchain branch 15 times, most recently from 3a0b6e9 to 0d75936 Compare March 13, 2026 07:11
@wt wt changed the title Update asm toolchain Remove asm toolchain Mar 13, 2026
@wt wt marked this pull request as ready for review March 13, 2026 07:14
@wt
Copy link
Contributor Author

wt commented Mar 13, 2026

@thejpster Here's what you asked for.

wt added 2 commits March 13, 2026 00:16
Inline asm has been supported in stable rust for some time, so I removed
the separate asm build infra and added that code to the normal crate code.

I also crated a mock of the asm functions that were needed to run clippy
with a non-arm target (like x86_64).
@wt wt force-pushed the update_asm_toolchain branch from 0d75936 to e7d07d2 Compare March 13, 2026 07:17
strategy:
matrix:
# All generated code should be running on stable now
rust: [stable]
Copy link
Contributor

Choose a reason for hiding this comment

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

clippy should only be run on a fixed version, otherwise new releases that add new lints will break the build.


# steps:
# - uses: actions/checkout@v4
# - uses: dtolnay/rust-toolchain@1.85
Copy link
Contributor

Choose a reason for hiding this comment

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

Can the commented out text be removed?

@thejpster
Copy link
Contributor

Had a quick look on my phone - looks ok, just a few notes. I want to inspect the symbol table later when I get to a laptop.

@wt wt force-pushed the update_asm_toolchain branch from e7d07d2 to 29ef316 Compare March 13, 2026 07:26
@wt
Copy link
Contributor Author

wt commented Mar 13, 2026

I removed the change to the clippy runs since I added the mock so that it can be run without issue with clippy targeting x86.

@wt
Copy link
Contributor Author

wt commented Mar 13, 2026

If you want me to add that change to the tests back in for clippy I can. It was not really related to this change, so I didn't want to add more complexity.

Comment on lines +8 to +12
#[cfg_attr(any(armv6m, armv7m, armv7em, armv8m), path = "asm/inner.rs")]
#[cfg_attr(
all(not(armv6m), not(armv7m), not(armv7em), not(armv8m)),
path = "asm/inner_mock.rs"
)]

Choose a reason for hiding this comment

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

If I understand this correctly this changes the behavior from declaring an extern "C" unsafe fn for the asm functions (which is what call_asm! does if inline-asm is not enabled) to silently replacing all functions with nops if the target is not one of these.
Before this PR, it would be a compile time error if one of these functions is used on an unsupported target (I think).
Is this the intended new behavior?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm fine with that. If you are on an incompatible target, the point is to do enough to make clippy/unit tests/whatever happy, not do anything useful.

use core::sync::atomic::{Ordering, compiler_fence};

#[inline(always)]
pub unsafe fn __bkpt() {
Copy link
Contributor

@thejpster thejpster Mar 14, 2026

Choose a reason for hiding this comment

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

These need marking with #[unsafe(no_mangle)] to ensure they have the same symbol as the old asm functions.

Perhaps like:

#[unsafe(link_section = ".text.__function_name_goes_here")]
#[cfg(not(feature = "inline-asm", unsafe(no_mangle)))]
#[inline(always)]
pub unsafe fn __bkpt() {
   // inline asm goes here
}

That way, anyone who has written code like the following example will still find their code works when not using inline-asm:

extern "C" {
    fn __wfi();
}

unsafe {
   __wfi();
}

And anyone who is using inline-asm will find the following still works:

#[unsafe(no_mangle)]
pub extern "C" fn __wfi() {
   // do stuff
}

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, nah, we talked about this on Matrix and the __foo functions are not part of the public API - that's what the __ prefix means. So it's OK for the functions to be renamed.

Copy link
Contributor

Choose a reason for hiding this comment

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

In fact you could remove the __ prefixes from all these functions (and the mock functions). It adds no value and suggests a backwards compatibility that isn't actually present.

Copy link
Contributor

@diondokter diondokter left a comment

Choose a reason for hiding this comment

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

Great, love it!

#[inline]
pub fn disable() {
call_asm!(__cpsid());
unsafe { crate::asm::inner::__cpsid() };
Copy link
Contributor

Choose a reason for hiding this comment

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

We should probably call the public api when we can

#[inline]
pub unsafe fn enable() {
call_asm!(__cpsie());
unsafe { crate::asm::inner::__cpsie() };
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants