Skip to content

asm! support for the Xtensa architecture#147302

Open
MabezDev wants to merge 1 commit intorust-lang:mainfrom
esp-rs:xtensa-asm
Open

asm! support for the Xtensa architecture#147302
MabezDev wants to merge 1 commit intorust-lang:mainfrom
esp-rs:xtensa-asm

Conversation

@MabezDev
Copy link
Contributor

@MabezDev MabezDev commented Oct 3, 2025

This implements the asm! support for Xtensa. We've been using this code for a few years in our fork and it's been working well. I finally found some time to clean it up a bit and start the upstreaming process. This should be one of the final PRs for Xtensa support on the Rust side (minus bug fixes of course). After this, we're mostly just waiting on the LLVM upstreaming which is going well. This PR doesn't cover all possible asm options for Xtensa, but the base ISA plus a few extras that are used in Espressif chips.

r? Amanieu

@rustbot
Copy link
Collaborator

rustbot commented Oct 3, 2025

Some changes occurred in compiler/rustc_codegen_gcc

cc @antoyo, @GuillaumeGomez

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 3, 2025
@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Oct 3, 2025
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

Copy link
Member

@Amanieu Amanieu left a comment

Choose a reason for hiding this comment

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

This is also missing an update to the unstable book entry for asm_experimental_arch.

View changes since this review

@bors
Copy link
Collaborator

bors commented Nov 5, 2025

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

@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@MabezDev MabezDev force-pushed the xtensa-asm branch 2 times, most recently from ad6e15a to 1e1ed2e Compare November 14, 2025 13:12
@MabezDev
Copy link
Contributor Author

I've made most of the updates here (sorry for the delay!).

It turns out we'll need a patch that landed just after rust branched LLVM: https://github.com/rust-lang/llvm-project/tree/rustc/21.1-2025-08-01/llvm/lib/Target/Xtensa , otherwise the asm tests fail :(.

The good news is that we've since landed FP support in LLVM upstream too, so maybe the next time rust branches LLVM 21 (I guess 21.2?) we can rerun CI on this PR and it will be green.

@rust-log-analyzer

This comment has been minimized.

Comment on lines +69 to +71
// The Xtensa arch doesn't require, nor use, a dedicated frame pointer register
// therefore if it is not force enabled, we can assume it won't be generated.
// If frame pointers are enabled, we cannot use the register as a general purpose one.
Copy link
Member

Choose a reason for hiding this comment

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

Unfortunately that's not exactly true. LLVM will force the use of a frame pointer if the stack frame has variable-sized objects. While this currently isn't possible in Rust, it is possible when doing cross-language LTO with C code. Therefore we should always reject the use of the frame pointer in asm.

a4: reg = ["a4"],
a5: reg = ["a5"],
a6: reg = ["a6"],
a7: reg = ["a7"],
Copy link
Member

Choose a reason for hiding this comment

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

Looking at the LLVM code, it seems use a7 instead of a15 as the frame pointer when the windowed ABI is used.

a13: reg = ["a13"],
a14: reg = ["a14"],
a15: reg = ["a15"] % is_frame_pointer,
sar: reg = ["sar"],
Copy link
Member

Choose a reason for hiding this comment

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

This shouldn't be part of the reg class since it doesn't usually make sense for asm to select this regiser for the reg constraint. It should probably be in its own clobber-only register class.

@reddevilmidzy reddevilmidzy added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 4, 2026
@rust-bors

This comment has been minimized.

@rustbot

This comment has been minimized.

Co-authored-by: Taiki Endo <te316e89@gmail.com>
Co-authored-by: Kerry Jones <kerry@iodrive.co.za>
@rustbot
Copy link
Collaborator

rustbot commented Mar 3, 2026

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@rust-log-analyzer
Copy link
Collaborator

The job pr-check-2 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
/dev/sda15      105M  6.2M   99M   6% /boot/efi
tmpfs           1.6G   12K  1.6G   1% /run/user/1001
================================================================================

Sufficient disk space available (95818484KB >= 52428800KB). Skipping cleanup.
##[group]Run echo "[CI_PR_NUMBER=$num]"
echo "[CI_PR_NUMBER=$num]"
shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}
---
##[group]Linting stage2 bootstrap (stage1 -> stage2, x86_64-unknown-linux-gnu)
error: failed to run `rustc` to learn about target-specific information

Caused by:
  process didn't exit successfully: `/checkout/obj/build/bootstrap/debug/rustc /checkout/obj/build/x86_64-unknown-linux-gnu/stage1/bin/clippy-driver /checkout/obj/build/bootstrap/debug/rustc - --crate-name ___ --print=file-names --sysroot /checkout/obj/build/x86_64-unknown-linux-gnu/stage1 --cfg=windows_raw_dylib -Csymbol-mangling-version=v0 -Zannotate-moves -Zunstable-options -Zforce-unstable-if-unmarked -Zmacro-backtrace -Csplit-debuginfo=off -Clink-args=-Wl,-z,origin '-Clink-args=-Wl,-rpath,$ORIGIN/../lib' -Zunstable-options --target x86_64-unknown-linux-gnu --crate-type bin --crate-type rlib --crate-type dylib --crate-type cdylib --crate-type staticlib --crate-type proc-macro --print=sysroot --print=split-debuginfo --print=crate-name --print=cfg -Wwarnings` (exit status: 101)
  --- stderr

  thread 'rustc' (32276) panicked at compiler/rustc_span/src/symbol.rs:2720:13:
  duplicate symbols in the rustc symbol list and the extra symbols added by the driver: ["println_macro", "thread_local_macro", "convert_identity", "print_macro"]
  stack backtrace:
     0: __rustc::rust_begin_unwind
     1: core::panicking::panic_fmt
     2: <rustc_span::symbol::Interner>::with_extra_symbols
     3: <rustc_span::SessionGlobals>::new
---
  warning: the ICE couldn't be written to `/checkout/rustc-ice-2026-03-03T16_38_04-32275.txt`: Read-only file system (os error 30)

  note: rustc 1.96.0-nightly (c69cde14c 2026-03-03) running on x86_64-unknown-linux-gnu

  note: compiler flags: -C symbol-mangling-version=v0 -Z annotate-moves -Z unstable-options -Z force-unstable-if-unmarked -Z macro-backtrace -C split-debuginfo=off -C link-args=-Wl,-z,origin -C link-args=-Wl,-rpath,$ORIGIN/../lib -Z unstable-options --crate-type bin --crate-type rlib --crate-type dylib --crate-type cdylib --crate-type staticlib --crate-type proc-macro -Z on-broken-pipe=kill -Z tls-model=initial-exec -Z allow-features=binary-dep-depinfo,proc_macro_span,proc_macro_span_shrink,proc_macro_diagnostic

  query stack during panic:
  end of query stack
  note: Clippy version: clippy 0.1.95 (c69cde14cd 2026-03-03)

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

Labels

A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants