v. About the Multilib Edition

What is Multilib

Today, most x86 systems are 64-bit. Before 64-bit came 32-bit, and 16-bit before that. These bit sizes are those that the CPU can work with most efficiently. A result of this is that the CPU registers have changed sizes, assignments, etc, along with different data alignment. Another consequence is that software written or built for one bit size may fail to work on another. To ensure that a previous bit size can run on a CPU with a newer bit size, the CPU with the help of the kernel can emulate software that targets the previous bit size.

This isn't quite enough to bridge bit size incompatibilities, however. Most compiled software has dependencies that come from the system, like the standard C library. When software of a different bit size requests those dependencies, it wants them to be of the same bit size as that software instead of the CPU's.

Multilib bridges that major gap, providing those dependencies for the software's bit size while still offering a mainly 64-bit experience.

This book provides 32-bit (i?86) and x32-bit dependencies and toolchains intended for 64-bit x86 (x86_64) systems.

How MLFS Enables Multilib

[Important]

Important

MLFS is a variant of LFS and installs a completely new LFS system. It is assumed that you are installing a new system and not rebuilding the toolchain to include multilib support. While possible to include support after the fact with a specific process, it is not yet recommended.

LFS in its nature bootstraps itself from another Linux distribution. To do this, every package is compiled from source and installed, often multiple times in stages. In that spirit, MLFS does the same for the dependencies. However, attempting to build a different bit sized application or library on a standard vanilla LFS system results in necessary libraries for this process being unable to be found and linked against or into. The toolchains in place need to gain that support.

The duty of MLFS is to arm the system with toolchains that can target 32-bit and/or x32-bit, then provide basic dependencies that allow 32-bit/x32-bit compilations of packages outside of LFS to succeed and work as expected.

The Purpose of a Multilib System

LFS nowadays is treated as educational material to learn from, less-so using the produced result day-to-day. Installing support for different bit sizes adds more onto the table at a price and makes the initial LFS installing experience more confusing. It's recommended to have installed LFS before installing MLFS. However, if you choose to do the latter, you may encounter situations where having a multilib system is rather beneficial. The following covers a non-exhaustive list of reasons to do so:

  • Closed-source software existing only for 32-bit. That may be the case for certain drivers or some desktop software.

  • Setting up virtualization for a system with a different bit size.

  • To learn the fundamentals of how multilib is set up.

Building a Multilib System

Earlier, it was mentioned MLFS does the same thing as LFS, which is bootstrapping the system from another Linux distribution. At the same time, it was mentioned that a compiler with no support for other bit sizes built in will fail to build anything for that bit size. This means that to build a compiler with support for other bit sizes (32-bit and x32-bit), you need the system you are bootstrapping from to have that support built into the compilers and must have the dependencies that go along with them.

Over time, users of MLFS found that the best media for this purpose is the Gentoo CD. It's personal preference whether you want to use the minimal installation CD, LiveGUI USB image, or the QCOW2 image. The LiveGUI USB image is very user friendly, using KDE as the desktop environment and has web browsers for use. The CDs offer 32-bit and x32-bit support on top of 64-bit. If you already built an MLFS system, MLFS offers a good base to bootstrap from as well.

Building a multilib system is not that much different from building a system using the vanilla LFS book. Besides incorporating changes that allow multilib support in some packages or toolchains, the overall process requires compiling some packages multiple times:

  1. For 64-bit (can provide both programs, libraries, and data)

  2. For 32-bit (typically installs only libraries)

Continue if your system meets the following requirements:

  • You have a x86_64 system.

  • Have the ability to execute 32-bit/x32-bit software. Check compatibility by running the following commands:

    echo 'int main(){}' > dummy.c
    gcc -m32 dummy.c
    ./a.out
    
    rm -vf dummy.c a.out

    If either of the ./a.out commands result in an "Exec format error" message, then you do not have a system kernel capable of building for that architecture within LFS. At that point, try using another distribution or installation media.

If you passed the above architecture requirements, go ahead and build MLFS.