[lfs] 01/03: glibc: Make the sanity check more complete for pass 1

"Git Owner" ([email protected] via lfs-book Mailing List) <[email protected]>
Newsgroups gmane.linux.lfs.book
Message-ID <[email protected]>
This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch trunk
in repository lfs.

commit 87e90fb63352a28de548a3eb8688b3b343733464
Author: Xi Ruoyao <[email protected]>
AuthorDate: Thu Mar 27 23:06:24 2025 +0800

    glibc: Make the sanity check more complete for pass 1
    
    Fixes #5651.
---
 chapter05/glibc.xml | 100 +++++++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 83 insertions(+), 17 deletions(-)

diff --git a/chapter05/glibc.xml b/chapter05/glibc.xml
index 2c7de998c..baec8f3a8 100644
--- a/chapter05/glibc.xml
+++ b/chapter05/glibc.xml
@@ -189,32 +189,98 @@ cd       build</userinput></screen>
 
 <screen><userinput remap="install">sed '/RTLDLIST=/s@/usr@@g' -i $LFS/usr/bin/ldd</userinput></screen>
 
-    <caution>
-      <para>At this point, it is imperative to stop and ensure that the basic
-      functions (compiling and linking) of the new toolchain are working as
-      expected. To perform a sanity check, run the following commands:</para>
+    <para>Now that our cross toolchain is in place, it is important to ensure
+    that compiling and linking will work as expected. We do this by performing
+    some sanity checks:</para>
 
-<screen><userinput>echo 'int main(){}' | $LFS_TGT-gcc -xc -
-readelf -l a.out | grep ld-linux</userinput></screen>
+<screen><userinput>echo 'int main(){}' | $LFS_TGT-gcc -x c - -v -Wl,--verbose &amp;&gt; dummy.log
+readelf -l a.out | grep ': /lib'</userinput></screen>
 
-      <para>If everything is working correctly, there should be no errors,
-      and the output of the last command will be of the form:</para>
+  <para>There should be no errors,
+  and the output of the last command will be (allowing for
+  platform-specific differences in the dynamic linker name):</para>
 
 <screen><computeroutput>[Requesting program interpreter: /lib64/ld-linux-x86-64.so.2]</computeroutput></screen>
 
-      <para>Note that for 32-bit machines, the interpreter name will be
-      <filename>/lib/ld-linux.so.2</filename>.</para>
+  <para>Note that this path should not contain
+  <filename class='directory'>/mnt/lfs</filename> (or the value of
+  the <envar>LFS</envar> variable if you used a different one).  The path is
+  resolved when the compiled program is executed, and that should only happen
+  after we enter the chroot environment where the kernel would consider
+  <filename class='directory'>$LFS</filename> as the root directory
+  (<filename class='directory'>/</filename>).</para>
 
-      <para>If the output is not as shown above, or there is no output at all,
-      then something is wrong. Investigate and retrace the steps to find out
-      where the problem is and correct it. This issue must be resolved before
-      continuing.</para>
+  <para>Now make sure that we're set up to use the correct start files:</para>
 
-      <para>Once all is well, clean up the test file:</para>
+<screen><userinput>grep -E -o "$LFS/lib.*/S?crt[1in].*succeeded" dummy.log</userinput></screen>
 
-<screen><userinput>rm -v a.out</userinput></screen>
+  <para>The output of the last command should be:</para>
 
-    </caution>
+<screen><computeroutput>/mnt/lfs/lib/../lib/Scrt1.o succeeded
+/mnt/lfs/lib/../lib/crti.o succeeded
+/mnt/lfs/lib/../lib/crtn.o succeeded</computeroutput></screen>
+
+  <para>Verify that the compiler is searching for the correct header
+  files:</para>
+
+<screen><userinput>grep -B3 "^ $LFS/usr/include" dummy.log</userinput></screen>
+
+  <para>This command should return the following output:</para>
+
+<screen><computeroutput>#include &lt;...&gt; search starts here:
+ /mnt/lfs/tools/lib/gcc/x86_64-lfs-linux-gnu/&gcc-version;/include
+ /mnt/lfs/tools/lib/gcc/x86_64-lfs-linux-gnu/&gcc-version;/include-fixed
+ /mnt/lfs/usr/include</computeroutput></screen>
+
+   <para>Again, the directory named after your target triplet may be
+   different than the above, depending on your system architecture.</para>
+
+  <para>Next, verify that the new linker is being used with the correct search paths:</para>
+
+<screen><userinput>grep 'SEARCH.*/usr/lib' dummy.log |sed 's|; |\n|g'</userinput></screen>
+
+  <para>References to paths that have components with '-linux-gnu' should
+  be ignored, but otherwise the output of the last command should be:</para>
+
+<screen><computeroutput>SEARCH_DIR("=/mnt/lfs/tools/x86_64-lfs-linux-gnu/lib64")
+SEARCH_DIR("=/usr/local/lib64")
+SEARCH_DIR("=/lib64")
+SEARCH_DIR("=/usr/lib64")
+SEARCH_DIR("=/mnt/lfs/tools/x86_64-lfs-linux-gnu/lib")
+SEARCH_DIR("=/usr/local/lib")
+SEARCH_DIR("=/lib")
+SEARCH_DIR("=/usr/lib");</computeroutput></screen>
+
+   <para>A 32-bit system may use a few other directories, but anyway
+   the important facet here is all the pathes should begin with an equal sign
+   (<literal>=</literal>), which would be replaced with the sysroot
+   directory that we've configured for the linker.</para>
+
+  <para>Next make sure that we're using the correct libc:</para>
+
+<screen><userinput>grep "/lib.*/libc.so.6 " dummy.log</userinput></screen>
+
+  <para>The output of the last command should be:</para>
+
+<screen><computeroutput>attempt to open /mnt/lfs/usr/lib/libc.so.6 succeeded</computeroutput></screen>
+
+  <para>Make sure GCC is using the correct dynamic linker:</para>
+
+<screen><userinput>grep found dummy.log</userinput></screen>
+
+  <para>The output of the last command should be (allowing for
+  platform-specific differences in dynamic linker name):</para>
+
+<screen><computeroutput>found ld-linux-x86-64.so.2 at /mnt/lfs/usr/lib/ld-linux-x86-64.so.2</computeroutput></screen>
+
+  <para>If the output does not appear as shown above or is not received
+  at all, then something is seriously wrong. Investigate and retrace the
+  steps to find out where the problem is and correct it.  Any
+  issues should be resolved before continuing with the process.</para>
+
+  <para>Once everything is working correctly, clean up the test files:</para>
+
+<screen><userinput>rm -v a.out dummy.log</userinput></screen>
 
     <note><para>Building the packages in the next chapter will serve as an
     additional check that the toolchain has been built properly. If some

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

-- 
http://lists.linuxfromscratch.org/sympa/info/lfs-book
Unsubscribe: See the above information page
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.