So you want to cross compile illumos...

I want to cross compile to illumos from linux, for reasons I’ll hopefully get to write about in the future. This is a pretty tricky endeavor. Let’s talk about why.

illumos’s toolchain for the most part is not terribly exotic. It’s using GCC, so at least we’re not dealing with a weird bespoke compiler. Here’s the main things we do need to care about:

libc is maybe an obvious one- your code needs to link against a libc and it’s gotta be the libc for the system. That’s fine enough. It does mean that we probably want to be able to cross-compile that libc along with everything else, but we could maybe scrape by copying a binary libc onto our Linux system to get started. The linker is maybe less obvious.

See, in illumos land, there’s a lot of tools with history older than many of the tools we use today, and one such tool is its linker. illumos has its own linker implementation, and to my knowledge it’s the only linker you can rely on to successfully generate illumos binaries (but we’ll talk about why we might be wrong about that in a bit). So, we really would like to get the linker to work if we can.

Speaking of illumos-only tools, here’s the thing that’s causing me the most grief right now: illumos’s dmake. Don’t get this confused with OpenOffice’s dmake - this is different. They might share some history? maybe? But if they do, they’re not compatible today. Anyways, why is this such a problem? Well illumos’ dmake is built with dmake! It’s a self-hosting build tool. That’s all well and good except for when you’re trying to compile for another OS, one where perhaps you can’t run the build tool yet.

All of this is a bit complicated by the fact that illumos has a monolithic git repo where all the code for the kernel and userspace software live, which means that there’s some project-wide state that gets threaded into the builds of each individual tool by the monolithic network of Makefiles, and the cross-dependencies between things are a little obscured.

So what are our options?

One thing we could do is try to cross-compile from illumos to Linux. Now we have two cross-compilation problems. But, if we could convince the build system to generate Linux binaries, then maybe we could build just dmake and nothing else, and use that to get started building things from the Linux side of things.

We could also try to replace dmake with GNU make. There’s some illumos forks that do this, and while it is tempting, I would like to be able to build with a source tree as close to upstream as possible, so I’m hesitant. But we could compromise, replacing the build system for just dmake, and then once we have that up and running use that to build everything else. But I think we may need to hack away at the build system a bit anyway to support the cross compilation, so maybe we should just replace the build system wholesale (again, there’s another project that does this.)

Then hopefully we can convince the linker to build under linux, and finally we can (probably?) start cross compiling.

So what’s this other project we keep talking about? There is some degree of precedent for all this, but we’re left with more questions than answers after investigating it a bit. There’s this aarch64/riscv port of illumos over at n-hys/illumos-gate, and it does replace the build system with GNU make, and it supports cross compiling from linux. But, it also seems to install the ld from GNU binutils into the system. It seems that it only builds the ld.so from illumos and we suspect that since it’s not beholden to generating stuff compatible with existing illumos systems, this fork might have gone out of its way to support output from the GNU linker to make life a bit easier. That makes sense for that project, but we need to generate stuff that works on existing illumos boxes, so that’s not a strategy we can pursue.

Or I could be dead wrong with my read on that. There’s a lot of commits of changes to go through if I wanted to be certain.

Anyway, it still might be worth grabbing the makefiles since they’re already kitted out to handle cross compilation.

The other challenge with the monolith is that it’s sort of geared to you building the whole thing at once, which is probably going to be a lot more effort than building a subset of it. Or it won’t be, I don’t know, but I think that we at least are not interested in building the kernel right now. It should be possible to only build subsections of the repo though, it’s just not obvious to me yet how we would go about doing that.

So anyway, if you know the answers to all of my problems do send me an email would you? Otherwise, well, hopefully we figure this out and have some interesting posts for you down the line.