2004-06-13 13:58:23 +01:00
|
|
|
<?xml version="1.0" encoding="ISO-8859-1"?>
|
2007-03-21 18:42:58 +00:00
|
|
|
<!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
|
|
|
|
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
|
2005-02-19 22:16:42 +00:00
|
|
|
<!ENTITY % general-entities SYSTEM "../general.ent">
|
|
|
|
%general-entities;
|
|
|
|
]>
|
2006-02-10 19:05:30 +00:00
|
|
|
|
2021-08-12 22:03:35 +01:00
|
|
|
<sect1 id="ch-system-stripping">
|
|
|
|
<?dbhtml filename="stripping.html"?>
|
2006-02-10 19:05:30 +00:00
|
|
|
|
2021-08-12 22:03:35 +01:00
|
|
|
<title>Stripping</title>
|
2006-02-10 19:05:30 +00:00
|
|
|
|
2021-09-07 21:33:18 +01:00
|
|
|
<para>This section is optional. If the intended user is not a
|
2017-04-26 04:01:26 +01:00
|
|
|
programmer and does not plan to do
|
2022-12-20 19:57:22 +00:00
|
|
|
any debugging of the system software, the system's size can be decreased
|
|
|
|
by some 2 GB by removing the debugging symbols, and some unnecessary symbol table
|
|
|
|
entries, from binaries and libraries. This causes no real inconvenience for
|
|
|
|
a typical Linux user.</para>
|
2006-02-10 19:05:30 +00:00
|
|
|
|
2017-04-26 04:44:27 +01:00
|
|
|
<para>Most people who use the commands mentioned below do not
|
2022-12-20 19:57:22 +00:00
|
|
|
experience any difficulties. However, it is easy to make a mistake and
|
|
|
|
render the new system unusable. So before running the
|
2017-04-26 04:44:27 +01:00
|
|
|
<command>strip</command> commands, it is a good idea to make a
|
2006-02-10 19:05:30 +00:00
|
|
|
backup of the LFS system in its current state.</para>
|
|
|
|
|
2022-12-20 19:57:22 +00:00
|
|
|
<para>A <command>strip</command> command with the
|
2022-08-21 13:27:28 +01:00
|
|
|
<parameter>--strip-unneeded</parameter> option removes all debug symbols
|
2022-12-20 19:57:22 +00:00
|
|
|
from a binary or library. It also removes all symbol table entries not
|
2022-08-21 13:27:28 +01:00
|
|
|
needed by the linker (for static libraries) or dynamic linker (for
|
2022-12-20 19:57:22 +00:00
|
|
|
dynamically linked binaries and shared libraries).</para>
|
2022-08-21 13:27:28 +01:00
|
|
|
|
2022-12-20 19:57:22 +00:00
|
|
|
<para>The debugging symbols from selected libraries are preserved
|
|
|
|
in separate files. That debugging information is needed to run
|
|
|
|
regression tests with <ulink
|
2021-09-07 21:33:18 +01:00
|
|
|
url='&blfs-book;/general/valgrind.html'>valgrind</ulink> or <ulink
|
2022-12-20 19:57:22 +00:00
|
|
|
url='&blfs-book;/general/gdb.html'>gdb</ulink> later, in BLFS.
|
2017-04-26 04:01:26 +01:00
|
|
|
</para>
|
2017-04-23 04:28:50 +01:00
|
|
|
|
2021-07-27 20:11:38 +01:00
|
|
|
<para>Note that <command>strip</command> will overwrite the binary or library
|
2021-08-12 22:03:35 +01:00
|
|
|
file it is processing. This can crash the processes using code or data from
|
2022-12-20 19:57:22 +00:00
|
|
|
the file. If the process running <command>strip</command> is
|
|
|
|
affected, the binary or library being stripped can be destroyed; this can
|
|
|
|
make the system completely unusable. To avoid this problem we copy some libraries
|
2021-07-27 20:11:38 +01:00
|
|
|
and binaries into <filename class="directory">/tmp</filename>, strip them
|
2022-12-20 19:57:22 +00:00
|
|
|
there, then reinstall them with the <command>install</command> command.
|
|
|
|
(The related entry in <xref linkend="pkgmgmt-upgrade-issues"/> gives the
|
|
|
|
rationale for using the <command>install</command> command here.)</para>
|
2021-07-26 12:34:27 +01:00
|
|
|
|
2021-08-06 06:49:32 +01:00
|
|
|
<note><para>The ELF loader's name is ld-linux-x86-64.so.2 on 64-bit systems
|
2022-03-24 17:11:57 +00:00
|
|
|
and ld-linux.so.2 on 32-bit systems. The construct below selects the
|
2022-05-22 08:57:28 +01:00
|
|
|
correct name for the current architecture, excluding anything ending
|
|
|
|
with <quote>g</quote>, in case the commands below have already been
|
|
|
|
run.</para></note>
|
2021-08-04 03:58:23 +01:00
|
|
|
|
2023-02-01 12:03:12 +00:00
|
|
|
<important>
|
|
|
|
<para>
|
2023-03-31 10:01:58 +01:00
|
|
|
If there is any package whose version is different from the version
|
2023-02-01 12:03:12 +00:00
|
|
|
specified by the book (either following a security advisory or
|
|
|
|
satisfying personal preference), it may be necessary to update the
|
2023-03-31 10:01:58 +01:00
|
|
|
library file name in <envar>save_usrlib</envar> or
|
2023-02-01 12:03:12 +00:00
|
|
|
<envar>online_usrlib</envar>.
|
|
|
|
<emphasis role='bold'>Failing to do so may render the system
|
|
|
|
completely unusable.</emphasis>
|
|
|
|
</para>
|
|
|
|
</important>
|
|
|
|
|
2020-06-13 09:55:55 +01:00
|
|
|
<!-- also of interest are libgfortan, libgo, libgomp, and libobjc from GCC -->
|
2017-04-23 04:28:50 +01:00
|
|
|
|
2017-05-19 00:32:21 +01:00
|
|
|
<!--<screen><userinput>save_lib="ld-2.25.so libc-2.25.so libpthread-2.25.so libthread_db-1.0.so"-->
|
2022-05-22 08:57:28 +01:00
|
|
|
<screen><userinput>save_usrlib="$(cd /usr/lib; ls ld-linux*[^g])
|
2021-08-03 04:27:16 +01:00
|
|
|
libc.so.6
|
2021-08-03 16:58:46 +01:00
|
|
|
libthread_db.so.1
|
2021-09-07 21:33:18 +01:00
|
|
|
libquadmath.so.&libquadmath-version;
|
2021-08-03 16:58:46 +01:00
|
|
|
libstdc++.so.&libstdcpp-version;
|
2021-09-07 21:33:18 +01:00
|
|
|
libitm.so.&libitm-version;
|
|
|
|
libatomic.so.&libatomic-version;"
|
2017-04-26 04:01:26 +01:00
|
|
|
|
|
|
|
cd /usr/lib
|
|
|
|
|
|
|
|
for LIB in $save_usrlib; do
|
|
|
|
objcopy --only-keep-debug $LIB $LIB.dbg
|
2021-07-26 02:10:18 +01:00
|
|
|
cp $LIB /tmp/$LIB
|
|
|
|
strip --strip-unneeded /tmp/$LIB
|
|
|
|
objcopy --add-gnu-debuglink=$LIB.dbg /tmp/$LIB
|
|
|
|
install -vm755 /tmp/$LIB /usr/lib
|
|
|
|
rm /tmp/$LIB
|
2017-04-26 04:01:26 +01:00
|
|
|
done
|
|
|
|
|
2021-07-26 12:34:27 +01:00
|
|
|
online_usrbin="bash find strip"
|
2021-08-03 16:58:46 +01:00
|
|
|
online_usrlib="libbfd-&binutils-version;.so
|
2023-01-16 12:26:15 +00:00
|
|
|
libsframe.so.0.0.0
|
2022-01-20 06:35:07 +00:00
|
|
|
libhistory.so.&readline-soversion;
|
2021-08-03 16:58:46 +01:00
|
|
|
libncursesw.so.&ncurses-version;
|
|
|
|
libm.so.6
|
2022-01-20 06:35:07 +00:00
|
|
|
libreadline.so.&readline-soversion;
|
2021-08-03 16:58:46 +01:00
|
|
|
libz.so.&zlib-version;
|
2021-07-27 18:18:37 +01:00
|
|
|
$(cd /usr/lib; find libnss*.so* -type f)"
|
2021-07-26 12:34:27 +01:00
|
|
|
|
|
|
|
for BIN in $online_usrbin; do
|
|
|
|
cp /usr/bin/$BIN /tmp/$BIN
|
2021-07-28 10:00:25 +01:00
|
|
|
strip --strip-unneeded /tmp/$BIN
|
2021-07-26 12:34:27 +01:00
|
|
|
install -vm755 /tmp/$BIN /usr/bin
|
|
|
|
rm /tmp/$BIN
|
|
|
|
done
|
2017-04-23 04:28:50 +01:00
|
|
|
|
2021-07-26 12:34:27 +01:00
|
|
|
for LIB in $online_usrlib; do
|
|
|
|
cp /usr/lib/$LIB /tmp/$LIB
|
|
|
|
strip --strip-unneeded /tmp/$LIB
|
|
|
|
install -vm755 /tmp/$LIB /usr/lib
|
|
|
|
rm /tmp/$LIB
|
|
|
|
done
|
2018-05-07 16:45:11 +01:00
|
|
|
|
2021-07-28 10:00:25 +01:00
|
|
|
for i in $(find /usr/lib -type f -name \*.so* ! -name \*dbg) \
|
|
|
|
$(find /usr/lib -type f -name \*.a) \
|
|
|
|
$(find /usr/{bin,sbin,libexec} -type f); do
|
|
|
|
case "$online_usrbin $online_usrlib $save_usrlib" in
|
2021-09-07 21:33:18 +01:00
|
|
|
*$(basename $i)* )
|
2021-07-27 20:11:38 +01:00
|
|
|
;;
|
2021-09-07 21:33:18 +01:00
|
|
|
* ) strip --strip-unneeded $i
|
2021-07-27 20:11:38 +01:00
|
|
|
;;
|
2021-07-26 12:34:27 +01:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
unset BIN LIB save_usrlib online_usrbin online_usrlib
|
|
|
|
</userinput></screen>
|
2004-06-13 13:58:23 +01:00
|
|
|
|
2022-12-20 19:57:22 +00:00
|
|
|
<para>A large number of files will be flagged as errors because their file
|
|
|
|
format is not recognized. These warnings can be safely ignored. They
|
|
|
|
indicate that those files are scripts, not binaries.</para>
|
2017-04-23 04:28:50 +01:00
|
|
|
|
2004-06-13 13:58:23 +01:00
|
|
|
</sect1>
|