gcc 使用错误的搜索列表编译 ELF 文件

gcc compiles ELF file with wrong search list

编译gcc并用它编译一个简单的c程序后:

echo 'int main(){}' > dummy.c
cc dummy.c -v -Wl,--verbose &> dummy.log
grep -B4 '^ /usr/include' dummy.log

结果是:

ignoring nonexistent directory "/tools/lib/gcc/x86_64-pc-linux-gnu/9.2.0/../../../../x86_64-pc-linux-gnu/include"
ignoring duplicate directory "/tools/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include

但根据 Linux From Scratch guide 9.1 in section 6.25 "Verify that the compiler is searching for the correct header files:" 预期如下(忽略 *linux-gnu 路径...):

#include <...> search starts here:
 /usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/include
 /usr/local/include
 /usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/include-fixed
 /usr/include

更糟糕的是

grep 'SEARCH.*/usr/lib' dummy.log |sed 's|; |\n|g'

是:

SEARCH_DIR("/usr/lib");

但应该是:

SEARCH_DIR("/usr/x86_64-pc-linux-gnu/lib64")
SEARCH_DIR("/usr/local/lib64")
SEARCH_DIR("/lib64")
SEARCH_DIR("/usr/lib64")
SEARCH_DIR("/usr/x86_64-pc-linux-gnu/lib")
SEARCH_DIR("/usr/local/lib")
SEARCH_DIR("/lib")
SEARCH_DIR("/usr/lib");

我尝试将所有路径添加到 /etc/ld。so.conf 并重新编译 gcc pass 2,但没有任何改变。

那么究竟是什么决定了 ELF 文件中的 SEARCH_DIR 个条目?

EDIT1:我回溯并发现上一步 make -k clean 没有完成,因为它缺少 autogen,这似乎在 LFS 指南 9.1 中根本没有涉及。

我重新启动了 LFS 9.1 并更加小心地按照说明操作,现在输出符合预期!

有两件事我做了不同的事情:

  1. 在我的第一次尝试中,我忽略了关于 chapter 5 在每个部分之后删除提取的 tarball 的建议:

For each package:

  1. Using the tar program, extract the package to be built. In Chapter 5, ensure you are the lfs user when extracting the package.

  2. Change to the directory created when the package was extracted.

  3. Follow the book's instructions for building the package.

  4. Change back to the sources directory.

  5. Delete the extracted source directory unless instructed otherwise.

  1. 当我重新安装主机 OS 时,我没有以 lfs 作为第一个用户创建它。相反,我使用 lfshost 用户创建了它,并创建了用户 lfs,如 section 4.3
  2. 中所述