當(dāng)前位置:首頁 > IT技術(shù) > 系統(tǒng)服務(wù) > 正文

Linux From Scratch(LFS11.0)構(gòu)建 LFS 系統(tǒng) - 移除調(diào)試符號
2021-10-11 14:56:56

大多數(shù)使用以下命令的用戶不會(huì)遇到什么困難。但是,如果打錯(cuò)了命令,很容易導(dǎo)致新系統(tǒng)無法使用,因此在運(yùn)行 strip 命令前,最好備份 LFS 系統(tǒng)的當(dāng)前狀態(tài)。

一些庫的調(diào)試符號需要保存在單獨(dú)的文件中。之后在 BLFS 中,如果使用 valgrind 或 gdb 運(yùn)行退化測試,則需要這些調(diào)試信息的存在。

需要注意的是,strip 命令會(huì)覆蓋它正在處理的二進(jìn)制程序或庫文件。這可能導(dǎo)致正在使用該文件中代碼或數(shù)據(jù)的進(jìn)程崩潰。如果運(yùn)行 strip 本身的進(jìn)程受到影響,則可能導(dǎo)致正在被處理的程序或庫完全損壞。這可能導(dǎo)致系統(tǒng)完全不可用。為了避免這種情況,將一些庫和程序復(fù)制到 /tmp 中,在那里移除調(diào)試符號,再使用 install 命令將它們安裝回原位置。

save_usrlib="$(cd /usr/lib; ls ld-linux*)
libc.so.6
libthread_db.so.1
libquadmath.so.0.0.0
libstdc++.so.6.0.29
libitm.so.1.0.0
libatomic.so.1.2.0"

cd /usr/lib

for LIB in $save_usrlib; do
objcopy --only-keep-debug $LIB $LIB.dbg
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
done

online_usrbin="bash find strip"
online_usrlib="libbfd-2.37.so
libhistory.so.8.1
libncursesw.so.6.2
libm.so.6
libreadline.so.8.1
libz.so.1.2.11
$(cd /usr/lib; find libnss*.so* -type f)"

for BIN in $online_usrbin; do
cp /usr/bin/$BIN /tmp/$BIN
strip --strip-unneeded /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-unneeded /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-unneeded $i
;;
esac
done

unset BIN LIB save_usrlib online_usrbin online_usrlib


這里會(huì)有很多文件被報(bào)告為格式無法識別。這些警告可以安全地忽略。它們表明那些文件是腳本文件,而不是二進(jìn)制文件。



本次分享到此結(jié)束啦~

技術(shù)交流可以 關(guān)注公眾號:Lucifer三思而后行?

本文摘自 :https://blog.51cto.com/l

開通會(huì)員,享受整站包年服務(wù)立即開通 >