问题描述
我试图理解Linux From Scratch的概念,并想知道为什么要多次构建binutils
,gcc
等.
为什么我们分别需要pass1和pass2?为什么我们不能在传递1中构建工具,然后使用它们构建gcc
,glibc
,libstdc++
等.
目标是确保您的构建都是一致的,无论您使用哪个编译器来编译您的编译器(以及编译器具有哪些错误).
假设您正在使用gcc 3.2构建gcc 4.1(我将把gcc 3.2称为"stage-0").在使用gcc 4.1以外的任何编译器进行构建时,对gcc 4.1进行质量检查的人们都没有测试它能否正常工作-因此,需要先构建一个stage-1 gcc,然后再使用那个stage-1编译阶段2编译器,以防止阶段0编译器中的任何错误影响最终结果.
然后,gcc的默认编译过程使用Stage-2编译器构建Stage-3编译器,并比较两个二进制文件:它们之间的任何差异都可以用来证明存在一个错误.
(当然,这只是避免意外错误的有效机制;请参阅经典的Ken Thompson论文对信任信任的思考,以讨论预期漏洞如何在这种措施下生存下来. /p>
这超出了gcc的范围,进入了整个工具链,因为相同的原则贯穿始终:如果在运行glibc-xy的系统和运行glibc-x的系统上构建glibc-xy的结果有任何差异.(y-1 ),并且您不要进行额外的检查,以确保您正在针对目标环境进行匹配,然后重现这些错误(并测试建议的修复程序)要比其他困难得多.确实是这样:没有您(通常未公开)构建环境的人不一定可以重新创建该错误!
I am trying to understand the concept of Linux From Scratch and would like to know why there are multiple passes for building binutils
, gcc
etc.
Why do we need pass1 and pass2 separately? Why can't we build the tools in pass 1 and then use them to build gcc
, glibc
, libstdc++
, etc.
The goal is to ensure that your build is consistent, no matter which compiler you're using to compile your compiler (and thus which bugs that compiler has).
Let's say you're building gcc 4.1 with gcc 3.2 (I'm going to call that gcc 3.2 "stage-0"). The folks who did QA for gcc 4.1 didn't test it to work correctly when built with any compiler other than gcc 4.1 -- hence, the need to first build a stage-1 gcc, and then use that stage-1 to compile a stage-2 compiler, to prevent any bugs in the stage-0 compiler from impacting the final result.
Then, the default compile process for gcc uses the stage-2 compiler to build a stage-3 compiler, and compares the two binaries: Any difference between them can be used as proof of presence of a bug.
(Of course, this is only an effective mechanism to avoid unintended bugs; see the classic Ken Thompson paper Reflections on Trusting Trust for a discussion of how intended bugs can survive this kind of measure).
This goes beyond gcc into the entire toolchain because the same principles apply throughout: If you have any differences in the result between building glibc-x.y on a system running glibc-x.y and a system running glibc-x.(y-1) and you don't do an extra pass to ensure that you're building in a match for your target environment, then reproducing those bugs (and testing proposed fixes) is made far more difficult than would otherwise be the case: Nobody who doesn't have your (typically undisclosed) build environment can necessarily recreate the bug!
这篇关于为什么要多次从头构建Linux(LFS)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!