LFS 学习日记(第5章构建临时系统之5.7. Glibc-2.11.1 )

2010年06月22日 星期二
http://www.linuxfromscratch.org/lfs/view/6.6/chapter05/glibc.html
5.7. Glibc-2.11.1

前面vmware宿主机的内存设为了256M,此时开始增为512M。

lfs:/mnt/lfs/sources/glibc-build$ time { ../glibc-2.11.1/configure --prefix=/tools     --host=$LFS_TGT --build=$(../glibc-2.11.1/scripts/config.guess)     --disable-profile --enable-add-ons     --enable-kernel=2.6.18 --with-headers=/tools/include     libc_cv_forced_unwind=yes libc_cv_c_cleanup=yes && make && make install; }

real    8m12.358s
user    7m24.676s
sys    5m28.597s

关于configure中 build,target,host中的学习 ( http://www.cublog.cn/u1/46715/showart_446825.html ),摘要如下:
<摘录开始>
具体解释一下,build就是你正在使用的机器,host就是你编译好的程序可以运行的平台,target就是你编译的程序可以处理的平台.这个build和host比较好理解,但是target就不好办了,到底什么意思呢?一般来说,我们平时所说的交差编译用不到他 target的,比如./configure --build=i386-linux,--host=arm-linux就可以了,在386的平台上编译可以运行在arm板的程序.但是,一般我们都是编译程序,而不是编译工具,如果我们编译工具,比如gcc,这个target就有用了.如果我们需要在一个我们的机器上为arm开发板编译一个可以处理 mips程序的gcc,那么target就是mips了.不知道我的解释是否正确,如果大家看到了这篇帖子,觉得不对,批评指正.
</摘录结束>

另一个学习资料:http://www.linuxview.net/show.php?id=305
交叉编译器制作流程
<摘录开始>
为什么叫“交叉编译器”(cross compiler),就是因为它跨平台来编译程序!做交叉编译器要弄清楚3个概念:host, build, target:
build -- 你在什么平台上编译的这个编译器
host -- 这个编译器将来要在什么平台上运行
target -- 编译器最终会生成在哪个平台上执行的可执行代码

这里我可以给个例子 build=i386 host=sparc64 target=mips32 表示我们在x86平台上编译了一个在sparc64平台上运行的编译器,它将源码编译生成了要在mips32平台上运行的可执行程序。
描述一个平台,通常使用三元组:arch-vendor-os, 比如i386-redhat-linux 表示x86平台,生产商是redhat,而使用的os是linux。
</摘录结束>

前面的同第5章小节Binutils和Gcc的第一遍编译中的 --target=$LFS_TGT 的作用就是编译可以处理$LFS_TGT系统程序的binutils和Gcc;这里 Glibc 中的 --host=$LFS_TGT 的作用就是告诉glibc配置成在$LFS_TGT系统上运行的程序,那么,它就将自动调用在$LFS/tools中可以处理$LFS_TGT程序的交叉链接器(cross-linker)和交叉编译器(cross-compiler),而不是宿主系统的链接器和编译器。这里试验一下,把tools目录改名看能不能不用交叉链接器和交叉编译器?

上述试验结果,没有在$LFS/tools中的交叉编译器等,会使用宿主系统中的gcc,但会报告如下(config.log):
<code>
## ----------- ##
## Core tests. ##
## ----------- ##

configure:2028: checking build system type
configure:2046: result: i686-pc-linux-gnu
configure:2068: checking host system type
configure:2083: result: i686-lfs-linux-gnu
configure:2114: checking for i686-lfs-linux-gnu-gcc
configure:2144: result: no
configure:2154: checking for gcc
configure:2170: found /usr/bin/gcc
configure:2181: result: gcc
configure:2193: WARNING: using cross tools not prefixed with host triplet
configure:2413: checking for C compiler version
configure:2421: gcc --version >&5
gcc (Ubuntu 4.4.3-4ubuntu5) 4.4.3
Copyright (C) 2009 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
</code>

而有$LFS/tools中的交叉编译器等存在的情况下,config.log中相应的报告为:
<code>
## ----------- ##
## Core tests. ##
## ----------- ##

configure:2028: checking build system type
configure:2046: result: i686-pc-linux-gnu
configure:2068: checking host system type
configure:2083: result: i686-lfs-linux-gnu
configure:2114: checking for i686-lfs-linux-gnu-gcc
configure:2130: found /tools/bin/i686-lfs-linux-gnu-gcc
configure:2141: result: i686-lfs-linux-gnu-gcc
configure:2413: checking for C compiler version
configure:2421: i686-lfs-linux-gnu-gcc --version >&5
i686-lfs-linux-gnu-gcc (GCC) 4.4.3
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
</code>

可见,configure测试首先找的是平台三元组(host triplet)为前缀的交叉编译器,找不到还会警告“configure:2193: WARNING: using cross tools not prefixed with host triplet”,然后在找不到交叉编译器i686-lfs-linux-gnu-gcc的情况下,使用宿主系统的gcc 。

question: 如果不用交叉编译器编译glibc会有什么后果?i686-lfs-linux-gnu-gcc的configure配置的是 --target=$LFS_TGT,而宿主系统的gcc配置的是 --target=i486-linux-gnu。

question: configure配置参数中的libc_cv_forced_unwind 和 libc_cv_c_cleanup 有什么用?不配置这两个参数会出现什么后果?

todo: gcc CFLAGS 相关参数的使用,如:march, mtune等;configparms 文件的使用 资源: man gcc
http://blog.openrays.org/blog.php?do=showone&tid=364 march 和mtune的区别

todo: 有需要时有选择的重点学习glibc中的一些库或程序的具体应用( http://www.linuxfromscratch.org/lfs/view/6.6/chapter06/glibc.html#contents-glibc )