0

I've been following the Linux From Scratch book and just need to fill some gaps in my understanding of cross compiling Linux.

Where a toolchain has already been built for the target machine, is the following the general sequence of jobs needed for cross compilation?

  • Create the file system hierarchy for the target
  • Compile the standard library for the target machine and install into the target's file system
  • Compile the kernel for the target machine using the standard library that was previously compiled for the target
  • Create an image from the target's file system
  • Run the image on the target machine
1

You start with a "freestanding" cross compiler, i.e. without OS integration. That will only work for the C frontend.

With this, you can compile the kernel and the C library (which requires kernel headers).

When the C library is built, you can compile the cross compiler with full OS integration and language support.

For gcc, there is usually a bit more back and forth involved as the shared libgcc should be linked against the shared libc, and the shared libc might be needed to be linked against the shared libgcc, but that is largely an optimization that saves a few kilobytes and some effort during in-place upgrades because it removes all compiler dependencies from libc (which allows it to be reused).

4
  • The c std library requires kernel headers?
    – oorst
    Oct 4 at 10:23
  • @oorst, yes, because the kernel interface is not a C function call, but a processor exception caused with a special instruction (int 0x80, sysenter, swi, ...) where the operation requested and the parameters are passed in specific registers. The kernel headers define the values to be passed here, and the libc provides a thin wrapper that allows calling system calls (e.g. open, read) with a C API. Oct 4 at 10:47
  • I see. That explains why libc has a target triple as well.
    – oorst
    Oct 4 at 22:40
  • @oorst, libc only has "build" and "host" triplets. The "target" triplet only exists for cross development tools (binutils, gcc, gdb) and on the toplevel, and the only way it is used is when configuring a subproject, typically like ./configure --build=${build} --host=${target}. Oct 5 at 0:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.