Gentoo/x32 Experiments

As I head down the path of “My computers are working too darn well, better tweak them more!” in my endless quest to use computers to make other computers work better so I can use them to make the first computer work better, while never actually doing anything outside this increasingly circular environment:

I’ve been curious for a while about the various forms of the x32/ILP32 ABIs for (correspondingly) x86 and ARM. They’re weird little forks, with x32 being “mostly abandoned” and ILP32 being “… wtf is that?” grade, but they have the potential, at least, to rather substantially improve things on the low power machines I prefer using. He says, from the house desktop…

Typically, OSes and applications are either 32-bit or 64-bit (both on x86 and ARM). The 32-bit processor operating modes are older, generally more restricted in register count and processor features, and end up using less memory. The newer, 64-bit operating modes typically have more registers, fancier processor features to use, and end up using a lot more RAM because the pointers are 64-bit, not 32-bit.


There’s this weird little fork that nobody cares about. It’s using a 64-bit processor mode, but 32-bit pointers. You get the benefits of 64-bit operating modes (more registers, more features), and most of the memory use of the 32-bit modes (some values will still be larger, but pointers, the common one, are half the size). The downside is only 4GB of virtual memory space per process, but… for end user stuff, especially as browser have moved to process based isolation, this isn’t the end of the world.

The upside is rather more “stuff” (in terms of number of data structures and the like) you can fit in the small processor caches. As low power x86 and low power ARM boxes tend to have small processor caches (well, really, after the M1 came out, everything else has small processor caches in comparison), this should lead to some performance benefits compared to 64-bit modes, and should improve performance over 32-bit modes (especially on x86) due to the increased register count.

Except, it’s not supported, and probably mostly broken. Which is where I fit in. Because I like that sort of stuff.

So, the short of it is that I have a Gentoo x32 build going right now in a VM, I plan to try and run Clank on x32 here at some point for testing and benchmarking, and once I work out how to build a Debian-type bootstrap from absolute scratch, I’d like to get an ILP32 ARM build going for some machines as well!

If it goes passably, I might even try to package some of it up for other people to mess with!

1 Like

And BPF in the kernel won’t build. :slight_smile: I suppose I shall start a cross compile locally and play there, easier than working in a VM without the full set of my normal tools installed.

So, most kernels actually seem to support the x32 ABI (CONFIG_X86_X32=y). And you don’t actually have to build an x32 kernel, it’s just a 64-bit kernel.

… and then everything else goes off the rails, mostly. Right now, it’s far from clear that Gentoo is capable of building a rustc in the x32 environment. It seems to have at least some support for it, there is x32 awareness in the Rust world, but I’m not quite sure how to find an actual x32 rust install to bootstrap from (rust builds rust).

It seems there was some x32 work in the 2015-2017 era, with the occasional random more recent issue related to it, but nobody really runs it anymore.

However, it should be possible to do some work in a chroot and start troubleshooting/debugging/etc that way…

Does GCC work? Do normal x64 programs work in the environment, or do they all have to be x32?

gcc wil emit x32 binaries just fine - use -mx32 and it’ll do it.

The problem is that the x32 ABI is incompatible with everything else - so you can’t use 32-bit or 64-bit libraries. You need to build an entire stack of x32 libraries.

There are clearly people using it - there are regular bugs filed for things like rust and such that “Hey, this doesn’t work in x32, here’s a patch!” I just can’t figure out what they’re running it on, because none of the distros seem to do much. I got a text console x32 Gentoo running well enough, but lots of the stuff I was trying to build then failed (though I’m gated on Rust).

I’m thinking that learning to build my own x32 .debs from source, and trying to bootstrap on that, will be easier. I can build an x32 target Rust from 64-bit, but the bootstrapping phase of “Downloading a working x32 rustc to build an x32 rustc” is where things go wrong.

I assume you saw the links from here in Adoption x32 ABI - Wikipedia - seems an old Debian worked at one point.

Maybe an old enough version of rustc that was written in C could be used to bootstrap.

Yeah, I’ve seen that. Looking for something a bit more modern.

“Building x32 packages on a 64-bit platform” also solves the rustc issue. Just a question of how much effort am I willing to put in for a bit of performance on obsolete hardware… :wink:

Hm… it may not be just an old Debian.

Index of /debian-ports/pool-x32 is actually pretty recent. Not comprehensive, but it has xorg, among other things. I should try it. It’s a debootstrap type install, no actual installer, but not a big deal. Or, at least, get an x32 capable kernel running on something and mess with that in a chroot.

Yeah interesting, it has stuff built a few days ago! Index of /debian-ports/pool-x32/main/k/krita

That seems like a lovely edge case of Gentoo. It has been ages since I built it on a Pentium 3 box. Likely my Helser days.

It really seems like ARM may be the future.

I’ve got a long series of blog posts coming up regarding ARM systems and interesting things on them!

I ran Gentoo on that quad Pentium Pro 200 server for a while… though at the time, that actually built it decently.