-
Notifications
You must be signed in to change notification settings - Fork 83
Description
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.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!0error. 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 instructionjsr $23,($27),__%E3%j5getting emited incompiler_builtins. From asking about, it seems like%can't be present in symbol names: it is a format specifier(like inprintf). 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).To pick up a draggable item, press the space bar. While dragging, use the arrow keys to move the item. Press space again to drop the item in its new position, or press escape to cancel.
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.To pick up a draggable item, press the space bar. While dragging, use the arrow keys to move the item. Press space again to drop the item in its new position, or press escape to cancel.
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).To pick up a draggable item, press the space bar. While dragging, use the arrow keys to move the item. Press space again to drop the item in its new position, or press escape to cancel.
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 thelibccrate refactor project, to ensure our work does not collide.(Optional) Add Alpha unwinding support to
std.To pick up a draggable item, press the space bar. While dragging, use the arrow keys to move the item. Press space again to drop the item in its new position, or press escape to cancel.
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 commentedon Jul 25, 2025
Do you also need some fixes to use the correct linker?
glaubitz commentedon Jul 25, 2025
Thank you so much for doing this! This is dearly needed and I am really looking forward to be able to bootstrap
rustcon the remaining four architectures in Debian!We can use
moldon m68k and sh4 but we have to useld.bfdon alpha and hppa. (alpha used to be supported inmoldbut it got removed, for hppa there is a WIP branch).CC @danglin44 @gyrovorbis @hdeller @maciej-w-rozycki @rth7680 @sozud
gyrovorbis commentedon Jul 26, 2025
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 commentedon Oct 9, 2025
Hi, I was wondering: Has there been any progress on this?
antoyo commentedon Oct 16, 2025
@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 commentedon Oct 16, 2025
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 commentedon Oct 16, 2025
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 commentedon Nov 3, 2025
We had a discussion with @glaubitz on this mailing list.
I wanted to answer here to keep the discussion in one place.
Yes.
The rust compiler uses the same data layout strings as LLVM, so you can build own using the doc.
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.
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.
Sorry, I didn't link this either in my email. The link is above in the original post.
Thanks a lot.
As mentioned, I'm first focusing on m68k, but I'll move to DEC Alpha when it is done.
thesamesam commentedon Nov 3, 2025
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 commentedon Nov 3, 2025
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 commentedon Nov 3, 2025
I have just looked into adding m68k support to
rustixandlinux-raw-sysand it seems to me that those packages basically duplicate the functionality of thelibccrate.Plus, it seems one needs
clangfor a given target architecture to auto-generate code inlinux-raw-sys, is that right?thesamesam commentedon Nov 3, 2025
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 commentedon Nov 3, 2025
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 commentedon Nov 3, 2025
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 commentedon Nov 3, 2025
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 commentedon Nov 3, 2025
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 commentedon Nov 3, 2025
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 commentedon Nov 3, 2025
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).
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 commentedon Nov 3, 2025
It's needed to figure out what some arbitrary C type actually is. A simple example is
int* ain some struct. What's the size of that struct? You need to know the size ofint*on that 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 commentedon Nov 3, 2025
Meh, that used to work without having clang support when there was just
libc. More work then. :(antoyo commentedon Nov 3, 2025
Would it be possible to generate these bindings manually by taking what's in
libcand adjusting the code if needed?bjorn3 commentedon Nov 3, 2025
For a subset yes. Most things in linux-raw-sys are not exported by libc however. Perhaps patching rustix to always enable the
use-libcfeature and to remove the linux-raw-sys dependency would be easier?glaubitz commentedon Nov 3, 2025
I have asked the
linux-raw-sysproject now to provide instructions on how to add a new target here.antoyo commentedon Nov 4, 2025
Thanks.
I believe I'm at the point where I need this for compiling rustc for m68k:
I'll try to workaround this for now.