rpmbuild 将二进制文件 strip,文件 md5 发生改变
-
上一篇中提到 strip 相关的操作,会去掉文件中的调试信息【strip 、objdump、objcopy 差异与区别】
-
在编译或打包环境中,莫名其妙的文件 大小 md5 都发生了改变,怀疑跟 rpmbuild 打包有关
用 file 命令,原文件与打包后解压文件对比下
源文件
ice-x86.ko.xz: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), BuildID[sha1]=ca1f40033e8b3ce779deb4604897f67aea62f459, with debug_info, not stripped
打包后文件
ice.ko.xz: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), BuildID[sha1]=ca1f40033e8b3ce779deb4604897f67aea62f459, not stripped
发现丢失了 debug_info,这是因为 rpmbuild 打包时一般会把 debug 信息提取出来,然后单独放入到一个 xxx.debuginfo.rpm,看一下当前环境中宏定义
# rpm --showrc |grep "strip"
-13: __brp_strip /usr/lib/rpm/brp-strip %{__strip}
-13: __brp_strip_comment_note /usr/lib/rpm/brp-strip-comment-note %{__strip} %{__objdump}
-13: __brp_strip_static_archive /usr/lib/rpm/brp-strip-static-archive %{__strip}
%{?__brp_strip}
%{?__brp_strip_comment_note}
%{?__brp_strip_static_archive}
-13: __strip /usr/bin/strip
pip%{python2_version} install -I dist/%{1} --root %{buildroot} --strip-file-prefix %{buildroot} --no-deps
pip install -I dist/%{1} --root %{buildroot} --strip-file-prefix %{buildroot} --no-deps
看下 __brp_strip 宏内容
# cat /usr/lib/rpm/brp-strip
#!/bin/sh
# If using normal root, avoid changing anything.
if [ -z "$RPM_BUILD_ROOT" ] || [ "$RPM_BUILD_ROOT" = "/" ]; then
exit 0
fi
STRIP=${1:-strip}
NCPUS=${RPM_BUILD_NCPUS:-1}
case `uname -a` in
Darwin*) exit 0 ;;
*) ;;
esac
# Strip ELF binaries
find "$RPM_BUILD_ROOT" -type f \! -regex "${RPM_BUILD_ROOT}/*usr/lib/debug.*" \! -name "*.ko" -print0 | \
xargs -0 -r -P$NCPUS -n32 sh -c "file \"\$@\" | sed -n -e 's/^\(.*\):[ ]*ELF.*, not stripped.*/\1/p' | xargs -I\{\} $STRIP -g \{\}" ARG0
$STRIP -g
说明去除了二进制文件的调试信息, ${1:-strip}
是给 STRIP 进行赋值,代表 $1 参数是否存在,如果不存在则使用 :-
后面的 strip