summary refs log tree commit diff
path: root/pkgs/os-specific
diff options
context:
space:
mode:
authorMaximilian Bosch <maximilian@mbosch.me>2023-03-20 20:42:10 +0100
committerGitHub <noreply@github.com>2023-03-20 20:42:10 +0100
commite999433b3a169306e752d6732527db8dc78e142c (patch)
treebd4af5da0acf5de70466c0a4dff523b1229b8294 /pkgs/os-specific
parentfb243f0f35ebd29ad542ed9bd9400e6291ac3f8b (diff)
parentd57568fcad7e3a9364850cb1c25d7a34693c02d5 (diff)
downloadnixpkgs-e999433b3a169306e752d6732527db8dc78e142c.tar
nixpkgs-e999433b3a169306e752d6732527db8dc78e142c.tar.gz
nixpkgs-e999433b3a169306e752d6732527db8dc78e142c.tar.bz2
nixpkgs-e999433b3a169306e752d6732527db8dc78e142c.tar.lz
nixpkgs-e999433b3a169306e752d6732527db8dc78e142c.tar.xz
nixpkgs-e999433b3a169306e752d6732527db8dc78e142c.tar.zst
nixpkgs-e999433b3a169306e752d6732527db8dc78e142c.zip
Merge pull request #221707 from NixOS/linuxManualConfig-unpack
linuxManualConfig: install GDB scripts
Diffstat (limited to 'pkgs/os-specific')
-rw-r--r--pkgs/os-specific/linux/kernel/common-config.nix7
-rw-r--r--pkgs/os-specific/linux/kernel/manual-config.nix55
2 files changed, 39 insertions, 23 deletions
diff --git a/pkgs/os-specific/linux/kernel/common-config.nix b/pkgs/os-specific/linux/kernel/common-config.nix
index 7f84c53d4d6..faa98ee8fe3 100644
--- a/pkgs/os-specific/linux/kernel/common-config.nix
+++ b/pkgs/os-specific/linux/kernel/common-config.nix
@@ -36,10 +36,7 @@ let
 
     debug = {
       # Necessary for BTF
-      DEBUG_INFO                = mkMerge [
-        (whenOlder "5.2" (if (features.debug or false) then yes else no))
-        (whenBetween "5.2" "5.18" yes)
-      ];
+      DEBUG_INFO                = yes;
       DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT = whenAtLeast "5.18" yes;
       # Reduced debug info conflict with BTF and have been enabled in
       # aarch64 defconfig since 5.13
@@ -62,6 +59,8 @@ let
       SUNRPC_DEBUG              = yes;
       # Provide access to tunables like sched_migration_cost_ns
       SCHED_DEBUG               = yes;
+
+      GDB_SCRIPTS               = yes;
     };
 
     power-management = {
diff --git a/pkgs/os-specific/linux/kernel/manual-config.nix b/pkgs/os-specific/linux/kernel/manual-config.nix
index b01805e83da..4c5ec86b1e6 100644
--- a/pkgs/os-specific/linux/kernel/manual-config.nix
+++ b/pkgs/os-specific/linux/kernel/manual-config.nix
@@ -115,6 +115,20 @@ let
             hash = "sha256-bBOyJcP6jUvozFJU0SPTOf3cmnTQ6ZZ4PlHjiniHXLU=";
           });
 
+      preUnpack = ''
+        # The same preUnpack is used to build the configfile,
+        # which does not have $dev.
+        if [ -n "$dev" ]; then
+            mkdir -p $dev/lib/modules/${modDirVersion}
+            cd $dev/lib/modules/${modDirVersion}
+        fi
+      '';
+
+      postUnpack = ''
+        mv -Tv "$sourceRoot" source 2>/dev/null || :
+        export sourceRoot=$PWD/source
+      '';
+
       postPatch = ''
         sed -i Makefile -e 's|= depmod|= ${buildPackages.kmod}/bin/depmod|'
 
@@ -156,8 +170,7 @@ let
       configurePhase = ''
         runHook preConfigure
 
-        mkdir build
-        export buildRoot="$(pwd)/build"
+        export buildRoot=$(mktemp -d)
 
         echo "manual-config configurePhase buildRoot=$buildRoot pwd=$PWD"
 
@@ -185,12 +198,14 @@ let
       '';
 
       buildFlags = [
+        "DTC_FLAGS=-@"
         "KBUILD_BUILD_VERSION=1-NixOS"
-        kernelConf.target
-        "vmlinux"  # for "perf" and things like that
-      ] ++ optional isModular "modules"
-        ++ optionals buildDTBs ["dtbs" "DTC_FLAGS=-@"]
-      ++ extraMakeFlags;
+
+        # Set by default in the kernel since a73619a845d5,
+        # replicated here to apply to older versions.
+        # Makes __FILE__ relative to the build directory.
+        "KCPPFLAGS=-fmacro-prefix-map=$(sourceRoot)/="
+      ] ++ extraMakeFlags;
 
       installFlags = [
         "INSTALL_PATH=$(out)"
@@ -262,8 +277,6 @@ let
       ];
 
       postInstall = optionalString isModular ''
-        mkdir -p $dev
-        cp vmlinux $dev/
         if [ -z "''${dontStrip-}" ]; then
           installFlagsArray+=("INSTALL_MOD_STRIP=1")
         fi
@@ -272,12 +285,7 @@ let
         unlink $out/lib/modules/${modDirVersion}/build
         unlink $out/lib/modules/${modDirVersion}/source
 
-        mkdir -p $dev/lib/modules/${modDirVersion}/{build,source}
-
-        # To save space, exclude a bunch of unneeded stuff when copying.
-        (cd .. && rsync --archive --prune-empty-dirs \
-            --exclude='/build/' \
-            * $dev/lib/modules/${modDirVersion}/source/)
+        mkdir $dev/lib/modules/${modDirVersion}/build
 
         cd $dev/lib/modules/${modDirVersion}/source
 
@@ -288,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
@@ -336,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 = {