简体   繁体   English

GNU Triplet,GCC和Linux内核编译

[英]GNU Triplet, GCC and Linux kernel compiling

My native gcc says, that its triplet is the following. 我的母语gcc说,它的三元组如下。

> gcc -dumpmachine
x86_64-suse-linux

Where cpu-vendor-os are correspondingly x86_64, suse, linux. 其中cpu-vendor-os相应地是x86_64,suse,linux。 The latter means that glibs is in use(?). 后者意味着glibs正在使用(?)。 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. 当我在进行交叉编译基于busybux的系统时,编译器三元组就像avr32-linux-uclibc,其中os是'linux-uclibc',意思是使用了uclibc。

The difference between 'linux-glibc' and 'linux-uclibc' is (AFAIU) in collect2 behavior and libgcc.a content. 'linux-glibc'和'linux-uclibc'之间的区别在于collect2行为和libgcc.a内容中的(AFAIU)。 Either glibc or uclibs are silently linked to the target binary. glibc或uclibs都默默地链接到目标二进制文件。

The questions is that how is the linux kernel been compiled by the same compilers? 问题是linux内核是如何由相同的编译器编译的? 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 一旦内核在裸机上运行,​​它就不能与任何类型的用户空间libc链接,并且应该使用适当的libgcc.a

gcc has all kind of options to control how it works. gcc有各种选项来控制它的工作方式。 Here's a few relevant ones: 这里有一些相关的:

  • -nostdlib to omit linking to the standard libraries and startup code -nostdlib省略链接到标准库和启动代码
  • -nostdinc to omit searching for header files in the standard locations. -nostdinc省略在标准位置搜索头文件。
  • -ffreestanding to compile for a freestanding environment (such as a kernel) -ffreestanding编译为独立环境(如内核)

You also do not need to use gcc for linking. 您也不需要使用gcc进行链接。 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. 由于任意原因,linux内核构建似乎不使用-ffreestanding ,它确实控制了链接​​阶段,并确保内核在不-ffreestanding任何用户空间代码的情况下进行链接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM