PacktPublishing / Mastering-Embedded-Linux-Programming-Third-Edition

Mastering Embedded Linux Programming Third Edition, published by Packt
MIT License
532 stars 151 forks source link

Chapter 5 - "Libraries for the root filesystem" missing files #70

Closed Xylopyrographer closed 5 months ago

Xylopyrographer commented 6 months ago

I’m at a bit of an impasse in Chapter 5, Libraries for the root filesystem starting on page 132 (MELP third edition).

Mirroring what is in the book, running these commands and the returned results are:

$ cd ~/rootfs

$ arm-cortex_a8-linux-gnueabihf-readelf -a bin/busybox | grep "program interpreter"
[Requesting program interpreter: /lib/ld-linux-armhf.so.3]

$ arm-cortex_a8-linux-gnueabihf-readelf -a bin/busybox | grep "Shared library"
0x00000001 (NEEDED)                     Shared library: [libm.so.6]
0x00000001 (NEEDED)                     Shared library: [libresolv.so.2]
0x00000001 (NEEDED)                     Shared library: [libc.so.6]

First problem; I get three hits on (NEEDED) libraries where the book only shows two.

Now, at the top of page 133, after creating the shell variable, which in my case resolves to:

$ echo $SYSROOT
/home/xylo/x-tools/arm-cortex_a8-linux-gnueabihf/arm-cortex_a8-linux-gnueabihf/sysroot

And doing

$ ls -l lib/ld-linux-armhf.so.3
-rwxr-xr-x 1 xylo xylo 1178040 Feb 20 12:54 lib/ld-linux-armhf.so.3

Which is an issue as lib/ld-linux-armhf.so.3 is not a symbolic link.

Repeating for libc.so.6 and libm.so.6 I get:

$ ls -l lib/libm.so.6                             
-rwxr-xr-x 1 xylo xylo 1395800 Feb 20 12:54 lib/libm.so.6
$ ls -l lib/libc.so.6 
-rwxr-xr-x 1 xylo xylo 12001768 Feb 20 12:54 lib/libc.so.6

Which are also not symbolic links, but files.

Long way of saying that when copying the libraries and symlinks to the appropriate places, it fails as no links exist to be copied, as shown for example.

$ cp -a $SYSROOT/lib/ld-2.22.so lib
cp: cannot stat '/home/xylo/x-tools/arm-cortex_a8-linux-gnueabihf/arm-cortex_a8-linux-gnueabihf/sysroot/lib/ld-2.22.so': No such file or directory

Which is where I’m stuck as the balance of the Chapter assumes we're working with the *2.22.so files. As well, what to do about the third (NEEDED) library?

Suggestions to resolve would be very appreciated.

FWIW, rolling back to Chapter 2, page 28; I created the arm-cortex_a8-linux-gnueabihf cross compiler as per the instructions, but also in Operating System | Version of linux, changed that to 5.4.248 before doing $ bin/ct-ng build. I had earlier built the cross compile with the default for the linux version (6.something), but the result was the same.

Must say that the book is well done 👍!

Xylopyrographer commented 5 months ago

Posting here the response from the authors. Many thanks!

"It's likely that the glibc build artifacts of the crosstool-NG toolchain have changed since these Chapter 5 exercises were last executed.

libresolv.so.2 is a new dependency that should be cherry-picked along with libm.so.6 and libc.so.6 for busybox to run. If it is a file rather than a symbolic link then you can copy it from sysroot like so:

$ cp -a $SYSROOT/lib/libresolv.so.2 lib

It should be okay that ld-linux-armhf.so.3, libm.so.6, and libc.so.6 are now files instead of symbolic links. That just means you don't need to copy the ld-2.22.so, libm-2.22.so, and libc-2.22.so target files because they no longer exist.

This is all good feedback as I'm sure these inconsistencies have frustrated other readers. I will make sure to add them to the book's errata when I find time."