Skip to content

Commit 16c36f8

Browse files
committed
kbuild: deb-pkg: use build ID instead of debug link for dbg package
There are two ways of managing separate debug info files: [1] The executable contains the .gnu_debuglink section, which specifies the name and the CRC of the separate debug info file. [2] The executable contains a build ID, and the corresponding debug info file is placed in the .build-id directory. We could do both, but the former, which 'make deb-pkg' currently does, results in complicated installation steps because we need to manually strip the debug sections, create debug links, and re-sign the modules. Besides, it is not working with module compression. This commit abandons the approach [1], and instead opts for [2]. Debian kernel commit de26137e2a9f ("Drop not needed extra step to add debug links") also stopped adding debug links. Signed-off-by: Masahiro Yamada <[email protected]>
1 parent 5e73758 commit 16c36f8

File tree

1 file changed

+13
-19
lines changed

1 file changed

+13
-19
lines changed

scripts/package/builddeb

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ install_linux_image () {
4949
${MAKE} -f ${srctree}/Makefile INSTALL_DTBS_PATH="${pdir}/usr/lib/linux-image-${KERNELRELEASE}" dtbs_install
5050
fi
5151

52-
${MAKE} -f ${srctree}/Makefile INSTALL_MOD_PATH="${pdir}" modules_install
52+
${MAKE} -f ${srctree}/Makefile INSTALL_MOD_PATH="${pdir}" INSTALL_MOD_STRIP=1 modules_install
5353
rm -f "${pdir}/lib/modules/${KERNELRELEASE}/build"
5454

5555
# Install the kernel
@@ -110,25 +110,21 @@ install_linux_image () {
110110

111111
install_linux_image_dbg () {
112112
pdir=$1
113-
image_pdir=$2
114113

115114
rm -rf ${pdir}
116115

117-
for module in $(find ${image_pdir}/lib/modules/ -name *.ko -printf '%P\n'); do
118-
module=lib/modules/${module}
119-
mkdir -p $(dirname ${pdir}/usr/lib/debug/${module})
120-
# only keep debug symbols in the debug file
121-
${OBJCOPY} --only-keep-debug ${image_pdir}/${module} ${pdir}/usr/lib/debug/${module}
122-
# strip original module from debug symbols
123-
${OBJCOPY} --strip-debug ${image_pdir}/${module}
124-
# then add a link to those
125-
${OBJCOPY} --add-gnu-debuglink=${pdir}/usr/lib/debug/${module} ${image_pdir}/${module}
126-
done
116+
# Parse modules.order directly because 'make modules_install' may sign,
117+
# compress modules, and then run unneeded depmod.
118+
while read -r mod; do
119+
mod="${mod%.o}.ko"
120+
dbg="${pdir}/usr/lib/debug/lib/modules/${KERNELRELEASE}/kernel/${mod}"
121+
buildid=$("${READELF}" -n "${mod}" | sed -n 's@^.*Build ID: \(..\)\(.*\)@\1/\2@p')
122+
link="${pdir}/usr/lib/debug/.build-id/${buildid}.debug"
127123

128-
# re-sign stripped modules
129-
if is_enabled CONFIG_MODULE_SIG_ALL; then
130-
${MAKE} -f ${srctree}/Makefile INSTALL_MOD_PATH="${image_pdir}" modules_sign
131-
fi
124+
mkdir -p "${dbg%/*}" "${link%/*}"
125+
"${OBJCOPY}" --only-keep-debug "${mod}" "${dbg}"
126+
ln -sf --relative "${dbg}" "${link}"
127+
done < modules.order
132128

133129
# Build debug package
134130
# Different tools want the image in different locations
@@ -176,9 +172,7 @@ for package in ${packages_enabled}
176172
do
177173
case ${package} in
178174
*-dbg)
179-
# This must be done after linux-image, that is, we expect the
180-
# debug package appears after linux-image in debian/control.
181-
install_linux_image_dbg debian/linux-image-dbg debian/linux-image;;
175+
install_linux_image_dbg debian/linux-image-dbg;;
182176
linux-image-*|user-mode-linux-*)
183177
install_linux_image debian/linux-image ${package};;
184178
linux-libc-dev)

0 commit comments

Comments
 (0)