From efe6967e9359bda4b9407e0d2cf9d0b0a6666652 Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Sat, 4 Dec 2021 00:11:22 +0900 Subject: [PATCH 01/10] bcc: move from linux-kernels packages to normal packages bcc doesn't really need kernel itself, it just cares about module path. It's actually better to use /run/booted-system/kernel-modules/lib/modules for two reasons: - no need to rebuild bcc for each new kernel - can use a newer bcc with a booted kernel that doesn't match the current system --- nixos/modules/programs/bcc.nix | 6 +++--- pkgs/os-specific/linux/bcc/default.nix | 14 ++++++-------- pkgs/top-level/all-packages.nix | 4 ++++ pkgs/top-level/linux-kernels.nix | 5 +---- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/nixos/modules/programs/bcc.nix b/nixos/modules/programs/bcc.nix index d76249bb5cab..e475c6ceaa6c 100644 --- a/nixos/modules/programs/bcc.nix +++ b/nixos/modules/programs/bcc.nix @@ -1,9 +1,9 @@ -{ config, lib, ... }: +{ config, pkgs, lib, ... }: { options.programs.bcc.enable = lib.mkEnableOption "bcc"; config = lib.mkIf config.programs.bcc.enable { - environment.systemPackages = [ config.boot.kernelPackages.bcc ]; - boot.extraModulePackages = [ config.boot.kernelPackages.bcc ]; + environment.systemPackages = [ pkgs.bcc ]; + boot.extraModulePackages = [ pkgs.bcc ]; }; } diff --git a/pkgs/os-specific/linux/bcc/default.nix b/pkgs/os-specific/linux/bcc/default.nix index 91e53d686a1b..4e8f28a0eda1 100644 --- a/pkgs/os-specific/linux/bcc/default.nix +++ b/pkgs/os-specific/linux/bcc/default.nix @@ -1,7 +1,7 @@ { lib, stdenv, fetchFromGitHub -, makeWrapper, cmake, llvmPackages, kernel +, makeWrapper, cmake, llvmPackages , flex, bison, elfutils, python, luajit, netperf, iperf, libelf -, systemtap, bash +, bash }: python.pkgs.buildPythonApplication rec { @@ -20,9 +20,9 @@ python.pkgs.buildPythonApplication rec { format = "other"; buildInputs = with llvmPackages; [ - llvm llvm.dev libclang kernel + llvm llvm.dev libclang elfutils luajit netperf iperf - systemtap.stapBuild flex bash + flex bash ]; patches = [ @@ -32,12 +32,10 @@ python.pkgs.buildPythonApplication rec { ]; propagatedBuildInputs = [ python.pkgs.netaddr ]; - nativeBuildInputs = [ makeWrapper cmake flex bison llvmPackages.llvm.dev ] - # libelf is incompatible with elfutils-libelf - ++ lib.filter (x: x != libelf) kernel.moduleBuildDependencies; + nativeBuildInputs = [ makeWrapper cmake flex bison llvmPackages.llvm.dev ]; cmakeFlags = [ - "-DBCC_KERNEL_MODULES_DIR=${kernel.dev}/lib/modules" + "-DBCC_KERNEL_MODULES_DIR=/run/booted-system/kernel-modules/lib/modules" "-DREVISION=${version}" "-DENABLE_USDT=ON" "-DENABLE_CPP_API=ON" diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index eabb434a3299..fd5a63bdc2cb 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -14149,6 +14149,10 @@ with pkgs; bpftools = callPackage ../os-specific/linux/bpftools { }; + bcc = callPackage ../os-specific/linux/bcc { + python = pkgs.python3; + }; + bpm-tools = callPackage ../tools/audio/bpm-tools { }; byacc = callPackage ../development/tools/parsing/byacc { }; diff --git a/pkgs/top-level/linux-kernels.nix b/pkgs/top-level/linux-kernels.nix index 2aa9f8482f18..e17bef470559 100644 --- a/pkgs/top-level/linux-kernels.nix +++ b/pkgs/top-level/linux-kernels.nix @@ -250,6 +250,7 @@ in { inherit (kernel) kernelOlder kernelAtLeast; # Obsolete aliases (these packages do not depend on the kernel). inherit (pkgs) odp-dpdk pktgen; # added 2018-05 + inherit (pkgs) bcc; # added 2021-12 acpi_call = callPackage ../os-specific/linux/acpi-call {}; @@ -263,10 +264,6 @@ in { batman_adv = callPackage ../os-specific/linux/batman-adv {}; - bcc = callPackage ../os-specific/linux/bcc { - python = pkgs.python3; - }; - bpftrace = callPackage ../os-specific/linux/bpftrace { }; bbswitch = callPackage ../os-specific/linux/bbswitch {}; From eb774dd0391d8a70b714f5dd5a95088ad0771d5f Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Sat, 4 Dec 2021 00:12:47 +0900 Subject: [PATCH 02/10] bpftrace: move from linux kernel packages to normal package bpftrace doesn't actually need to be a kernel package anymore. It used to require path to kernel sources, but we build our kernels with IKHEADER and BTF so the currently running configuration can always be found automatically without any patch --- pkgs/os-specific/linux/bpftrace/default.nix | 17 +++----------- .../bpftrace/fix-kernel-include-dir.patch | 22 ------------------- pkgs/top-level/all-packages.nix | 2 ++ pkgs/top-level/linux-kernels.nix | 4 +--- 4 files changed, 6 insertions(+), 39 deletions(-) delete mode 100644 pkgs/os-specific/linux/bpftrace/fix-kernel-include-dir.patch diff --git a/pkgs/os-specific/linux/bpftrace/default.nix b/pkgs/os-specific/linux/bpftrace/default.nix index 4d2f29491fca..f62ecc24b6aa 100644 --- a/pkgs/os-specific/linux/bpftrace/default.nix +++ b/pkgs/os-specific/linux/bpftrace/default.nix @@ -1,6 +1,6 @@ { lib, stdenv, fetchFromGitHub , cmake, pkg-config, flex, bison -, llvmPackages, kernel, elfutils +, llvmPackages, elfutils , libelf, libbfd, libbpf, libopcodes, bcc }: @@ -17,22 +17,11 @@ stdenv.mkDerivation rec { buildInputs = with llvmPackages; [ llvm libclang - kernel elfutils libelf bcc + elfutils libelf bcc libbpf libbfd libopcodes ]; - nativeBuildInputs = [ cmake pkg-config flex bison llvmPackages.llvm.dev ] - # libelf is incompatible with elfutils-libelf - ++ lib.filter (x: x != libelf) kernel.moduleBuildDependencies; - - # patch the source, *then* substitute on @NIX_KERNEL_SRC@ in the result. we could - # also in theory make this an environment variable around bpftrace, but this works - # nicely without wrappers. - patchPhase = '' - patch -p1 < ${./fix-kernel-include-dir.patch} - substituteInPlace ./src/utils.cpp \ - --subst-var-by NIX_KERNEL_SRC '${kernel.dev}/lib/modules/${kernel.modDirVersion}' - ''; + nativeBuildInputs = [ cmake pkg-config flex bison llvmPackages.llvm.dev ]; # tests aren't built, due to gtest shenanigans. see: # diff --git a/pkgs/os-specific/linux/bpftrace/fix-kernel-include-dir.patch b/pkgs/os-specific/linux/bpftrace/fix-kernel-include-dir.patch deleted file mode 100644 index bff370d51e27..000000000000 --- a/pkgs/os-specific/linux/bpftrace/fix-kernel-include-dir.patch +++ /dev/null @@ -1,22 +0,0 @@ -commit b6172952c0150d84912fa6f09bab782dd0549f1e -Author: Austin Seipp -Date: Fri May 3 00:47:12 2019 -0500 - - src: special case nix build directories for clang - - Signed-off-by: Austin Seipp - -diff --git a/src/clang_parser.cpp b/src/clang_parser.cpp -index b1db8ff..0cfb01f 100644 ---- a/src/utils.cpp -+++ b/src/utils.cpp -@@ -140,6 +140,9 @@ static bool is_dir(const std::string& path) - // Both ksrc and kobj are guaranteed to be != "", if at least some trace of kernel sources was found. - std::tuple get_kernel_dirs(const struct utsname& utsname) - { -+ // NB (aseipp): special case the kernel directory for nix -+ return { "@NIX_KERNEL_SRC@/source", "@NIX_KERNEL_SRC@/build" }; -+ - #ifdef KERNEL_HEADERS_DIR - return {KERNEL_HEADERS_DIR, KERNEL_HEADERS_DIR}; - #endif diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index fd5a63bdc2cb..d806d62d961e 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -14153,6 +14153,8 @@ with pkgs; python = pkgs.python3; }; + bpftrace = callPackage ../os-specific/linux/bpftrace { }; + bpm-tools = callPackage ../tools/audio/bpm-tools { }; byacc = callPackage ../development/tools/parsing/byacc { }; diff --git a/pkgs/top-level/linux-kernels.nix b/pkgs/top-level/linux-kernels.nix index e17bef470559..64b5d068220f 100644 --- a/pkgs/top-level/linux-kernels.nix +++ b/pkgs/top-level/linux-kernels.nix @@ -250,7 +250,7 @@ in { inherit (kernel) kernelOlder kernelAtLeast; # Obsolete aliases (these packages do not depend on the kernel). inherit (pkgs) odp-dpdk pktgen; # added 2018-05 - inherit (pkgs) bcc; # added 2021-12 + inherit (pkgs) bcc bpftrace; # added 2021-12 acpi_call = callPackage ../os-specific/linux/acpi-call {}; @@ -264,8 +264,6 @@ in { batman_adv = callPackage ../os-specific/linux/batman-adv {}; - bpftrace = callPackage ../os-specific/linux/bpftrace { }; - bbswitch = callPackage ../os-specific/linux/bbswitch {}; chipsec = callPackage ../tools/security/chipsec { From 1ffe19f6d848e411050e4cbe20e61032d2879fe1 Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Sat, 4 Dec 2021 21:08:02 +0900 Subject: [PATCH 03/10] maintainers: add martinetd will add myself to bpf-related packages over the next few commits --- maintainers/maintainer-list.nix | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/maintainers/maintainer-list.nix b/maintainers/maintainer-list.nix index bc71b9718c72..97b7645e3789 100644 --- a/maintainers/maintainer-list.nix +++ b/maintainers/maintainer-list.nix @@ -7203,6 +7203,12 @@ githubId = 623509; name = "Martijn Vermaat"; }; + martinetd = { + email = "f.ktfhrvnznqxacf@noclue.notk.org"; + github = "martinetd"; + githubId = 1729331; + name = "Dominique Martinet"; + }; martingms = { email = "martin@mg.am"; github = "martingms"; From 292cea941887d4a590beac48137f6a2914aae566 Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Sat, 4 Dec 2021 08:56:03 +0900 Subject: [PATCH 04/10] bpftrace: 0.13.0 -> 0.14.0 --- pkgs/os-specific/linux/bpftrace/default.nix | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pkgs/os-specific/linux/bpftrace/default.nix b/pkgs/os-specific/linux/bpftrace/default.nix index f62ecc24b6aa..e737a4f1f37a 100644 --- a/pkgs/os-specific/linux/bpftrace/default.nix +++ b/pkgs/os-specific/linux/bpftrace/default.nix @@ -2,23 +2,25 @@ , cmake, pkg-config, flex, bison , llvmPackages, elfutils , libelf, libbfd, libbpf, libopcodes, bcc +, cereal, asciidoctor }: stdenv.mkDerivation rec { pname = "bpftrace"; - version = "0.13.0"; + version = "0.14.0"; src = fetchFromGitHub { owner = "iovisor"; repo = "bpftrace"; rev = "v${version}"; - sha256 = "sha256-BKWBdFzj0j7rAfG30A0fwyYCpOG/5NFRPODW46EP1u0="; + sha256 = "sha256-rlaajNfpoiMtU/4aNAnbQ0VixPz9/302TZMarGzsb58="; }; buildInputs = with llvmPackages; [ llvm libclang elfutils libelf bcc libbpf libbfd libopcodes + cereal asciidoctor ]; nativeBuildInputs = [ cmake pkg-config flex bison llvmPackages.llvm.dev ]; @@ -45,6 +47,6 @@ stdenv.mkDerivation rec { description = "High-level tracing language for Linux eBPF"; homepage = "https://github.com/iovisor/bpftrace"; license = licenses.asl20; - maintainers = with maintainers; [ rvl thoughtpolice ]; + maintainers = with maintainers; [ rvl thoughtpolice martinetd ]; }; } From bc5879524469789911b984f308a0b0362d21757c Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Sat, 4 Dec 2021 08:54:26 +0900 Subject: [PATCH 05/10] pahole: 1.20 -> 1.22 --- pkgs/development/tools/misc/pahole/default.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/development/tools/misc/pahole/default.nix b/pkgs/development/tools/misc/pahole/default.nix index 86e1dac021c2..a6cf8355faeb 100644 --- a/pkgs/development/tools/misc/pahole/default.nix +++ b/pkgs/development/tools/misc/pahole/default.nix @@ -2,11 +2,11 @@ stdenv.mkDerivation rec { pname = "pahole"; - version = "1.20"; + version = "1.22"; src = fetchgit { url = "https://git.kernel.org/pub/scm/devel/pahole/pahole.git"; rev = "v${version}"; - sha256 = "11q9dpfi4qj2v8z0nlf8c0079mlv10ljhh0d1yr0j4ds3saacd15"; + sha256 = "sha256-U1/i9WNlLphPIcNysC476sqil/q9tMYmu+Y6psga8I0="; fetchSubmodules = true; }; From 78a4ea51e4186180397abd281f918d8c248ae1ea Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Sat, 4 Dec 2021 20:25:09 +0900 Subject: [PATCH 06/10] libbpf: install linux/btf.h This installs the linux/btf.h header in libbpf, which is necessarily compatible with bpf/btf.h Note that we also ship the linux header's linux/btf.h with glibc, but explicit buildInputs should have priority over default headers so hopefully this one will always be used. --- pkgs/os-specific/linux/libbpf/default.nix | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkgs/os-specific/linux/libbpf/default.nix b/pkgs/os-specific/linux/libbpf/default.nix index 5debfd2ef2c8..ba765b4f92e2 100644 --- a/pkgs/os-specific/linux/libbpf/default.nix +++ b/pkgs/os-specific/linux/libbpf/default.nix @@ -23,6 +23,11 @@ stdenv.mkDerivation rec { enableParallelBuilding = true; makeFlags = [ "PREFIX=$(out)" ]; + postInstall = '' + # install linux's libbpf-compatible linux/btf.h + install -Dm444 ../include/uapi/linux/btf.h -t $out/include/linux + ''; + # FIXME: Multi-output requires some fixes to the way the pkg-config file is # constructed (it gets put in $out instead of $dev for some reason, with # improper paths embedded). Don't enable it for now. @@ -33,7 +38,7 @@ stdenv.mkDerivation rec { description = "Upstream mirror of libbpf"; homepage = "https://github.com/libbpf/libbpf"; license = with licenses; [ lgpl21 /* or */ bsd2 ]; - maintainers = with maintainers; [ thoughtpolice vcunat saschagrunert ]; + maintainers = with maintainers; [ thoughtpolice vcunat saschagrunert martinetd ]; platforms = platforms.linux; }; } From 0ae1623ea3f146b07477a8e81d6bbcef23ea91f0 Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Sat, 4 Dec 2021 08:55:48 +0900 Subject: [PATCH 07/10] pahole: remove submodule 1.22 merged the EMBEDDED_LIBBPF patch back --- pkgs/development/tools/misc/pahole/default.nix | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pkgs/development/tools/misc/pahole/default.nix b/pkgs/development/tools/misc/pahole/default.nix index a6cf8355faeb..e0100154f3be 100644 --- a/pkgs/development/tools/misc/pahole/default.nix +++ b/pkgs/development/tools/misc/pahole/default.nix @@ -1,4 +1,4 @@ -{ lib, stdenv, fetchgit, cmake, elfutils, zlib }: +{ lib, stdenv, fetchgit, pkg-config, libbpf, cmake, elfutils, zlib }: stdenv.mkDerivation rec { pname = "pahole"; @@ -7,14 +7,13 @@ stdenv.mkDerivation rec { url = "https://git.kernel.org/pub/scm/devel/pahole/pahole.git"; rev = "v${version}"; sha256 = "sha256-U1/i9WNlLphPIcNysC476sqil/q9tMYmu+Y6psga8I0="; - fetchSubmodules = true; }; - nativeBuildInputs = [ cmake ]; - buildInputs = [ elfutils zlib ]; + nativeBuildInputs = [ cmake pkg-config ]; + buildInputs = [ elfutils zlib libbpf ]; # Put libraries in "lib" subdirectory, not top level of $out - cmakeFlags = [ "-D__LIB=lib" ]; + cmakeFlags = [ "-D__LIB=lib" "-DLIBBPF_EMBEDDED=OFF" ]; meta = with lib; { homepage = "https://git.kernel.org/cgit/devel/pahole/pahole.git/"; @@ -22,6 +21,6 @@ stdenv.mkDerivation rec { license = licenses.gpl2Only; platforms = platforms.linux; - maintainers = [ maintainers.bosu ]; + maintainers = with maintainers; [ bosu martinetd ]; }; } From 2318433b7388444c67a54cc79a9d7baf7df27e26 Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Sat, 4 Dec 2021 09:22:45 +0900 Subject: [PATCH 08/10] bcc: remove submodule reverting libbpf back to 0.5.0 fixes bcc compilation with our libbpf This also shows this was a libbpf bug rather than a bcc problem... --- pkgs/os-specific/linux/bcc/default.nix | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pkgs/os-specific/linux/bcc/default.nix b/pkgs/os-specific/linux/bcc/default.nix index 4e8f28a0eda1..7033329b9b39 100644 --- a/pkgs/os-specific/linux/bcc/default.nix +++ b/pkgs/os-specific/linux/bcc/default.nix @@ -1,7 +1,7 @@ { lib, stdenv, fetchFromGitHub , makeWrapper, cmake, llvmPackages , flex, bison, elfutils, python, luajit, netperf, iperf, libelf -, bash +, bash, libbpf }: python.pkgs.buildPythonApplication rec { @@ -14,15 +14,14 @@ python.pkgs.buildPythonApplication rec { owner = "iovisor"; repo = "bcc"; rev = "v${version}"; - sha256 = "sha256-4zfjr3VLg26uZ4xNKA1wayti7f2tqGvYSbwoZnr+Ygk="; - fetchSubmodules = true; + sha256 = "sha256-iLVUwJTDQ8Bn38sgHOcIR8TYxIB+gIlfTgr9+gPU0gE="; }; format = "other"; buildInputs = with llvmPackages; [ llvm llvm.dev libclang elfutils luajit netperf iperf - flex bash + flex bash libbpf ]; patches = [ @@ -39,6 +38,7 @@ python.pkgs.buildPythonApplication rec { "-DREVISION=${version}" "-DENABLE_USDT=ON" "-DENABLE_CPP_API=ON" + "-DCMAKE_USE_LIBBPF_PACKAGE=ON" ]; postPatch = '' @@ -73,6 +73,6 @@ python.pkgs.buildPythonApplication rec { description = "Dynamic Tracing Tools for Linux"; homepage = "https://iovisor.github.io/bcc/"; license = licenses.asl20; - maintainers = with maintainers; [ ragge mic92 thoughtpolice ]; + maintainers = with maintainers; [ ragge mic92 thoughtpolice martinetd ]; }; } From 559fe436657bf68f83718548c02cdcd6e93e6add Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Sat, 4 Dec 2021 10:20:26 +0900 Subject: [PATCH 09/10] nixos/tests: add bpf test test bcc and bpftrace briefly --- nixos/tests/all-tests.nix | 1 + nixos/tests/bpf.nix | 25 +++++++++++++++++++++ pkgs/os-specific/linux/bcc/default.nix | 6 ++++- pkgs/os-specific/linux/bpftrace/default.nix | 5 +++++ 4 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 nixos/tests/bpf.nix diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 1ff1b8d58642..d67cfea11646 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -44,6 +44,7 @@ in boot-stage1 = handleTest ./boot-stage1.nix {}; borgbackup = handleTest ./borgbackup.nix {}; botamusique = handleTest ./botamusique.nix {}; + bpf = handleTestOn ["x86_64-linux" "aarch64-linux"] ./bpf.nix {}; btrbk = handleTest ./btrbk.nix {}; buildbot = handleTest ./buildbot.nix {}; buildkite-agents = handleTest ./buildkite-agents.nix {}; diff --git a/nixos/tests/bpf.nix b/nixos/tests/bpf.nix new file mode 100644 index 000000000000..233c7dab1ee2 --- /dev/null +++ b/nixos/tests/bpf.nix @@ -0,0 +1,25 @@ +import ./make-test-python.nix ({ pkgs, ... }: { + name = "bpf"; + meta.maintainers = with pkgs.lib.maintainers; [ martinetd ]; + + machine = { pkgs, ... }: { + programs.bcc.enable = true; + environment.systemPackages = with pkgs; [ bpftrace ]; + }; + + testScript = '' + ## bcc + # syscount -d 1 stops 1s after probe started so is good for that + print(machine.succeed("syscount -d 1")) + + ## bpftrace + # list probes + machine.succeed("bpftrace -l") + # simple BEGIN probe (user probe on bpftrace itself) + print(machine.succeed("bpftrace -e 'BEGIN { print(\"ok\"); exit(); }'")) + # tracepoint + print(machine.succeed("bpftrace -e 'tracepoint:syscalls:sys_enter_* { print(probe); exit(); }'")) + # kprobe + print(machine.succeed("bpftrace -e 'kprobe:schedule { print(probe); exit() }'")) + ''; +}) diff --git a/pkgs/os-specific/linux/bcc/default.nix b/pkgs/os-specific/linux/bcc/default.nix index 7033329b9b39..c87740ed0217 100644 --- a/pkgs/os-specific/linux/bcc/default.nix +++ b/pkgs/os-specific/linux/bcc/default.nix @@ -1,7 +1,7 @@ { lib, stdenv, fetchFromGitHub , makeWrapper, cmake, llvmPackages , flex, bison, elfutils, python, luajit, netperf, iperf, libelf -, bash, libbpf +, bash, libbpf, nixosTests }: python.pkgs.buildPythonApplication rec { @@ -69,6 +69,10 @@ python.pkgs.buildPythonApplication rec { wrapPythonProgramsIn "$out/share/bcc/tools" "$out $pythonPath" ''; + passthru.tests = { + bpf = nixosTests.bpf; + }; + meta = with lib; { description = "Dynamic Tracing Tools for Linux"; homepage = "https://iovisor.github.io/bcc/"; diff --git a/pkgs/os-specific/linux/bpftrace/default.nix b/pkgs/os-specific/linux/bpftrace/default.nix index e737a4f1f37a..b69514e8080f 100644 --- a/pkgs/os-specific/linux/bpftrace/default.nix +++ b/pkgs/os-specific/linux/bpftrace/default.nix @@ -3,6 +3,7 @@ , llvmPackages, elfutils , libelf, libbfd, libbpf, libopcodes, bcc , cereal, asciidoctor +, nixosTests }: stdenv.mkDerivation rec { @@ -43,6 +44,10 @@ stdenv.mkDerivation rec { outputs = [ "out" "man" ]; + passthru.tests = { + bpf = nixosTests.bpf; + }; + meta = with lib; { description = "High-level tracing language for Linux eBPF"; homepage = "https://github.com/iovisor/bpftrace"; From fa857bb4357937a20675ae1ef49cf37e54e2f20c Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Sat, 4 Dec 2021 21:54:07 +0900 Subject: [PATCH 10/10] bpftrace: fix build with libbpf 0.6.0 libbpf 0.6.0 relies on typeof in bpf/btf.h to pick the right version of btf_dump__new() but that's not valid c++. see https://github.com/iovisor/bpftrace/issues/2068 --- .../linux/bpftrace/btf-dump-new-0.6.0.patch | 39 +++++++++++++++++++ pkgs/os-specific/linux/bpftrace/default.nix | 5 +++ 2 files changed, 44 insertions(+) create mode 100644 pkgs/os-specific/linux/bpftrace/btf-dump-new-0.6.0.patch diff --git a/pkgs/os-specific/linux/bpftrace/btf-dump-new-0.6.0.patch b/pkgs/os-specific/linux/bpftrace/btf-dump-new-0.6.0.patch new file mode 100644 index 000000000000..b5037192203c --- /dev/null +++ b/pkgs/os-specific/linux/bpftrace/btf-dump-new-0.6.0.patch @@ -0,0 +1,39 @@ +diff -ur source/src/btf.cpp new/src/btf.cpp +--- source/src/btf.cpp 1970-01-01 09:00:01.000000000 +0900 ++++ new/src/btf.cpp 2021-12-04 21:46:59.337023489 +0900 +@@ -225,7 +225,7 @@ + char err_buf[256]; + int err; + +- dump = btf_dump__new(btf, nullptr, &opts, dump_printf); ++ dump = btf_dump__new_deprecated(btf, nullptr, &opts, dump_printf); + err = libbpf_get_error(dump); + if (err) + { +@@ -496,7 +496,7 @@ + char err_buf[256]; + int err; + +- dump = btf_dump__new(btf, nullptr, &opts, dump_printf); ++ dump = btf_dump__new_deprecated(btf, nullptr, &opts, dump_printf); + err = libbpf_get_error(dump); + if (err) + { +@@ -554,7 +554,7 @@ + char err_buf[256]; + int err; + +- dump = btf_dump__new(btf, nullptr, &opts, dump_printf); ++ dump = btf_dump__new_deprecated(btf, nullptr, &opts, dump_printf); + err = libbpf_get_error(dump); + if (err) + { +@@ -648,7 +648,7 @@ + char err_buf[256]; + int err; + +- dump = btf_dump__new(btf, nullptr, &opts, dump_printf); ++ dump = btf_dump__new_deprecated(btf, nullptr, &opts, dump_printf); + err = libbpf_get_error(dump); + if (err) + { diff --git a/pkgs/os-specific/linux/bpftrace/default.nix b/pkgs/os-specific/linux/bpftrace/default.nix index b69514e8080f..9a197b4c78c8 100644 --- a/pkgs/os-specific/linux/bpftrace/default.nix +++ b/pkgs/os-specific/linux/bpftrace/default.nix @@ -17,6 +17,11 @@ stdenv.mkDerivation rec { sha256 = "sha256-rlaajNfpoiMtU/4aNAnbQ0VixPz9/302TZMarGzsb58="; }; + # libbpf 0.6.0 relies on typeof in bpf/btf.h to pick the right version of + # btf_dump__new() but that's not valid c++. + # see https://github.com/iovisor/bpftrace/issues/2068 + patches = [ ./btf-dump-new-0.6.0.patch ]; + buildInputs = with llvmPackages; [ llvm libclang elfutils libelf bcc