3
votes

My native gcc says, that its triplet is the following.

> gcc -dumpmachine
x86_64-suse-linux

Where cpu-vendor-os are correspondingly x86_64, suse, linux. The latter means that glibs is in use(?). When I am doing cross-compiling busybux-based system the compiler triplet is something like avr32-linux-uclibc, where os is 'linux-uclibc', meaning that uclibc is used.

The difference between 'linux-glibc' and 'linux-uclibc' is (AFAIU) in collect2 behavior and libgcc.a content. Either glibc or uclibs are silently linked to the target binary.

The questions is that how is the linux kernel been compiled by the same compilers? As soon as the kernel runs on bare-metal it must not been linked with any kind of user-space libc, and should use appropriate libgcc.a

1
Some compilers use a quadruplet. The form is architechure-vendor-os-library. But even this is not sufficient as FPU, object format and other conventions may apply. At the root, gcc just supports a prefix that is free form. People come up with names and there is no unifying body to make them unique. -dumpspecs, etc can be used to help identify the compiler.artless noise

1 Answers

3
votes

gcc has all kind of options to control how it works. Here's a few relevant ones:

  • -nostdlib to omit linking to the standard libraries and startup code
  • -nostdinc to omit searching for header files in the standard locations.
  • -ffreestanding to compile for a freestanding environment (such as a kernel)

You also do not need to use gcc for linking. You can invoke the linker directly, supply it with your own linker map, startup object code, and anything else you need.

The linux kernel build seems, for arbitrary reasons not to use -ffreestanding , it does control the linking stage though, and ensures the kernel gets linked without pulling in any userspace code.