-
Notifications
You must be signed in to change notification settings - Fork 47
Description
We're in the process on adding support for new architectures to the Rust compiler with the help of rustc_codegen_gcc.
As a first candidate, we want to get the m68k architecture working which has an LLVM backend which is not 100% feature-complete and has some issues when trying to build the Rust compiler for m68k. Thus, we want to give it a try with rustc_codegen_gcc.
Now, to get the backend working, we need to add m68k support in rustix and linux-raw-sys. While I have experience adding architecture support to the libc crate, I'm not sure how to add architecture support to these two crates. It seems that one has to run bindgen to generate the bindings, but there doesn't seem to be any easy to follow manual for it.
Could you please add instructions on how to add a new architecture so that new contributors don't have to figure this out by trial and error?
Activity
antoyo commentedon Nov 4, 2025
I believe I found it (to be confirmed by someone who knows this project).
In this match, we need:
However, when trying to generate the bindings, it panics with:
I guess I might need to set the alignment to 4 for m68k somewhere.
pekkarr commentedon Nov 4, 2025
I'm able to generate bindings for m68k using the regular LLVM-based rustc with these changes:
antoyo commentedon Nov 4, 2025
I still get the same panic as above with these changes.
Do you use rust stable version 1.91?
Which command do you run to generate the bindings?
I tried:
Thanks for your help.
pekkarr commentedon Nov 4, 2025
I'm using stable rustc 1.91.0 (installed with rustup) on Debian testing, with
libclang-19-dev 1:19.1.7-7(which is used by bindgen). I used those same commands.I tried it now on Arch Linux and I actually got the same alignment panic. Maybe Debian patches their clang to change the alignment on m68k?
pekkarr commentedon Nov 4, 2025
It looks like
size_t(which isunsigned inton m68k) alignment was changed recently in clang to 2 bytes to match what GCC does. Debian is just using an old version of clang.glaubitz commentedon Nov 4, 2025
This is actually a more complicated story. The official SysV ABI for m68k requires a default alignment of 4 bytes and that is actually used on NetBSD ELF as well as Amiga Unix.
However, one of the Linux/m68k maintainers back in the days decided not to switch the default alignment on m68k for Linux from 2 to 4 bytes when the switch was made from a.out to ELF.
I am planning to eventually switch Debian/m68k to 4 bytes alignment and so does Gentoo, but there are still some tests to be done.
See this wiki page for more information.
antoyo commentedon Nov 4, 2025
@pekkarr: Thanks. I managed to generate the code for m68k, but I noticed a few modules are not generated (the content is only
/* automatically generated by rust-bindgen 0.72.1 */).It seems it was the same issue for sparc.
Here are the logs for m68k (it looks normal to me):
I applied a similar fix in my rustix fork to handle m68k.
pekkarr commentedon Nov 5, 2025
Right. For
bootparamandimagethat's probably fine, since those are generated only for a select few architectures.For
ioctl, I got things to work with these changes:(If you're using Linux kernel >= 6.13 you also need to remove one reiserfs include and ioctl from
gen/ioctl/list.c, since reiserfs was removed from the kernel. For some reason the ioctl generation uses system-wide installed Linux headers instead of fresh git ones like the other modules.)And then run
cd gen/ioctl && ./generate.sh(which requires GCC cross-compilers for several architectures installed) and then regenerate the bindings as before.Anyways, I think the alignment panic is a bug in bindgen. Based on the code comments, the issue and the commit that introduced this check, the idea is to check that
size_tis the same type asuintptr_tso thatsize_tcan be mapped tousizein Rust. However, the code checks thatsize_talignment is equal to pointer size, not pointer alignment. I don't think this is required, it should be enough thatsize_thas the same size and alignment as a pointer (which is true for m68k).antoyo commentedon Nov 5, 2025
@pekkarr: Thanks for the info.
What would be the way forward to add support for m68k here?
Would the first step be fixing the panic in bindgen?
pekkarr commentedon Nov 5, 2025
If @sunfishcode agrees that we can add an architecture that's only usable with rustc_codegen_gcc, I can make a pull request for linux-raw-sys.
I think that the bindgen panic is not critical to fix for this, since it can be worked around by using an older libclang (like on Debian) and bindgen is only used when pre-generating the bindings, so users of linux-raw-sys aren't affected. However, fixing the check in bindgen would be important for other Rust libraries that generate C bindings at build time, since that won't work on m68k if the C headers use
size_t.antoyo commentedon Nov 5, 2025
I'm not sure if that's what you mean here, but the Rust compiler already has tier-3 support for m68k.