Skip to content

DEC Alpha support #742

@FractalFir

Description

@FractalFir
Contributor

This is an issue tracking the work on cross-compiling the Rust compiler to DEC Alpha.

Here is a list of things that need to be done to facilitate compiling any Rust code for DEC Alpha:

  • Add bare-bones support for DEC Alpha in the object crate. This crate is used by Rust to embed metadata in executables.
    Done, PR waiting for merge Add support for the alpha architecture in cc-rs
    Create an Alpha target file - I have created a target file myself, but I would prefer to double-check if that target is correct.
    Fix the libgccjit !gdisp!0 error. For now, I workaround this issue by removing this erronious label from all assembled files. We should figure out why this is even generated.
    Fix the instruction jsr $23,($27),__%E3%j5 getting emited in compiler_builtins. From asking about, it seems like % can't be present in symbol names: it is a format specifier(like in printf). So, it seems like it just does not get expanded properly? This function should normally expand to a call to a division subroutine(DEC alpha lacks hardware division support).

Here is a list of compiler-side changes we will need to make to compile any code to Alpha. Those changes should be merged upstream.

  • Add handling of the Alpha ABI to the Rust compiler, here.
    Add Alpha to the code inserting metadata into object files, here.
    Add Alpha as a recognized architecture to be used in #[cfg(target_arch = "alpha")]. This is not strictly needed for our work, but it is a required step before getting anything else upstream.

From some talks with the Rust folk, it seems like we can do those steps without the need for an official target. So, we will be able to just use our own target files, and add a tier 3 target once we have better support.

After those changes, we will be able to build code not depending on std.

  • (Optional) We should also add the config for the x86_64 -> Alpha cross compiler to our configs. This will just make cross-compilation slightly easier for other people(creating those config files is not hard, but having prepared configs would not hurt).

Next, I will list the changes needed to build on std, and code depending on the standard library for Alpha.

  • Add Alpha support to libc(a Rust library desciribing C types on the target). Doing so would require some work(tracking down the size / layout of all the libc types on Alpha). That work should get merged upstream. We may need to cordinate with the libc crate refactor project, to ensure our work does not collide.

    (Optional) Add Alpha unwinding support to std.

At this point, we should be able to build std, and at least a chunk of crates depending on it. There might be some issues with crates which build C dependencies, but we should be nontheless able to at least try cross-compling some Rust packages to Alpha. We would not be able to run the Rust compiler on Alpha yet, but we would be able to run a chunk of Rust code there.

I belive we should then cross-compile the Rust core, std and alloc test suite to Alpha, to check if everything is working correctly.

I don't yet know what would be required to get the Rust compiler to run on Alpha - will update this once I figure this out.

@glaubitz I think this issue might be of interest to you.

Activity

antoyo

antoyo commented on Jul 25, 2025

@antoyo
Contributor

Do you also need some fixes to use the correct linker?

glaubitz

glaubitz commented on Jul 25, 2025

@glaubitz

Thank you so much for doing this! This is dearly needed and I am really looking forward to be able to bootstrap rustc on the remaining four architectures in Debian!

Do you also need some fixes to use the correct linker?

We can use mold on m68k and sh4 but we have to use ld.bfd on alpha and hppa. (alpha used to be supported in mold but it got removed, for hppa there is a WIP branch).

CC @danglin44 @gyrovorbis @hdeller @maciej-w-rozycki @rth7680 @sozud

gyrovorbis

gyrovorbis commented on Jul 26, 2025

@gyrovorbis

Thank you SO MUCH for this from the Sega Dreamcast community as well...

Trust me, there are a WHOLE lot of us on "tier 3" devices who are still using the latest GCC 15.x and are drooling over potentially having Rust support... Truly, thank you.

glaubitz

glaubitz commented on Oct 9, 2025

@glaubitz

Hi, I was wondering: Has there been any progress on this?

antoyo

antoyo commented on Oct 16, 2025

@antoyo
Contributor

@glaubitz: As far as I know, there's not been any progress on this recently.
I do plan to start working on compiling rustc for m68k soon, though.
But for now, I'm sending patches to GCC in order to have them merged for the next release, hopefully.

thesamesam

thesamesam commented on Oct 16, 2025

@thesamesam

I've started filing bugs and playing with using rustc_codegen_gcc on x86_64. Too soon to think about others for me yet.

FractalFir

FractalFir commented on Oct 16, 2025

@FractalFir
ContributorAuthor

Hi, I was wondering: Has there been any progress on this?

I sadly was unable to get something merge-able before the end of GSoC, and I am now far too busy with other things to pour any more time into this.

antoyo

antoyo commented on Nov 3, 2025

@antoyo
Contributor

We had a discussion with @glaubitz on this mailing list.

I wanted to answer here to keep the discussion in one place.

I assume you're talking about this:

https://github.com/rust-lang/rust/tree/master/compiler/rustc_target/src/spec/targets

How do I actually determine the data layout for non-LLVM architectures?

Yes.
The rust compiler uses the same data layout strings as LLVM, so you can build own using the doc.

  • Add handling of the Alpha ABI to the Rust compiler

I assume you're talking about the calling convention?

https://github.com/rust-lang/rust/tree/master/compiler/rustc_target/src/callconv

Yes. Sorry I didn't added the links you can see in the original post of this issue in my email on the mailing list.

I have added both for several targets and I can certainly do that for Alpha, HPPA
and SuperH. I just need to understand how to wire architectures up when they don't
have an LLVM backend.

Are you referring to our discussion we had here?
If so, I believe we were at the point of opening an MCP to add a target only supported by GCC.
Would @glaubitz or @thesamesam be interested in creating such an MCP?
There was an example of an MCP adding a tier-3 target here.
Opening such an MCP should at least trigger the discussion we need to have regarding adding a GCC-only target.

  • Add Alpha to the code inserting metadata into object files

Which code part is this? Are you talking about the object crate?

Sorry, I didn't link this either in my email. The link is above in the original post.

  • Add Alpha as a recognized architecture to be used in
    #[cfg(target_arch = "alpha")].
  • Add Alpha support to libc.

I can do that as well.

Thanks a lot.
As mentioned, I'm first focusing on m68k, but I'll move to DEC Alpha when it is done.

thesamesam

thesamesam commented on Nov 3, 2025

@thesamesam

Would @glaubitz or @thesamesam be interested in creating such an MCP?

I am interested. I just want to get amd64 working well enough first so I am not proposing lots before I know what I am doing. Probably HPPA as it's the one I have the most interest in, but I am open to the others too. I can also do some together with @glaubitz (maybe the first one and then others we can divide up, dunno).

antoyo

antoyo commented on Nov 3, 2025

@antoyo
Contributor

Nice. Thank you.
I guess we should write a draft somewhere first to be able to review it to make sure we don't forget some things like the required change in Rust to mention that a specific target only works with the GCC codegen.

glaubitz

glaubitz commented on Nov 3, 2025

@glaubitz

I have just looked into adding m68k support to rustix and linux-raw-sys and it seems to me that those packages basically duplicate the functionality of the libc crate.

Plus, it seems one needs clang for a given target architecture to auto-generate code in linux-raw-sys, is that right?

thesamesam

thesamesam commented on Nov 3, 2025

@thesamesam

The generated bindings seem to be checked into the repo. Does building the crate require regenerating them? As long as it doesn't, we're fine.

bjorn3

bjorn3 commented on Nov 3, 2025

@bjorn3
Member

linux-raw-sys contains a separate set of bindings for every architecture given that various types have different definitions between architectures. So while you don't need to regenerate the bindings while building linux-raw-sys, you do need to generate them once for the target architecture first, which needs libclang support for the architecture as that is what rust-bindgen is built on top of.

glaubitz

glaubitz commented on Nov 3, 2025

@glaubitz

which needs libclang support for the architecture as that is what rust-bindgen is built on top of.

Is that actually true? I would assume that you can just generate the bindings on x86_64 even for other architectures when you have the kernel source checked out. I don't assume that bindgen has to be run natively for the architecture you want to add, does it?

thesamesam

thesamesam commented on Nov 3, 2025

@thesamesam

Ah, I'd assumed libclang was used for generation from some definitions of types and such in Rust (and therefore just libclang on another platform would be sufficient). That's going to be a problem then...

Where is the actual requirement coming from here? The kernel doesn't rely on C standard library types, so I guess it comes from the right preprocessor macros being set (and perhaps sizeof(...)) giving the results needed? But for almost all of it, they should be references to some type which is defined in a handful of places.

bjorn3

bjorn3 commented on Nov 3, 2025

@bjorn3
Member

I don't assume that bindgen has to be run natively for the architecture you want to add, does it?

I meant that libclang has to have support for analyzing code for the target architecture, not that libclang itself must be built for the target architecture.

glaubitz

glaubitz commented on Nov 3, 2025

@glaubitz

I don't assume that bindgen has to be run natively for the architecture you want to add, does it?

I meant that libclang has to have support for analyzing code for the target architecture, not that libclang itself must be built for the target architecture.

OK, but that would defeat the whole purpose of GCC-based code generation backends. Can we do this differently?

And is libclang actually used for parsing assembler code?

bjorn3

bjorn3 commented on Nov 3, 2025

@bjorn3
Member

And is libclang actually used for parsing assembler code?

No. It is only used by rust-bindgen for parsing C headers and expanding preprocessor macros to extract type definitions and function declarations (and experimentally to parse function bodies for inline functions, but I don't expect linux-raw-sys to depend on that).

Can we do this differently?

Either rust-bindgen would need to gain a C parser and pre-processor written in Rust, or it would need to gain a GCC backend: rust-lang/rust-bindgen#1949 Or maybe in the case of linux-raw-sys you can hack your way around it with a whole bunch of #defines and then telling libclang that you are compiling for a known target?

thesamesam

thesamesam commented on Nov 3, 2025

@thesamesam

And is libclang actually used for parsing assembler code?

It's needed to figure out what some arbitrary C type actually is. A simple example is int* a in some struct. What's the size of that struct? You need to know the size of int* on that target.

Or maybe in the case of linux-raw-sys you can hack your way around it with a whole bunch of #defines and then telling libclang that you are compiling for a known target?

That's what I was thinking, but I'm also looking at whether we can get away with some small support in Clang (without an LLVM backend). TCE.{h,cpp} is a small example.

glaubitz

glaubitz commented on Nov 3, 2025

@glaubitz

Meh, that used to work without having clang support when there was just libc. More work then. :(

antoyo

antoyo commented on Nov 3, 2025

@antoyo
Contributor

I have just looked into adding m68k support to rustix and linux-raw-sys and it seems to me that those packages basically duplicate the functionality of the libc crate.

Would it be possible to generate these bindings manually by taking what's in libc and adjusting the code if needed?

bjorn3

bjorn3 commented on Nov 3, 2025

@bjorn3
Member

For a subset yes. Most things in linux-raw-sys are not exported by libc however. Perhaps patching rustix to always enable the use-libc feature and to remove the linux-raw-sys dependency would be easier?

glaubitz

glaubitz commented on Nov 3, 2025

@glaubitz

I have asked the linux-raw-sys project now to provide instructions on how to add a new target here.

antoyo

antoyo commented on Nov 4, 2025

@antoyo
Contributor

I have asked the linux-raw-sys project now to provide instructions on how to add a new target here.

Thanks.

I believe I'm at the point where I need this for compiling rustc for m68k:

error[E0432]: unresolved import `crate::general`
    --> /home/user/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/linux-raw-sys-0.9.4/src/lib.rs:166:16
     |
 166 |     use crate::general::__kernel_fd_set;
     |                ^^^^^^^ could not find `general` in the crate root
     |
note: found an item that was configured out
    --> /home/user/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/linux-raw-sys-0.9.4/src/lib.rs:239:9
     |
 237 | #[cfg(target_arch = "arm")]
     |       ------------------- the item is gated behind the `arm` feature
 238 | #[path = "arm/general.rs"]
 239 | pub mod general;
     |         ^^^^^^^
note: found an item that was configured out
    --> /home/user/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/linux-raw-sys-0.9.4/src/lib.rs:319:9
     |
 317 | #[cfg(target_arch = "aarch64")]
     |       ----------------------- the item is gated behind the `aarch64` feature
 318 | #[path = "aarch64/general.rs"]
 319 | pub mod general;
     |         ^^^^^^^
note: found an item that was configured out
    --> /home/user/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/linux-raw-sys-0.9.4/src/lib.rs:399:9
     |
 397 | #[cfg(target_arch = "csky")]
     |       -------------------- the item is gated behind the `csky` feature
 398 | #[path = "csky/general.rs"]
 399 | pub mod general;
     |         ^^^^^^^

[…]

I'll try to workaround this for now.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @antoyo@glaubitz@gyrovorbis@thesamesam@bjorn3

        Issue actions

          DEC Alpha support · Issue #742 · rust-lang/rustc_codegen_gcc