rpmbuild时为什么会出现空的debugsourcefiles.list?

错误: 空 %file 文件 /home/user/rpmbuild/BUILD/xxxx-0.1/debugsourcefiles.list

你看错误的里边有一个%file,这是使用spec文件构建时的一个命令阶段,用于列出文件以生成对应的rpm包。
我们查找rpm的宏定义,发现了一行代码%files debugsource -f debugsourcefiles.list,debugsource包要使用debugsourcefiles.list文件,而debugsourcefiles.list是空的,所以出现了相应的错误。

源码包经过构建后,除了生成spec中指定的包外,还会生成额外的debuginfo和debugsource包,noarch架构除外。

  • 那么debugsourcefiles.list文件是怎么生成的?为什么是空的?

debugsourcefiles.list是由find-debuginfo生成的。
生成的文件内容为空有以下几个原因:
1 编译的目标并未生成任何动态库和可执行文件。
2 编译时未给编译器加可调试选项,比如gcc的-g选项。
3 有些开发者在构建文件的install阶段执行了strip,剥除了调试信息。

如果不想生成额外的debuginfo和debugsource包,可以在rpmbuild命令行指定--nodebuginfo,也可以在spec文件的开头加上%define debug_package %{nil}

如果只是不想生成debugsource,还继续生成debuginfo,可以在spec文件的开头加上%define _debugsource_template %{nil}
如果不想生成debuginfo,还继续生成debugsource?别折腾了,这样做没意义。

但是如果本意是想生成的,却遇到了以上的问题,那就往下看,了解一下find-debuginfo的原理。

find-debuginfo

创建临时目录 /tmp/find-debuginfo.XXXXXX,XXXXXX为随机数。

然后在$RPM_BUILD_ROOT查找文件属性中有not stripped标志的文件,将结果写到临时目录的primary文件内。使用了下边的一段代码。
可以看到查找条件,只要文件权限中owner、group、other任意一个可执行,并且属性中有not stripped就满足要求。

touch "$temp/primary"
find "$RPM_BUILD_ROOT" ! -path "${debugdir}/*.debug" -type f \
                     \( -perm -0100 -or -perm -0010 -or -perm -0001 \) \
                     -print | LC_ALL=C sort |
file -N -f - | sed -n -e 's/^\(.*\):[   ]*.*ELF.*, not stripped.*/\1/p' |
xargs --no-run-if-empty stat -c '%h %D_%i %n' |
while read nlinks inum f; do
  if [ $nlinks -gt 1 ]; then
    var=seen_$inum
    if test -n "${!var}"; then
      echo "$inum $f" >>"$temp/linked"
      continue
    else
      read "$var" < <(echo 1)
    fi
  fi
  echo "$nlinks $inum $f" >>"$temp/primary"
done

对所有写入primary的文件,逐个进行处理,这里使用了多线程,脚本中每个线程是一个run_job函数,ran_job其本质执行的是do_file函数。
比如使用了8个线程,线程0是run_job0,run_job0将自己处理过的文件写入elfbins.0,将提取的信息写入debugsources.0,将处理结果写入res.0。

然后再将多个线程处理产生的多个elfbins和debugsources文件进行合并,顾名思义,debugsources里边记录着调试源文件的名称和类型。

debugsourcefiles.list debugsource包的列表文件。记录所有调试源文件(就是代码文件)将要被安装到系统的路径,一般是/usr/src/debug/%{packagename}-%{version}-%{release}.%{dist}.%{arch}
debugfiles.list debuginfo包的列表文件。记录所有的调试文件将要被安装的路径,就是未被stripped的文件,每个文件一条记录。
debuglinks.list
debugsources.list 记录所有调试用源代码文件的名称和类型。源代码文件的调试类型可以是<internal><built-in><__thread_local_inner macros>等。
elfbins.list 记录所有的可调试的可执行程序,不包括动态库,每个文件一条记录。

我们再来看看run_job线程内都做了些什么?

run_job线程内调用了do_file函数,do_file函数使用了debugedit命令对单个文件进行调试信息处理。

posted on 2023-02-17 15:55  ddev  阅读(1286)  评论(0编辑  收藏  举报