Cross-compiling an i386 kernel snap

Moving from bug 1563363 here, since the bug’s not receiving any attention.

From my investigation on this:

  • There’s “setarch i386” to fake a native 32bit host (uts_machine in Snapcraft’s context).
  • gcc requires -m32 to change its output format and works perfectly with a stand-alone .c file
  • From a proof of concept, ldd needs more convincing in a kbuild context. An error message tells me I need “-m elf-i386” to make things work, but it still won’t link, claiming the format is wrong.
  • I had to get libc6-dev-i386 - this could be added to cross-build-packages. Not sure if I may be missing something else, right now x86 is incomplete in that regard and probably not really tested.

Now my question: Wow do you usually set up your environment to cross-compile? I’d like for Snapcraft to replicate ideally the typical setup and use that. Since I don’t build kernels outside of testing Snapcraft, I’d love some feedback from the (i386) kernel developers here.