Skip to content

Instantly share code, notes, and snippets.

@srleyva
Last active May 19, 2019 20:26
Show Gist options
  • Save srleyva/48b825add54321f28f359833a2595f46 to your computer and use it in GitHub Desktop.
Save srleyva/48b825add54321f28f359833a2595f46 to your computer and use it in GitHub Desktop.

Creating the toolchain

We must build from source as our OS does not have a package manager.

  • configure - will create a Makefile based off of user input. Checks for appropriate dependancies and compilers.
  • make - calls compilers and complies the code.
  • make install - copies compiled binaries to correct location

Bootstrapping is essentially using host OS tools (without creating dependancies on the host) to create a temporary toolchain in the LFS env. This allows us to use a temporary toolchain to build our OS.

Why bin-utils first?

Why is bin-utils installed first? It creates some things we need such as the assember to create the executable and ldd which links to libc.so. Bin-utils is needed to compile the compiler.

How C compilation works?

  1. Dumps all of c header files into <program_name>.i file
  2. Compiler converts the <program_name>.i file to assembly
  3. bin-utils provides an assembler used to convert assembly to binary or <program_name>.o
  4. bin-utils utility ld or linker to convert object file into an executable format <program_name>.o a. Check the os and links shared lib to the a.o b. in LFS libc.so which is provided by glibc
  5. libc.so is needed or is considered a dependancy on disk

This is why you can't run on windows. <program_file>.o is relocatable and ldd has not made libc.so a dependancy. This can be copied and run after particular libray is avaiable on disk provided by the OS. In linux this is glibc but windows or other OS's can provide there own.

Linux Headers

  • API - is a set of structured functions that can be consumed from an application
  • Linux Kernel handles the inner hardware
    • glibc interacts with the kernel through system calls
    • This has to be exposed through API (Header files are the Linux API)

Glibc

  • Provides the list of shared libraries
    • libc.so is included
    • provides basic system routines (memory, pattern matching, etc.)
    • Works very closely with kernel
      • System calls all go through glibc even though they are implemented by the kernel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment