Post APqClkXLcUIaSXxYum by js@mstdn.io
 (DIR) More posts by js@mstdn.io
 (DIR) Post #APqCVVOKA9jsqwzdXk by bugaevc@floss.social
       2022-11-21T20:34:26Z
       
       1 likes, 0 repeats
       
       Spent most of today trying to build myself a cross toolchain —specifically, I want to compile binaries for GNU/Hurd from my GNU/Linux box. These are both GNU systems that are well supported in the upstream GNU projects, so this should have worked flawlessly, without a single hiccup, right?Lol no 🧵
       
 (DIR) Post #APqCVVpyVLrCEhvids by bugaevc@floss.social
       2022-11-21T20:35:43Z
       
       0 likes, 0 repeats
       
       For starters, there are all the circular dependencies:• GCC includes libgcc and so depends on glibc• glibc of course cannot be built without GCC, and it also depends on MIG, as well as Mach and Hurd headers• MIG depends on Mach too, for types & stuff• Mach naturally needs GCC and MIG to be built• The Hurd needs all four — GCC, MIG, Mach, and glibc.Yay
       
 (DIR) Post #APqCVWP4OrvhzYLkLQ by js@mstdn.io
       2022-11-21T21:30:08Z
       
       0 likes, 0 repeats
       
       @bugaevc newlib is part of GCC to work around that circular dependency
       
 (DIR) Post #APqCVbomGiSqmjPqbo by bugaevc@floss.social
       2022-11-21T20:37:24Z
       
       1 likes, 0 repeats
       
       But this can be worked around in a relatively not-so-terrible way:• You build GCC proper, without libgcc• Then you install some Mach headers without actually compiling anything• Then you build MIG• Now you can kinda compile the Hurd MIG defs, if you trick the build system into letting you build anything.
       
 (DIR) Post #APqCVhXH0i1mWBGx9s by bugaevc@floss.social
       2022-11-21T20:39:19Z
       
       0 likes, 0 repeats
       
       You do this by invoking CC=gcc ./configure --host=i686-gnu $OTHER_FLAGS — i.e., we're building for the Hurd, but do your stupid checks using my host toolchain for now so that we can pretend that everything works and at least get something done today• After this, you can actually build enough of glibc to install its headers. You'll also have to build csu/crt[1in].o & manually copy them over into the prefix, and also create a couple of empty files (include/gnu/stubs.h & the very lib/libc.so!)
       
 (DIR) Post #APqCVjIoRReHzuWQtc by bugaevc@floss.social
       2022-11-21T20:41:29Z
       
       0 likes, 0 repeats
       
       Why glibc doesn't do this automatically is beyond me, but I guess this is a small thing relative to everything else here• Now you can finally go back to GCC and build libgcc• Now you can build glibc for real, then Hurd, then whatever else remains.Sounds like a breeze, doesn't it?But anyways, *that* I have figured out. What I haven't is paths.
       
 (DIR) Post #APqCVktiVilMwenQ3c by bugaevc@floss.social
       2022-11-21T20:45:22Z
       
       0 likes, 0 repeats
       
       Simply speaking, I want my toolchain to intrinsically know where to look for (system) header files and libraries — in $PREFIX/include and $PREFIX/lib respectively — so that when I set CC=$PREFIX/bin/i686-gnu-gcc the right directories are picked up automatically, just like the system compiler picks up /usr/include and /usr/lib without me having to add them explicitly.That doesn't sound like a very strange thing to want, does it?
       
 (DIR) Post #APqCVmTucdJHrCjq76 by bugaevc@floss.social
       2022-11-21T20:49:49Z
       
       0 likes, 0 repeats
       
       In fact I'm almost positive that other cross toolchains I've worked with in the past have done just that.But — I can't seem to be able to find the right combination of incantations. Between all the --prefix, DESTDIR, --with-sysroot, --with-byild-sysroot, --with-headers, --with-native-system-header-dir, something goes wrong. I was actually able to convince GCC to look for headers in the right place, but the libraries still escape me.
       
 (DIR) Post #APqCdPIahMIoH44ydU by js@mstdn.io
       2022-11-21T21:31:43Z
       
       0 likes, 0 repeats
       
       @bugaevc Pass `--with-sysroot` to GCC's `./configure`
       
 (DIR) Post #APqClkXLcUIaSXxYum by js@mstdn.io
       2022-11-21T21:33:09Z
       
       0 likes, 0 repeats
       
       @bugaevc Oh and maybe also `--oldincludedir`.
       
 (DIR) Post #APqCz6r9wo85Rlb4ka by bugaevc@floss.social
       2022-11-21T21:35:00Z
       
       0 likes, 0 repeats
       
       @js yeah, --with-sysroot=$PREFIX --with-native-system-header-dir=/include is what got me working includes. If there was a --with-native-system-library-dir, I'd be basically done
       
 (DIR) Post #APqDBXBJtfmCZGx34q by js@mstdn.io
       2022-11-21T21:37:50Z
       
       0 likes, 0 repeats
       
       @bugaevc Why not just put those into $PREFIX/$host/lib and $PREFIX/$host/include?
       
 (DIR) Post #APqGSBZ9oe9YJWjUYK by bugaevc@floss.social
       2022-11-21T22:14:33Z
       
       0 likes, 0 repeats
       
       @js for one thing, I don't get to choose, it's enough for me to set --prefix=$PREFIX and stuff already installs itself into $PREFIX/lib & $PREFIX/include (and some installs into $PREFIX/i686-gnu/* too, for some reason!) — and I need my toolchain to with that.But I also don't see why I'd need that extra /i686-gnu/. There's no multilib here, neither on the host nor in the prefix, everything is i686-gnu.I guess if nothing else works I could strategically place some symlinks...
       
 (DIR) Post #APvTp7Lzugg36YdsPo by bugaevc@floss.social
       2022-11-23T15:31:53Z
       
       0 likes, 0 repeats
       
       🎉$ i686-gnu-gcc hello.c -o hello$ file hellohello: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld.so, for GNU/Hurd 0.0.0, with debug_info, not stripped$ unameLinux
       
 (DIR) Post #APvTp7mEL9f2PuupIu by js@mstdn.io
       2022-11-24T10:37:54Z
       
       0 likes, 0 repeats
       
       @bugaevc That looks wrong? The triple is either missing vendor or OS. What does i686-gnu-gcc -v say?
       
 (DIR) Post #APvTp8wtyxn83IurZo by bugaevc@floss.social
       2022-11-23T15:33:34Z
       
       0 likes, 0 repeats
       
       But I'm not sure I should call this a win: I eventually gave up and had to$ ln -s ../include i686-gnu/sys-include$ ln -s ../lib i686-gnu/libmy way out of this.
       
 (DIR) Post #APvTpAXS4Yccyx1ZBY by bugaevc@floss.social
       2022-11-24T08:54:59Z
       
       0 likes, 0 repeats
       
       And it runs, too!$ scp hello darnassus:$ ssh darnassusbugaevc@darnassus:~$ ./hello Hello world!
       
 (DIR) Post #APvUI8K5OB5AVaaFhQ by bugaevc@floss.social
       2022-11-24T10:43:04Z
       
       0 likes, 0 repeats
       
       @jsUsing built-in specs.COLLECT_GCC=i686-gnu-gccCOLLECT_LTO_WRAPPER=/home/sergey/dev/crosshurd/libexec/gcc/i686-gnu/12.2.0/lto-wrapperTarget: i686-gnuConfigured with: ../configure --prefix=/home/sergey/dev/crosshurd --target=i686-gnu --with-lib-path=/home/sergey/dev/crosshurd/lib --disable-multilib --enable-languages=cThread model: posixSupported LTO compression algorithms: zlib zstdgcc version 12.2.0 (GCC)
       
 (DIR) Post #APvUlxxiTUQV3wLVg0 by js@mstdn.io
       2022-11-24T10:48:35Z
       
       0 likes, 0 repeats
       
       @bugaevc Hm ok, it seems to not have normalized to a proper triple (you can have the binprefix to be different from the target). So it seems that GNU people don't talk to each other and don't know how triples work, great. It should be probably something like i686-pc-gnu.
       
 (DIR) Post #APvUqJag0EQTIfdvFY by bugaevc@floss.social
       2022-11-24T10:48:42Z
       
       0 likes, 0 repeats
       
       @js FWIW, this is the same "triple" as used by Debian GNU/Hurd. I've also seen i[356]86-pc-gnu in the wild, but chose to stick with what Debian uses
       
 (DIR) Post #APvUqK5s8FNarQEpsG by js@mstdn.io
       2022-11-24T10:49:22Z
       
       0 likes, 0 repeats
       
       @bugaevc Yeah I just looked it up and found a patch where someone tried to add it to LLVM, which was met with a lot of disbelief that GNU people don't know how the stuff works that they invented ;)
       
 (DIR) Post #APw7u948yJHY1rF98q by js@mstdn.io
       2022-11-24T18:06:59Z
       
       0 likes, 0 repeats
       
       @bugaevc Out of curiosity, how would you even match that correctly in a configure script? $host against *gnu also catch Linux. $host_os - probably not even set? $host_vendor (or whatever it was called) == gnu? This is just … so wrong.
       
 (DIR) Post #APwAMYYfz78T6pCS5A by mathew@mastodon.social
       2022-11-21T21:55:41Z
       
       0 likes, 0 repeats
       
       @bugaevc The first language where I’ve found cross-compilation painless enough to consider using for my own projects, is Go.I’ve tried building C programs for my Synology NAS and it was a horrible experience, even though both systems were x86. My Go programs, I just set a couple of environment variables, compile normally, and rsync the binary across.I hope more languages will follow Go’s lead and have painless cross compile.
       
 (DIR) Post #APwAMZ3s785afZnMhs by feld@bikeshed.party
       2022-11-24T18:34:20.621267Z
       
       0 likes, 0 repeats
       
       @mathew @bugaevc it's not as hard when you don't need to link to a libc which is what you get with GoBut then that opens a different can of worms :can: