-
Notifications
You must be signed in to change notification settings - Fork 83
Description
I am currently working on building rustc for m68k(since that seems like a more achievable short-term goal). Many of the roadblocks I'll hit on m68k will also likely be shared with other targets - this issue could server as a reference for that.
Here is a list of currently-known issues:
-
linux-raw-sysdoes not support m68k. This crate is needed byrustc, and a lot of other crates. Proper support will require a moderate amount of work, but it something that can be done now.- The
rustixcrate does not supportm68k. (more specifically, the iocl::const module needs the right values for syscall arguments).- The const assert in https://github.com/rust-lang/rust/blob/ce5fdd7d42aba9a2925692e11af2bd39cf37798a/compiler/rustc_data_structures/src/tagged_ptr.rs#L163 fails. EDIT: the problem is the alignment of usize. Rust uses those bits to store type tags. If the aligement is less than 4, this fails. I have a fix ready to be sent & merged.
- The bootstrap script fails to compile native
GCCfor m68k. This prevents it from building any codegen backends or tools later down the line. This is skipable with some fiddling.- When building other tools(eg.
cargo) the bootstrap script "forgets" where thestdfor m68k is.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.
So, as of toady, with some workarounds, I can get pretty far into the cross-compilation process - a bit more work, and we may be able to get rustc running on m68k.
@glaubitz I think this issue might be of interest to you.
Activity
FractalFir commentedon Jul 27, 2025
For now, it seems like those 4 are the only remaining issues that stop us from getting
rustcon that plaform.Working around them, I got a build of
rustcfor m68k.glaubitz commentedon Jul 27, 2025
Wow, amazing! I guess you can also then add support for alpha, hppa and sh4 ;-).
glaubitz commentedon Jul 27, 2025
FWIW, in case you're running into alignment issues with m68k, you can use 32-bit alignment as this is the alignment we want to use in the future on Linux/m68k and which is also the default alignment according to the official ELF ABI specification.
FractalFir commentedon Jul 28, 2025
Sadly, any upstream support will have to wait for an MCP about adding the alpha / hppa / sh4 target. There is nothing I can do in this area: I can't maintain those targets, and I have to wait until the interested parties create a MCP.
glaubitz commentedon Jul 28, 2025
Can you elaborate on this a little more? Has it become more complicated adding new targets? What's an MCP?
Back when I added
m68k-unknown-linux-gnu,powerpc-unknown-linux-gnuspeandsparc-unknown-linux-gnuit was a matter of creating a PR.FractalFir commentedon Jul 28, 2025
I sent a message about this here - guess it just got buried.
The TLDR is that adding a tier 3 target requires a MCP, like this one, for example.
A MCP issue is kind of like the PRs you'd send before(I think, unless the process changed a lot). If nobody voices concern about adding Alpha, and one of the Rust devs agrees to help facilitate/oversee the work, the MCP gets accepted after 10 days.
At that point, we have all the blessings to start compiler-side work, and get it merged. This way, we also avoid the repeat of the hppa situation - the target can't be removed as easily.
glaubitz commentedon Jul 28, 2025
glaubitz commentedon Jul 28, 2025
@FractalFir Could you share the m68k
rustcbinaries with me for testing?And did you also manage to build
cargo?FractalFir commentedon Jul 28, 2025
Building
cargoATM - will see if it works out. Once that is done, I will share the tar.gz files with you.Also, you I think you will need to build libgccjit from our repo. That contains the needed patches.
FractalFir commentedon Jul 29, 2025
cargodepends on openSSL, and that is causing a lot of build problems.For now, here is the Rust for m68k without
cargo: https://drive.google.com/file/d/1jF30QJUbDHqvRfjzwXrg4K-oTpLEGqO-/view?usp=sharingantoyo commentedon Jul 29, 2025
With this
rustc, can you successfully compile a "Hello, world!" (using the std) for m68k?FractalFir commentedon Jul 29, 2025
Not yet - I don't have libgccjit.so for m68k.
FractalFir commentedon Jul 29, 2025
With a mock libgccjit.so, I am able to check the
no_coretest file on m68k.So, we now know that everything up to codegen works.
Codegen fails, due to
GenericArgKindnot being sufficiently aligned.glaubitz commentedon Jul 29, 2025
Well, I was actually expecting that. It's the main reason why I'm working to switch Linux/m68k to 32-bit alignment. The linked wiki page contains a patch to switch GCC to 32-bit alignment on Linux/m68k.
Please patch
rustcto use 32-bit alignment onm68k-unknown-linux-gnuby default and don't bother about the broken alignment.Once you have everything in place, I will take care of the alignment discussion with GCC upstream.
dkm commentedon Jul 29, 2025
I'm only lurking here, but when the build is easily reproducible and working, feel free to ping me to add it to compiler explorer (I tried 3 years ago compiler-explorer/compiler-explorer#3760 without success, but would be happy to resurrect the task)
antoyo commentedon Jul 29, 2025
Just to make sure, do you want a cross-compiler or a native compiler?
dkm commentedon Jul 29, 2025
A cross compiler. We're mainly running things on common ubuntu/intel hosts. We have some aarch64 runners, but it's not the main thing, and won't help here anyway 😅
FractalFir commentedon Jul 30, 2025
Cross compilation has worked for a couple of months now. There have been some breakages recently(related to a
rustcrefactor), but those ought to be fully fixed soon.We compile & run m68k executables in our CI:
https://github.com/rust-lang/rustc_codegen_gcc/blob/master/.github/workflows/m68k.yml
dkm commentedon Jul 30, 2025
Oh, nice to hear. Sorry if I'm a little late 😅 I'll see how to port that on our sides! Thanks!
antoyo commentedon Jul 30, 2025
@dkm: It is to be noted, though, that this doesn't work as well as it used to.
We would need to add the support for
m68kin this method first and then do a sync.So, I suggest you wait a bit before trying adding the support for m68k.
FractalFir commentedon Jul 30, 2025
FractalFir commentedon Jul 30, 2025
My PR with this is waiting for review.
rust-lang/rust#144640
glaubitz commentedon Aug 7, 2025
Any progress on this? I recently landed adding the
m68k-unknown-linux-gnutarget in cc-rs, so that building a rustc cross-compiler fails on m68k during the linking stage.We still need to add support for large GOTs in LLVM to get this addressed.
FractalFir commentedon Aug 7, 2025
Got knocked out by a cold for a week or so - so not much progress for now.
Right now, I plan on trying your aligment-fixing patch.
Do you have any images(for VMs) of Debian with this patch applied? And do you have a patched version of qemu somewhere?
From reading the links you have sent, I'll need a slightly modified version of those to fix the alignment issue.
I also tried the other approach(of just patching rustc to work with lower alignment) an that seems feasible, albeit not trivial. Rustc does not use too many bit-fiddling hacks, but the alignment is still an issue in a few spots.
For cargo, we need to cross-compile OpenSSL too, which is a bit of a pain.
I am also working on fixing some other, unrelated problems upstream.
glaubitz commentedon Aug 7, 2025
I have a partially built Debian unstable for m68k with these changes that I created with the help of rebootstrap.
Alternatively, you can use this Gentoo chroot which was built with 32-bits alignment.
While QEMU has the alignment in its code, I did not have any problems with an unpatched QEMU.
glaubitz commentedon Aug 7, 2025
I think you should just use the Gentoo chroot. It works out of the box with 32-bits alignment.
antoyo commentedon Nov 2, 2025
We had a discussion with @glaubitz on this mailing list.
I wanted to answer here to keep the discussion in one place.
No, this is only listed in the original message of this issue.
Do you plan to build
libgccjityourself or let thebootstrapscript from the Rust project build it for you?If you plan to build it yourself, then this is not really a problem. I'm in the process of trying to cross-compile rustc for m68k and I already have a WIP commit to specify where to look for a
libgccjit.sodepending on the target arch.So, on the Rust side, do we need to change the alignment in the target file?
I see
p:32:16:32here. Does it need to bep:32:32:32?Also, I don't know if this is related, but I might need help with these errors that I have when building the Rust library artifacts for m68k:
I only get these errors in a weird case of building them with stage0, but not with stage2. I might not need to build them with stage0, but that's where I'm currently at in my attempt to build the cross-compiler.
Thanks for your help!