source: chapter08/stripping.xml@ 942e81de

11.2 11.2-rc1 11.3 11.3-rc1 12.0 12.0-rc1 12.1 12.1-rc1 bdubbs/gcc13 multilib renodr/libudev-from-systemd trunk xry111/arm64 xry111/arm64-12.0 xry111/clfs-ng xry111/loongarch xry111/loongarch-12.0 xry111/loongarch-12.1 xry111/mips64el xry111/pip3 xry111/rust-wip-20221008 xry111/update-glibc
Last change on this file since 942e81de was 942e81de, checked in by Xi Ruoyao <xry111@…>, 20 months ago

stripping: also mention symbol table bisides debug symbols

  • Property mode set to 100644
File size: 4.6 KB
RevLine 
[3c928f1]1<?xml version="1.0" encoding="ISO-8859-1"?>
[b06ca36]2<!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
3 "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
[81fd230]4 <!ENTITY % general-entities SYSTEM "../general.ent">
5 %general-entities;
6]>
[ddd5542]7
[8a269ec]8<sect1 id="ch-system-stripping">
9 <?dbhtml filename="stripping.html"?>
[ddd5542]10
[8a269ec]11 <title>Stripping</title>
[ddd5542]12
[d672ab7]13 <para>This section is optional. If the intended user is not a
[c32384e]14 programmer and does not plan to do
[ddd5542]15 any debugging on the system software, the system size can be decreased
[942e81de]16 by about 2 GB by removing the debugging symbols and unneeded symbol table
17 entries from binaries and libraries. This causes no inconvenience other
18 than not being able to debug the software fully anymore.</para>
[ddd5542]19
[826bbcc]20 <para>Most people who use the commands mentioned below do not
[ddd5542]21 experience any difficulties. However, it is easy to make a typo and
22 render the new system unusable, so before running the
[826bbcc]23 <command>strip</command> commands, it is a good idea to make a
[ddd5542]24 backup of the LFS system in its current state.</para>
25
[942e81de]26 <para>A <command>strip</command> command with
27 <parameter>--strip-unneeded</parameter> option removes all debug symbols
28 from a binary or library. And, it removes all symbol table entries not
29 needed by the linker (for static libraries) or dynamic linker (for
30 dynamic-linked binaries and shared libraries).</para>
31
[de28837]32 <para>The debugging symbols for selected libraries are placed
[d672ab7]33 in separate files. This debugging information is needed if running
34 regression tests that use <ulink
35 url='&blfs-book;/general/valgrind.html'>valgrind</ulink> or <ulink
[826bbcc]36 url='&blfs-book;/general/gdb.html'>gdb</ulink> later in BLFS.
[c32384e]37 </para>
[6c8a79a]38
[11d5dee]39 <para>Note that <command>strip</command> will overwrite the binary or library
[8a269ec]40 file it is processing. This can crash the processes using code or data from
[11d5dee]41 the file. If the process running <command>strip</command> itself is
[8a269ec]42 affected, the binary or library being stripped can be destroyed and can
[11d5dee]43 make the system completely unusable. To avoid it, we'll copy some libraries
44 and binaries into <filename class="directory">/tmp</filename>, strip them
[de28837]45 there, and install them back with the <command>install</command> command.
46 Read the related entry in <xref linkend="pkgmgmt-upgrade-issues"/> for the
47 rationale to use the <command>install</command> command here.</para>
48
[a3d6232]49 <note><para>The ELF loader's name is ld-linux-x86-64.so.2 on 64-bit systems
[bcb20b4]50 and ld-linux.so.2 on 32-bit systems. The construct below selects the
[8731bd1]51 correct name for the current architecture, excluding anything ending
52 with <quote>g</quote>, in case the commands below have already been
53 run.</para></note>
[4350669]54
[77d2cd8d]55<!-- also of interest are libgfortan, libgo, libgomp, and libobjc from GCC -->
[6c8a79a]56
[00abb8f]57<!--<screen><userinput>save_lib="ld-2.25.so libc-2.25.so libpthread-2.25.so libthread_db-1.0.so"-->
[8731bd1]58<screen><userinput>save_usrlib="$(cd /usr/lib; ls ld-linux*[^g])
[adcaf07e]59 libc.so.6
[6094dae]60 libthread_db.so.1
[d672ab7]61 libquadmath.so.&libquadmath-version;
[6094dae]62 libstdc++.so.&libstdcpp-version;
[d672ab7]63 libitm.so.&libitm-version;
64 libatomic.so.&libatomic-version;"
[c32384e]65
66cd /usr/lib
67
68for LIB in $save_usrlib; do
69 objcopy --only-keep-debug $LIB $LIB.dbg
[ff96923]70 cp $LIB /tmp/$LIB
71 strip --strip-unneeded /tmp/$LIB
72 objcopy --add-gnu-debuglink=$LIB.dbg /tmp/$LIB
73 install -vm755 /tmp/$LIB /usr/lib
74 rm /tmp/$LIB
[c32384e]75done
76
[de28837]77online_usrbin="bash find strip"
[6094dae]78online_usrlib="libbfd-&binutils-version;.so
[b83366b]79 libhistory.so.&readline-soversion;
[6094dae]80 libncursesw.so.&ncurses-version;
81 libm.so.6
[b83366b]82 libreadline.so.&readline-soversion;
[6094dae]83 libz.so.&zlib-version;
[d1592b9]84 $(cd /usr/lib; find libnss*.so* -type f)"
[de28837]85
86for BIN in $online_usrbin; do
87 cp /usr/bin/$BIN /tmp/$BIN
[08f72423]88 strip --strip-unneeded /tmp/$BIN
[de28837]89 install -vm755 /tmp/$BIN /usr/bin
90 rm /tmp/$BIN
91done
[6c8a79a]92
[de28837]93for LIB in $online_usrlib; do
94 cp /usr/lib/$LIB /tmp/$LIB
95 strip --strip-unneeded /tmp/$LIB
96 install -vm755 /tmp/$LIB /usr/lib
97 rm /tmp/$LIB
98done
[658dcab]99
[08f72423]100for i in $(find /usr/lib -type f -name \*.so* ! -name \*dbg) \
101 $(find /usr/lib -type f -name \*.a) \
102 $(find /usr/{bin,sbin,libexec} -type f); do
103 case "$online_usrbin $online_usrlib $save_usrlib" in
[d672ab7]104 *$(basename $i)* )
[11d5dee]105 ;;
[d672ab7]106 * ) strip --strip-unneeded $i
[11d5dee]107 ;;
[de28837]108 esac
109done
110
111unset BIN LIB save_usrlib online_usrbin online_usrlib
112</userinput></screen>
[3c928f1]113
[ddd5542]114 <para>A large number of files will be reported as having their file
[8a269ec]115 format not recognized. These warnings can be safely ignored. They
116 indicate that those files are scripts instead of binaries.</para>
[6c8a79a]117
[3c928f1]118</sect1>
Note: See TracBrowser for help on using the repository browser.