Linux From Scratch 8.3: Some checks after 5.36. Changing Ownership and before 6. Installing Basic System Software
5.2. Toolchain Technical Notes ...removes potential contamination of the target system by lessening the chance of headers or libraries from the host being incorporated into the new tools test suite failure will usually highlight this error before too much additional work is performed
1.1. How to Build an LFS System Chapter 5 also shows you how to build a first pass of the toolchain, including Binutils and GCC (first pass basically means these two core packages will be reinstalled). The next step is to build Glibc, the C library. Glibc will be compiled by the toolchain programs built in the first pass. Then, a second pass of the toolchain will be built. This time, the toolchain will be dynamically linked against the newly built Glibc. The remaining Chapter 5 packages are built using this second pass toolchain. When this is done, the LFS installation process will no longer depend on the host distribution, with the exception of the running kernel. Find out all files that depend on dynamic linker from the host system's /lib(64) directory, id est
/lib64/ld-linux-x86-64.so.2
# Log in as a normal user instead of the user 'lfs' to avoid the following error: "support for the -P option is not compiled into this --disable-perl-regexp binary"
$ cd $LFS
$ FILE1=/tmp/files_depend_on_host_dynamic_linker.txt
$ truncate -s0 $FILE1
for i in $(find tools/ -type f); do
# PCRE negative look-ahead regex: (?!<regex>). https://unix.stackexchange.com/questions/70710/regular-expression-problems-in-bash-negate-doesnt-seem-to-work
# A=$( readelf -l "$i" 2>/dev/null | grep -e '\[Requesting program interpreter: (?!/tool).*\]' )
# if [ $? -eq 0 ]; then
if readelf -l "$i" 2>/dev/null | grep -Pe '\[Requesting program interpreter: (?!/tool).*\]' &>/dev/null; then
echo "$i"
echo "$i" >>$FILE1
fi
done
# https://stackoverflow.com/questions/29244351/how-to-sort-a-file-in-place
$ sort -o "$FILE1"{,}
Retrieve git log for commit hash
$ cd $LFS
$ git --no-pager log --oneline
...
b4dc31e 5.5. GCC-8.2.0 - Pass 1
7087fdc 5.4. Binutils-2.31.1 - Pass 1
...
List all files committed in pass 1
$ FILE2=/tmp/files_built_in_first_pass.txt
$ git --no-pager diff --name-only 7087fdc^ b4dc31e | tee $FILE2
$ sort -o "$FILE2"{,}
Compare to make sure all files depend on dynamic linker from the host system are committed in pass 1
$ comm --check-order -2 -3 $FILE1 $FILE2
# Output should be empty
$ su - lfs
$ ld --verbose | grep SEARCH | sed -E 's#; +#\n#g'
SEARCH_DIR("=/tools/x86_64-pc-linux-gnu/lib64")
SEARCH_DIR("/tools/lib")
SEARCH_DIR("=/tools/x86_64-pc-linux-gnu/lib");
$ chown -R root:root $LFS/tools
$ find $LFS/tools/ -not \( -user root -and -group -root \)
# Output should be empty
$ find $LFS/tools/ -not -type l -perm /g+w,o+w # Make sure only the root user has write access to any file
# Output should be empty
X
# find . -exec stat -c'%u %g %A %n' {} \; | sort | less -SM +%
# find . -exec stat -c'%A %n' {} \; | sort | less -SM +%