From 34150f86c0a6b9d452bab09157896c3b85b103d1 Mon Sep 17 00:00:00 2001 From: roblabla Date: Tue, 22 Jun 2021 17:55:14 +0200 Subject: [PATCH] linux-kernel: Enable BTF BTF is a new, lightweight debug information format tailored specifically for the needs of eBPF, allowing eBPF programs to be portable across various kernel versions, configurations and distributions. This is used by bpftrace and lots of new eBPF-based tooling to avoid a dependency on LLVM on the host. BTF debug information is enabled on all major distributions: Fedora 31+, RHEL 8.2+, Ubuntu 20.10, Debian 11 and ArchLinux all have enabled it. Enabling BTF debug information requires adding two new dependencies to the kernel build: Python3 and pahole. Those will be used to generate the BTF debugging information. --- pkgs/os-specific/linux/kernel/common-config.nix | 7 ++++++- pkgs/os-specific/linux/kernel/manual-config.nix | 6 ++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/pkgs/os-specific/linux/kernel/common-config.nix b/pkgs/os-specific/linux/kernel/common-config.nix index 1ce4a21e2424..38bb2c4ebd07 100644 --- a/pkgs/os-specific/linux/kernel/common-config.nix +++ b/pkgs/os-specific/linux/kernel/common-config.nix @@ -35,7 +35,12 @@ let options = { debug = { - DEBUG_INFO = if (features.debug or false) then yes else no; + # Necessary for BTF + DEBUG_INFO = mkMerge [ + (whenOlder "5.2" (if (features.debug or false) then yes else no)) + (whenAtLeast "5.2" yes) + ]; + DEBUG_INFO_BTF = whenAtLeast "5.2" yes; DEBUG_KERNEL = yes; DEBUG_DEVRES = no; DYNAMIC_DEBUG = yes; diff --git a/pkgs/os-specific/linux/kernel/manual-config.nix b/pkgs/os-specific/linux/kernel/manual-config.nix index 77add0aef539..12eca63e2162 100644 --- a/pkgs/os-specific/linux/kernel/manual-config.nix +++ b/pkgs/os-specific/linux/kernel/manual-config.nix @@ -1,5 +1,5 @@ { lib, buildPackages, runCommand, nettools, bc, bison, flex, perl, rsync, gmp, libmpc, mpfr, openssl -, libelf, cpio, elfutils, zstd, gawk, python3Minimal +, libelf, cpio, elfutils, zstd, gawk, python3Minimal, zlib, pahole , writeTextFile }: @@ -316,10 +316,12 @@ stdenv.mkDerivation ((drvAttrs config stdenv.hostPlatform.linux-kernel kernelPat ++ optional (lib.versionAtLeast version "4.14" && lib.versionOlder version "5.8") libelf # Removed util-linuxMinimal since it should not be a dependency. ++ optionals (lib.versionAtLeast version "4.16") [ bison flex ] - ++ optional (lib.versionAtLeast version "5.2") cpio + ++ optionals (lib.versionAtLeast version "5.2") [ cpio pahole ] ++ optional (lib.versionAtLeast version "5.8") elfutils ; + buildInputs = optional (lib.versionAtLeast version "5.2") zlib; + hardeningDisable = [ "bindnow" "format" "fortify" "stackprotector" "pic" "pie" ]; # Absolute paths for compilers avoid any PATH-clobbering issues.