summary refs log tree commit diff
path: root/pkgs/os-specific/linux/kernel/manual-config.nix
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2023-03-17 18:44:06 +0000
committerAlyssa Ross <hi@alyssa.is>2023-03-20 00:09:52 +0000
commitd57568fcad7e3a9364850cb1c25d7a34693c02d5 (patch)
tree395b65c99853af7301f64efaac61e5c6185df682 /pkgs/os-specific/linux/kernel/manual-config.nix
parent41f788b1217b05d8661ebb77bfc9d9f3f65b5dd2 (diff)
downloadnixpkgs-d57568fcad7e3a9364850cb1c25d7a34693c02d5.tar
nixpkgs-d57568fcad7e3a9364850cb1c25d7a34693c02d5.tar.gz
nixpkgs-d57568fcad7e3a9364850cb1c25d7a34693c02d5.tar.bz2
nixpkgs-d57568fcad7e3a9364850cb1c25d7a34693c02d5.tar.lz
nixpkgs-d57568fcad7e3a9364850cb1c25d7a34693c02d5.tar.xz
nixpkgs-d57568fcad7e3a9364850cb1c25d7a34693c02d5.tar.zst
nixpkgs-d57568fcad7e3a9364850cb1c25d7a34693c02d5.zip
linuxManualConfig: install GDB scripts
These are required to debug kernel modules.  Since we're now able to
do that, there's another reason besides BTF to enable DEBUG_INFO, so
I've done that for pre-BTF kernel modules as well here.

For GDB to get configured correctly, vmlinux-gdb.py has to be two
directories up from scripts/gdb, and vmlinux has to be next to
vmlinux-gdb.py.  The least invasive way to satisfy these constraints
is to make vmlinux a symlink, which GDB will resolve before looking
for vmlinux-gdb.py.

Tested both ways of getting the scripts into GDB that I know of:

gdb /nix/store/7n77ijlxkxr6d613h02lr707kvjx6j1k-linux-6.1.19-dev/vmlinux \
    -iex 'add-auto-load-safe-path /nix/store/7n77ijlxkxr6d613h02lr707kvjx6j1k-linux-6.1.19-dev/lib/modules/6.1.19/build/vmlinux-gdb.py' \
    -ex 'lx-version' \
    -ex 'q'
gdb /nix/store/7n77ijlxkxr6d613h02lr707kvjx6j1k-linux-6.1.19-dev/vmlinux \
    -ex 'source /nix/store/7n77ijlxkxr6d613h02lr707kvjx6j1k-linux-6.1.19-dev/lib/modules/6.1.19/build/vmlinux-gdb.py' \
    -ex 'lx-version' \
    -ex 'q'

Also tested that the strip changes don't result in meaningful output
size changes (there's some small variation due to BTF data not always
coming out the same size, which is unrelated), and built every kernel
I can on x86_64 to make sure I'm not relying on build system behaviour
specific to newer kernels.
Diffstat (limited to 'pkgs/os-specific/linux/kernel/manual-config.nix')
-rw-r--r--pkgs/os-specific/linux/kernel/manual-config.nix18
1 files changed, 13 insertions, 5 deletions
diff --git a/pkgs/os-specific/linux/kernel/manual-config.nix b/pkgs/os-specific/linux/kernel/manual-config.nix
index fa21ab3b615..4c5ec86b1e6 100644
--- a/pkgs/os-specific/linux/kernel/manual-config.nix
+++ b/pkgs/os-specific/linux/kernel/manual-config.nix
@@ -277,7 +277,6 @@ let
       ];
 
       postInstall = optionalString isModular ''
-        cp vmlinux $dev/
         if [ -z "''${dontStrip-}" ]; then
           installFlagsArray+=("INSTALL_MOD_STRIP=1")
         fi
@@ -297,12 +296,16 @@ let
         # from a `try-run` call from the Makefile
         rm -f $dev/lib/modules/${modDirVersion}/build/.[0-9]*.d
 
-        # Keep some extra files on some arches (powerpc, aarch64)
-        for f in arch/powerpc/lib/crtsavres.o arch/arm64/kernel/ftrace-mod.o; do
-          if [ -f "$buildRoot/$f" ]; then
-            cp $buildRoot/$f $dev/lib/modules/${modDirVersion}/build/$f
+        # Keep some extra files
+        for f in arch/powerpc/lib/crtsavres.o arch/arm64/kernel/ftrace-mod.o \
+                 scripts/gdb/linux vmlinux vmlinux-gdb.py
+        do
+          if [ -e "$buildRoot/$f" ]; then
+            mkdir -p "$(dirname "$dev/lib/modules/${modDirVersion}/build/$f")"
+            cp -HR $buildRoot/$f $dev/lib/modules/${modDirVersion}/build/$f
           fi
         done
+        ln -s $dev/lib/modules/${modDirVersion}/build/vmlinux $dev
 
         # !!! No documentation on how much of the source tree must be kept
         # If/when kernel builds fail due to missing files, you can add
@@ -345,6 +348,11 @@ let
         sed -i Makefile -e 's|= ${buildPackages.kmod}/bin/depmod|= depmod|'
       '';
 
+      preFixup = ''
+        # Don't strip $dev/lib/modules/*/vmlinux
+        stripDebugList="$(cd $dev && echo lib/modules/*/build/*/)"
+      '';
+
       requiredSystemFeatures = [ "big-parallel" ];
 
       meta = {