LFS: Building LFS: Difference between revisions
Appearance
No edit summary |
No edit summary |
||
| Line 3: | Line 3: | ||
== Troubleshooting == | == Troubleshooting == | ||
* Kalo ada error, coba mount ulang seperti di [[LFS: Virtual Kernel File Systems]] | * Kalo ada error, coba mount ulang seperti di [[LFS: Virtual Kernel File Systems]] | ||
== Debug Symbol & Stripping == | |||
Secara default, hampir semua program dan library di Linux From Scratch (LFS) akan dikompilasi dengan debugging symbols (-g). Ini berguna untuk proses debugging karena debugger seperti gdb bisa menampilkan nama fungsi dan variabel, bukan sekadar alamat memori. | |||
Namun, debugging symbols ini membuat ukuran file biner menjadi jauh lebih besar. Berikut contoh perbandingan ukuran: | |||
{| class="wikitable" style="margin:auto" | |||
! Binary !! Dengan Debug Symbols !! Tanpa Debug Symbols !! Penghematan | |||
|- | |||
| Bash || 1200 KB || 480 KB || ~60% | |||
|- | |||
| Glibc dan GCC (/lib dan /usr/lib) || 87 MB || 16 MB || ~82% | |||
|} | |||
Karena sebagian besar pengguna tidak membutuhkan fitur debugging di sistem operasi hasil build, kita bisa strip simbol-simbol ini untuk menghemat ruang disk. | |||
<syntaxhighlight lang=bash> | |||
save_usrlib="$(cd /usr/lib; ls ld-linux*[^g]) | |||
libc.so.6 | |||
libthread_db.so.1 | |||
libquadmath.so.0.0.0 | |||
libstdc++.so.6.0.33 | |||
libitm.so.1.0.0 | |||
libatomic.so.1.2.0" | |||
cd /usr/lib | |||
for LIB in $save_usrlib; do | |||
objcopy --only-keep-debug --compress-debug-sections=zlib $LIB $LIB.dbg | |||
cp $LIB /tmp/$LIB | |||
strip --strip-debug /tmp/$LIB | |||
objcopy --add-gnu-debuglink=$LIB.dbg /tmp/$LIB | |||
install -vm755 /tmp/$LIB /usr/lib | |||
rm /tmp/$LIB | |||
done | |||
online_usrbin="bash find strip" | |||
online_usrlib="libbfd-2.44.so | |||
libsframe.so.1.0.0 | |||
libhistory.so.8.2 | |||
libncursesw.so.6.5 | |||
libm.so.6 | |||
libreadline.so.8.2 | |||
libz.so.1.3.1 | |||
libzstd.so.1.5.7 | |||
$(cd /usr/lib; find libnss*.so* -type f)" | |||
for BIN in $online_usrbin; do | |||
cp /usr/bin/$BIN /tmp/$BIN | |||
strip --strip-debug /tmp/$BIN | |||
install -vm755 /tmp/$BIN /usr/bin | |||
rm /tmp/$BIN | |||
done | |||
for LIB in $online_usrlib; do | |||
cp /usr/lib/$LIB /tmp/$LIB | |||
strip --strip-debug /tmp/$LIB | |||
install -vm755 /tmp/$LIB /usr/lib | |||
rm /tmp/$LIB | |||
done | |||
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 | |||
*$(basename $i)* ) | |||
;; | |||
* ) strip --strip-debug $i | |||
;; | |||
esac | |||
done | |||
unset BIN LIB save_usrlib online_usrbin online_usrlib | |||
</syntaxhighlight> | |||
Revision as of 06:46, 18 April 2025
https://www.linuxfromscratch.org/lfs/view/development/chapter08/introduction.html
Troubleshooting
- Kalo ada error, coba mount ulang seperti di LFS: Virtual Kernel File Systems
Debug Symbol & Stripping
Secara default, hampir semua program dan library di Linux From Scratch (LFS) akan dikompilasi dengan debugging symbols (-g). Ini berguna untuk proses debugging karena debugger seperti gdb bisa menampilkan nama fungsi dan variabel, bukan sekadar alamat memori.
Namun, debugging symbols ini membuat ukuran file biner menjadi jauh lebih besar. Berikut contoh perbandingan ukuran:
| Binary | Dengan Debug Symbols | Tanpa Debug Symbols | Penghematan |
|---|---|---|---|
| Bash | 1200 KB | 480 KB | ~60% |
| Glibc dan GCC (/lib dan /usr/lib) | 87 MB | 16 MB | ~82% |
Karena sebagian besar pengguna tidak membutuhkan fitur debugging di sistem operasi hasil build, kita bisa strip simbol-simbol ini untuk menghemat ruang disk.
save_usrlib="$(cd /usr/lib; ls ld-linux*[^g])
libc.so.6
libthread_db.so.1
libquadmath.so.0.0.0
libstdc++.so.6.0.33
libitm.so.1.0.0
libatomic.so.1.2.0"
cd /usr/lib
for LIB in $save_usrlib; do
objcopy --only-keep-debug --compress-debug-sections=zlib $LIB $LIB.dbg
cp $LIB /tmp/$LIB
strip --strip-debug /tmp/$LIB
objcopy --add-gnu-debuglink=$LIB.dbg /tmp/$LIB
install -vm755 /tmp/$LIB /usr/lib
rm /tmp/$LIB
done
online_usrbin="bash find strip"
online_usrlib="libbfd-2.44.so
libsframe.so.1.0.0
libhistory.so.8.2
libncursesw.so.6.5
libm.so.6
libreadline.so.8.2
libz.so.1.3.1
libzstd.so.1.5.7
$(cd /usr/lib; find libnss*.so* -type f)"
for BIN in $online_usrbin; do
cp /usr/bin/$BIN /tmp/$BIN
strip --strip-debug /tmp/$BIN
install -vm755 /tmp/$BIN /usr/bin
rm /tmp/$BIN
done
for LIB in $online_usrlib; do
cp /usr/lib/$LIB /tmp/$LIB
strip --strip-debug /tmp/$LIB
install -vm755 /tmp/$LIB /usr/lib
rm /tmp/$LIB
done
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
*$(basename $i)* )
;;
* ) strip --strip-debug $i
;;
esac
done
unset BIN LIB save_usrlib online_usrbin online_usrlib