From 017e0d82f765c82f46f8ac7c1c216f2304083d13 Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Thu, 18 Sep 2025 13:15:44 +0200 Subject: [PATCH] Fix AMDuProfPcm so it finds libnuma.so MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We change the search procedure so it detects NixOS from /etc/os-release and uses "libnuma.so" when calling dlopen, instead of harcoding a full path to /usr. The full patch of libnuma is stored in the runpath, so dlopen can find it. Reviewed-by: Aleix Boné Tested-by: Vincent Arcila --- pkgs/amd-uprof/default.nix | 9 ++++++++- pkgs/amd-uprof/libnuma.r2 | 10 ++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 pkgs/amd-uprof/libnuma.r2 diff --git a/pkgs/amd-uprof/default.nix b/pkgs/amd-uprof/default.nix index f412ad2..9eb6707 100644 --- a/pkgs/amd-uprof/default.nix +++ b/pkgs/amd-uprof/default.nix @@ -17,12 +17,15 @@ , dbus , rocmPackages , libxcrypt-legacy +, numactl +, radare2 }: let version = "5.1.701"; tarball = "AMDuProf_Linux_x64_${version}.tar.bz2"; + # NOTE: Remember to update the radare2 patch below if AMDuProfPcm changes. uprofSrc = runCommandLocal tarball { nativeBuildInputs = [ curl ]; outputHash = "sha256-j9gxcBcIg6Zhc5FglUXf/VV9bKSo+PAKeootbN7ggYk="; @@ -45,7 +48,7 @@ in src = uprofSrc; dontStrip = true; phases = [ "installPhase" "fixupPhase" ]; - nativeBuildInputs = [ autoPatchelfHook ]; + nativeBuildInputs = [ autoPatchelfHook radare2 ]; buildInputs = [ stdenv.cc.cc.lib ncurses5 @@ -69,6 +72,7 @@ in freetype dbus rocmPackages.rocprofiler + numactl ]; installPhase = '' set -x @@ -77,6 +81,9 @@ in rm $out/bin/AMDPowerProfilerDriverSource.tar.gz patchelf --replace-needed libroctracer64.so.1 libroctracer64.so $out/bin/ProfileAgents/x64/libAMDGpuAgent.so patchelf --add-needed libcrypt.so.1 --add-needed libstdc++.so.6 $out/bin/AMDuProfSys + echo "16334a51fcc48668307ad94e20482ca4 $out/bin/AMDuProfPcm" | md5sum -c - + radare2 -w -q -i ${./libnuma.r2} $out/bin/AMDuProfPcm + patchelf --add-needed libnuma.so $out/bin/AMDuProfPcm set +x ''; } diff --git a/pkgs/amd-uprof/libnuma.r2 b/pkgs/amd-uprof/libnuma.r2 new file mode 100644 index 0000000..77cbabc --- /dev/null +++ b/pkgs/amd-uprof/libnuma.r2 @@ -0,0 +1,10 @@ +# Patch arguments to call sym std::string::find(char const*, unsigned long, unsigned long) +# so it matches NixOS: +# +# Change OS name to NixOS +wz NixOS @ 0x00550a43 +# And set the length to 5 characters +wa mov ecx, 5 @0x00517930 +# +# Then change the argument to dlopen() so it only uses libnuma.so +wz libnuma.so @ 0x00562940