Skip to content

Lower x86-interrupt byval first argument as pointer#893

Merged
antoyo merged 1 commit into
rust-lang:masterfrom
Dnreikronos:x86-interrupt-non-pointer-first-arg
Jul 22, 2026
Merged

Lower x86-interrupt byval first argument as pointer#893
antoyo merged 1 commit into
rust-lang:masterfrom
Dnreikronos:x86-interrupt-non-pointer-first-arg

Conversation

@Dnreikronos

@Dnreikronos Dnreikronos commented May 30, 2026

Copy link
Copy Markdown
Contributor

Fixes #833

An extern "x86-interrupt" function can have a by-value first Rust argument, such as i64 or a by-value struct. rustc's LLVM backend lowers that first byval stack argument to a pointer-shaped backend parameter for x86_intrcc.

GCC's interrupt attribute expects the same pointer-shaped first parameter. Without that lowering, libgccjit reports interrupt service routine should have a pointer as the first argument and does not write an object file, which then shows up as a confusing follow-up archive/object error.

Mirror rustc's lowering in the GCC backend for the first x86-interrupt byval argument, while keeping the interrupt attribute. This avoids the libgccjit abort without rejecting a Rust signature that rustc accepts.

The regression test covers scalar and by-value struct first arguments.

@Dnreikronos

Copy link
Copy Markdown
Contributor Author

@antoyo, hi mate!
can you help me with this, please?

@antoyo

antoyo commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Sorry for the delay.
I'll try to review this in the following days.

@Dnreikronos

Copy link
Copy Markdown
Contributor Author

Sorry for the delay. I'll try to review this in the following days.

all good!
ty!

@antoyo

antoyo commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

LLVM only warns on the same code.

What is the warning produced by LLVM? (I don't see it.)

One question I have is: is the code in the issue supposed to work correctly, or does Rust also always expect a pointer argument?

@Dnreikronos

Copy link
Copy Markdown
Contributor Author

yeah, i checked this again and i think the pr description is a bit off here.

i don't see an llvm warning either. with rustc 1.96.0 / llvm 22.1.2, the testcase compiles cleanly for me. dumping the llvm ir shows rustc lowers the first arg to a pointer/byval param:

define x86_intrcc void ... (ptr byval([8 x i8]) align 8 %_a)

so imo rust is not expecting the rust-level arg itself to be a pointer. it accepts something like i64 or a by-value struct, then lowers it into the pointer shape the backend wants.

tbh i think the better fix is to mirror that lowering in the gcc backend, instead of rejecting the source signature or dropping the interrupt attr. i'll update the pr in that direction.

@Dnreikronos Dnreikronos changed the title abi: Emit a clean error for non-pointer x86-interrupt first argument Lower x86-interrupt byval first argument as pointer Jul 5, 2026
@rustbot

This comment has been minimized.

@Dnreikronos
Dnreikronos force-pushed the x86-interrupt-non-pointer-first-arg branch from 516f055 to 39f9537 Compare July 22, 2026 00:33
@rustbot

rustbot commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different master 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.

Comment thread src/abi.rs
Comment thread src/abi.rs
Comment thread src/attributes.rs Outdated
@Dnreikronos
Dnreikronos force-pushed the x86-interrupt-non-pointer-first-arg branch from ad98c09 to b3d543e Compare July 22, 2026 15:47
@Dnreikronos
Dnreikronos requested review from antoyo and bjorn3 July 22, 2026 16:03
@antoyo

antoyo commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

@Dnreikronos: Oh it seems my last comment was not sent correctly.
Here it is:

Please add this as a comment (why we add general-regs-only) so that the reasoning stays in the code.
After that, I think we'll be good to merge this.

@Dnreikronos
Dnreikronos force-pushed the x86-interrupt-non-pointer-first-arg branch from b3d543e to c01fb17 Compare July 22, 2026 16:09
@Dnreikronos
Dnreikronos force-pushed the x86-interrupt-non-pointer-first-arg branch from c01fb17 to 622323a Compare July 22, 2026 16:38
@Dnreikronos
Dnreikronos requested a review from antoyo July 22, 2026 16:42
@antoyo

antoyo commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

@Dnreikronos Did you make any change since my last approval? (I'm asking because you requested another review.)
Is this PR ready to be merged if the CI passes?

@Dnreikronos

Copy link
Copy Markdown
Contributor Author

@Dnreikronos Did you make any change since my last approval? (I'm asking because you requested another review.) Is this PR ready to be merged if the CI passes?

I just squashed all the commits to clean the history and be easier to understand everything. And yes, it's ready the be merged when the CI passses

@antoyo
antoyo enabled auto-merge July 22, 2026 17:13
@antoyo
antoyo merged commit e052a81 into rust-lang:master Jul 22, 2026
40 checks passed
@antoyo

antoyo commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

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.

interrupt service routine should have a pointer as the first argument

4 participants