2015年1月18日 星期日

[LFS] 6.10. Adjusting the Toolchain

1. Link any newly compiled program against these new libraries.
mv -v /tools/bin/{ld,ld-old}
mv -v /tools/$(gcc -dumpmachine)/bin/{ld,ld-old}
mv -v /tools/bin/{ld-new,ld}
ln -sv /tools/bin/ld /tools/$(gcc -dumpmachine)/bin/ld


2. Adjust the specs file so that GCC knows where to find the correct headers and Glibc start files.
Verify the intended change was actually made, so create specs.
gcc -dumpspecs | sed -e 's@/tools@@g'                   \
    -e '/\*startfile_prefix_spec:/{n;s@.*@/usr/lib/ @}' \
    -e '/\*cpp:/{n;s@$@ -isystem /usr/include@}' >      \
    `dirname $(gcc --print-libgcc-file-name)`/specs


3. Checking adjusted toolchain are working as expected.
echo 'main(){}' > dummy.c
cc dummy.c -v -Wl,--verbose &> dummy.log
readelf -l a.out | grep ': /lib'


There should be no errors, and the output will like following
[Requesting program interpreter: /lib/ld-linux-armhf.so.3]


4. Make sure that we’re setup to use the correct startfiles
grep -o '/usr/lib.*/crt[1in].*succeeded' dummy.log
The output of the last command should be:
/usr/lib/crt1.o succeeded
/usr/lib/crti.o succeeded
/usr/lib/crtn.o succeeded


5. Verify that the compiler is searching for the correct header files.
grep -B1 '^ /usr/include' dummy.log
output of the last command should be:
#include <...> search starts here:
 /usr/include


6. Verify that the new linker is being used with the correct search paths
grep 'SEARCH.*/usr/lib' dummy.log |sed 's|; |\n|g'
The output of the last command should be:
SEARCH_DIR("/usr/lib")
SEARCH_DIR("/lib");


7. Make sure that we’re using the correct libc:
grep "/lib.*/libc.so.6 " dummy.log
output of the last command
attempt to open /lib/libc.so.6 succeeded


8. Make sure GCC is using the correct dynamic linker:
grep found dummy.log
utput of the last command should be
found ld-linux-armhf.so.3 at /lib/ld-linux-armhf.so.3


8. Once everything is working correctly, clean up the test files:
rm -v dummy.c a.out dummy.log


Reference:
1. 6.10. Adjusting the Toolchain

0 意見:

張貼留言