Re: General cross-toolchain tutorial recommendation

"Xi Ruoyao" ([email protected] via lfs-support Mailing List) <[email protected]> Sat, 23 Aug 2025 00:27:02 +0800
Newsgroups gmane.linux.lfs.support
Message-ID <[email protected]>
On Fri, 2025-08-22 at 17:21 +0200, Ricardo Oliveira wrote:
> The book states:
> > The LFS book is not (and does not contain) a general tutorial to
> > build a cross- (or native) toolchain. Don't use the commands in the
> > book for a cross-toolchain for some purpose other than building LFS,
> > unless you really understand what you are doing.
> Could you folks recommend me a general tutorial to build a cross-
> toolchain? I intend to build my own personal Linux distribution. I was
> going to use LFS' cross-compilation procedure before reading the above
> note.
> Which are the deficiencies of LFS' procedure that can't make it
> general?

You cannot cross-compile *many* innocent packages with the LFS cross
toolchain.  "Innocent" meaning it can be cross-compiled fine with a
general cross toolchain (some packages are just not meant to be cross-
compiled but they are out of our discussion).

The correctness of the LFS method somehow depends on the list of chapter
6 packages.  We've no intention to make the cross toolchain work for
other packages unless we really need to add one into chapter 6.

At least, anything in C++ requiring threading or exception handling will
break with chapter 5 libstdc++ because when it's built libgcc isn't
linked to libc, and the cross-compiler does not support threads.

We may work around the thread issue by using a sed like the one in
chapter 6 gcc, but because we've no intention to make it work for other
packages we just won't add this sed.

The exception handling issue cannot be worked around.  To make a
libstdc++ with exception support we must rebuild libgcc and then
libstdc++ after installing glibc into the sysroot.  In the book the
process is a part of chapter 6 gcc, but then the produced libstdc++ can
only work with chapter 6 gcc (i.e. after entering the chroot
environment).  Thus just installing chapter 6 gcc into sysroot will make
the cross toolchain completely unable to compile C++ programs, as we've
already mentioned in the book (just below the paragraph you quoted).

We can use a hack like
https://www.linuxfromscratch.org/~xry111/lfs/view/rust-systemd/chapter06/gcc-pass2.html
(disclaimer: I wrote it years ago and I've never tested it again in the
years; and again we've no intention to include one in the book unless
really necessary) to make the cross toolchain able to build C++ (even
with thread and/or exception) after installing chapter 6 gcc, but
obviously for a general cross toolchain recipe it's easier and more
natural to just build gcc again as a cross compiler (in the LFS term,
"rebuild GCC pass 1"; a new libgcc and libstdc++ will also be rebuilt in
the process) and overwrite the old one.

If you just want to build a distro and you'll not deviate from the book
in and before chapter 6, it should be fine to use the LFS instructions
for the limited cross toolchain.  But if you want to build a fully-
cross-compiled distro (like one for some 100MHz RV32I processor where
building packages is not practical), or for some reason you'll build
something like LLVM in chapter 6, you need a general cross toolchain.

Recipes for a general cross toolchain should be available in a repo of
any distro providing cross toolchains.  See
https://www.linuxfromscratch.org/blfs/view/systemd/introduction/beyond.html
for where to find those repos.  Or maybe it's easier to just use such a
distro and install a cross toolchain from its binary repo.

-- 
Xi Ruoyao <[email protected]>

-- 
http://lists.linuxfromscratch.org/sympa/info/lfs-support
Unsubscribe: See the above information page