为什么要多次从头构建Linux(LFS)? [英] why multiple passes for building Linux From Scratch (LFS)?

查看:96
本文介绍了为什么要多次从头构建Linux(LFS)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图理解Linux From Scratch的概念,并想知道为什么要多次构建binutilsgcc等.

为什么我们分别需要pass1和pass2?为什么我们不能在传递1中构建工具,然后使用它们构建gccglibclibstdc++等.

解决方案

目标是确保您的构建都是一致的,无论您使用哪个编译器来编译您的编译器(以及编译器具有哪些错误).

假设您正在使用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论文 解决方案

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)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆