cgccldelflinux-from-scratch

gcc compiles ELF file with wrong search list


After compiling gcc and using it to compile a simple c program:

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

the result is:

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

but according to Linux From Scratch guide 9.1 in section 6.25 "Verify that the compiler is searching for the correct header files:" the following is expected (ignoring the *linux-gnu paths...):

#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

What's even worse is that

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

is:

SEARCH_DIR("/usr/lib");

but should be:

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");

I've tried to add all paths to /etc/ld.so.conf and recompiled gcc pass 2, but nothing changed.

So what exactly determines the SEARCH_DIR entries in an ELF file?

EDIT1: I backtracked and found out that the previous step make -k clean did not finish because it's missing autogen, which is not covered at all in the LFS guide 9.1 it seems.


Solution

  • I restarted LFS 9.1 and followed the instruction with more care, now the output is as expected!

    There are two things I did differently:

    1. In my first attempt I ignored the advice on chapter 5 to remove extracted tarballs after each section:

    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. When I reinstalled the host OS I didn't create it with lfs as first user. Instead I created it with lfshost user and created the user lfs as described in section 4.3