[Unstable,5/6] UBUNTU: [Debian]: dkms-build: new parameter for debug package directory
diff mbox series

Message ID 20190828122604.6829-6-mfo@canonical.com
State New
Headers show
Series
  • Add support for ZFS debug symbols
Related show

Commit Message

Mauricio Faria de Oliveira Aug. 28, 2019, 12:26 p.m. UTC
BugLink: https://bugs.launchpad.net/bugs/1840704

Provide the 'dkms-build' script an argument that specifies
the path for installing modules built with debug symbols,
and update callers (currently just 'build_dkms' function)
and post-processor scripts for consistency (nvidia, vbox).

This is similar to the currently used package directory
argument 'pkgdir/lib/modules/abi-release/kernel', where
modules are installed anyway regardless of debug symbols.

The proposal is that the 'dkms-build' script, if provided
such argument, should handle the generation and stripping
of debug symbols, and installing the non-stripped modules
into the debug package directory and the stripped modules
into the other package directory (which is used currently).

The script double checks whether debug symbols are indeed
present in the module file (via the '.debug_info' section)
to avoid non-debug modules in the debug package directory,
with an additional benefit of backwards compatibility and
gracefully handling DKMS packages that do not yet support
building debug symbols (or that failed to for some reason).

The script should not handle the '.gnu_debuglink' section
to reference the non-stripped modules in stripped modules
(and re-signinig afterward), as this is now done in rules
after the DKMS modules have been built and installed.

This currently does nothing as no DKMS modules are built
with debug symbols (so this keeps the new argument empty).

This will allow for some of the DKMS-built modules to be
shipped with debug symbols to aid with debug and support.

Signed-off-by: Mauricio Faria de Oliveira <mfo@canonical.com>
---
 debian/rules.d/2-binary-arch.mk             | 10 +++---
 debian/scripts/dkms-build                   | 34 +++++++++++++++++++--
 debian/scripts/dkms-build--nvidia-N         |  5 +--
 debian/scripts/dkms-build--virtualbox-guest |  5 +--
 4 files changed, 43 insertions(+), 11 deletions(-)

Patch
diff mbox series

diff --git a/debian/rules.d/2-binary-arch.mk b/debian/rules.d/2-binary-arch.mk
index 9c991b49e868..90396689de2d 100644
--- a/debian/rules.d/2-binary-arch.mk
+++ b/debian/rules.d/2-binary-arch.mk
@@ -60,7 +60,7 @@  define build_dkms_sign =
 	)
 endef
 define build_dkms =
-	$(SHELL) $(DROOT)/scripts/dkms-build $(dkms_dir) $(abi_release)-$* '$(call build_dkms_sign,$(builddir)/build-$*)' $(1) $(2) $(3) $(4)
+	CROSS_COMPILE=$(CROSS_COMPILE) $(SHELL) $(DROOT)/scripts/dkms-build $(dkms_dir) $(abi_release)-$* '$(call build_dkms_sign,$(builddir)/build-$*)' $(1) $(2) $(3) $(4) $(5)
 endef
 
 define install_control =
@@ -390,15 +390,15 @@  endif
 	install -d $(dkms_dir) $(dkms_dir)/headers $(dkms_dir)/build $(dkms_dir)/source
 	cp -rp "$(hdrdir)" "$(indep_hdrdir)" "$(dkms_dir)/headers"
 
-	$(if $(filter true,$(enable_zfs)),$(call build_dkms, $(mods_pkg_name)-$*, $(pkgdir)/lib/modules/$(abi_release)-$*/kernel, zfs, pool/universe/z/zfs-linux/zfs-dkms_$(dkms_zfs_linux_version)_all.deb))
+	$(if $(filter true,$(enable_zfs)),$(call build_dkms, $(mods_pkg_name)-$*, $(pkgdir)/lib/modules/$(abi_release)-$*/kernel, "", zfs, pool/universe/z/zfs-linux/zfs-dkms_$(dkms_zfs_linux_version)_all.deb))
 
 ifeq ($(do_dkms_nvidia),true)
-	$(call build_dkms, $(bldinfo_pkg_name)-$*, $(pkgdir_bldinfo)/usr/lib/linux/$(abi_release)-$*/signatures, nvidia-390, pool/restricted/n/nvidia-graphics-drivers-390/nvidia-kernel-source-390_$(dkms_nvidia_390_version)_$(arch).deb pool/restricted/n/nvidia-graphics-drivers-390/nvidia-dkms-390_$(dkms_nvidia_390_version)_$(arch).deb)
-	$(call build_dkms, $(bldinfo_pkg_name)-$*, $(pkgdir_bldinfo)/usr/lib/linux/$(abi_release)-$*/signatures, nvidia-430, pool/restricted/n/nvidia-graphics-drivers-430/nvidia-kernel-source-430_$(dkms_nvidia_430_version)_$(arch).deb pool/restricted/n/nvidia-graphics-drivers-430/nvidia-dkms-430_$(dkms_nvidia_430_version)_$(arch).deb)
+	$(call build_dkms, $(bldinfo_pkg_name)-$*, $(pkgdir_bldinfo)/usr/lib/linux/$(abi_release)-$*/signatures, "", nvidia-390, pool/restricted/n/nvidia-graphics-drivers-390/nvidia-kernel-source-390_$(dkms_nvidia_390_version)_$(arch).deb pool/restricted/n/nvidia-graphics-drivers-390/nvidia-dkms-390_$(dkms_nvidia_390_version)_$(arch).deb)
+	$(call build_dkms, $(bldinfo_pkg_name)-$*, $(pkgdir_bldinfo)/usr/lib/linux/$(abi_release)-$*/signatures, "", nvidia-430, pool/restricted/n/nvidia-graphics-drivers-430/nvidia-kernel-source-430_$(dkms_nvidia_430_version)_$(arch).deb pool/restricted/n/nvidia-graphics-drivers-430/nvidia-dkms-430_$(dkms_nvidia_430_version)_$(arch).deb)
 endif
 
 ifeq ($(do_extras_package),true)
-	$(if $(filter true,$(do_dkms_vbox)),$(call build_dkms, $(mods_pkg_name)-$*, $(pkgdir_ex)/lib/modules/$(abi_release)-$*/kernel, virtualbox-guest, http://archive.ubuntu.com/ubuntu/pool/multiverse/v/virtualbox/virtualbox-guest-dkms_$(dkms_vbox_guest_version)_all.deb))
+	$(if $(filter true,$(do_dkms_vbox)),$(call build_dkms, $(mods_pkg_name)-$*, $(pkgdir_ex)/lib/modules/$(abi_release)-$*/kernel, "", virtualbox-guest, http://archive.ubuntu.com/ubuntu/pool/multiverse/v/virtualbox/virtualbox-guest-dkms_$(dkms_vbox_guest_version)_all.deb))
 endif
 
 ifneq ($(skipdbg),true)
diff --git a/debian/scripts/dkms-build b/debian/scripts/dkms-build
index 7264852d3133..f77063f7b745 100755
--- a/debian/scripts/dkms-build
+++ b/debian/scripts/dkms-build
@@ -6,8 +6,9 @@  abi_flavour="$2"
 sign="$3"
 pkgname="$4"
 pkgdir="$5"
-package="$6"
-shift 6
+dbgpkgdir="$6"
+package="$7"
+shift 7
 
 srcdir=$(pwd)
 cd "$dkms_dir" || exit 1
@@ -134,6 +135,34 @@  sed -e "s@$dkms_dir@<<DKMSDIR>>@g" <"$log"
 # If this build failed then exit here.
 [ "$rc" != 0 ] && exit "$rc"
 
+# Install the modules with debug symbols we possibly built,
+# and strip the original modules for the next install step.
+if [ -n "$dbgpkgdir" ]; then
+	dbgpkgdir="$dbgpkgdir/$package"
+	echo "II: dkms-build installing $package into $dbgpkgdir (debug symbols)"
+	install -d "$dbgpkgdir"
+	find "$dkms_dir/build/$dkms_package/$dkms_version/$abi_version" -name \*.ko |
+	while read module; do
+		vmodule=$( basename "$module" )
+
+		# Check for '.debug_info' section in order to copy module.
+		# Useful if debug symbols are requested but not built for
+		# any reason (including not yet supported by DKMS package).
+		# Strip module just in case even if section isn't present.
+		if ${CROSS_COMPILE}objdump -h -j '.debug_info' "$module" >/dev/null 2>&1
+		then
+			echo "copying $vmodule"
+			cp "$module" "$dbgpkgdir"
+		else
+			echo "ignoring $vmodule (missing debug symbols)"
+		fi
+
+		# Just 'strip -g' as '/usr/sbin/dkms' does.
+		echo "stripping $vmodule"
+		strip -g "$module"
+	done
+fi
+
 # Install and optionally sign the modules we have built.
 pkgdir="$pkgdir/$package"
 echo "II: dkms-build installing $package into $pkgdir"
@@ -180,6 +209,7 @@  do
 		"$sign" \
 		"$pkgname" \
 		"$pkgdir" \
+		"$dbgpkgdir" \
 		"$package" \
 		"$@" || exit 1
 	break
diff --git a/debian/scripts/dkms-build--nvidia-N b/debian/scripts/dkms-build--nvidia-N
index 72673e0ba7d8..bdec78233b43 100755
--- a/debian/scripts/dkms-build--nvidia-N
+++ b/debian/scripts/dkms-build--nvidia-N
@@ -10,8 +10,9 @@  abi_flavour="$2"
 sign="$3"
 pkgname="$4"
 pkgdir="$5"
-package="$6"
-shift 6
+dbgpkgdir="$6"
+package="$7"
+shift 7
 
 build="$( dirname "$objects" )/build"
 
diff --git a/debian/scripts/dkms-build--virtualbox-guest b/debian/scripts/dkms-build--virtualbox-guest
index 29b5a1686bd1..dd981b83e77e 100644
--- a/debian/scripts/dkms-build--virtualbox-guest
+++ b/debian/scripts/dkms-build--virtualbox-guest
@@ -10,8 +10,9 @@  abi_flavour="$2"
 sign="$3"
 pkgname="$4"
 pkgdir="$5"
-package="$6"
-shift 6
+dbgpkgdir="$6"
+package="$7"
+shift 7
 
 # We want to ship the vboxvideo.ko from the upstream staging tree, so
 # remove the one built via dkms.