From be85a5548509d267cdeae8a13a02e019c3dbcfac Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Wed, 16 Feb 2022 19:34:10 -0800 Subject: [PATCH 1/3] valgrind: Search NIX_DEBUG_INFO_DIRS for debug info Signed-off-by: Anders Kaseorg --- .../valgrind/debug-info-from-env.patch | 31 +++++++++++++++++++ .../tools/analysis/valgrind/default.nix | 6 ++++ 2 files changed, 37 insertions(+) create mode 100644 pkgs/development/tools/analysis/valgrind/debug-info-from-env.patch diff --git a/pkgs/development/tools/analysis/valgrind/debug-info-from-env.patch b/pkgs/development/tools/analysis/valgrind/debug-info-from-env.patch new file mode 100644 index 000000000000..a237bc87d072 --- /dev/null +++ b/pkgs/development/tools/analysis/valgrind/debug-info-from-env.patch @@ -0,0 +1,31 @@ +diff --git a/coregrind/m_debuginfo/readelf.c b/coregrind/m_debuginfo/readelf.c +index c586e3f33..e3bb1717f 100644 +--- a/coregrind/m_debuginfo/readelf.c ++++ b/coregrind/m_debuginfo/readelf.c +@@ -1508,13 +1508,25 @@ DiImage* find_debug_file( struct _DebugInfo* di, + HChar* debugpath = NULL; /* where we found it */ + + if (buildid != NULL) { ++ const HChar *dir = VG_(getenv)("NIX_DEBUG_INFO_DIRS"); + debugpath = ML_(dinfo_zalloc)("di.fdf.1", +- VG_(strlen)(buildid) + 33); ++ VG_(strlen)(buildid) + 33 + ++ (dir ? VG_(strlen)(dir) : 0)); + + VG_(sprintf)(debugpath, "/usr/lib/debug/.build-id/%c%c/%s.debug", + buildid[0], buildid[1], buildid + 2); + + dimg = open_debug_file(debugpath, buildid, 0, rel_ok, NULL); ++ ++ while (!dimg && dir) { ++ const HChar *sep = VG_(strchr)(dir, ':'); ++ Int size = sep ? sep - dir : VG_(strlen)(dir); ++ VG_(sprintf)(debugpath, "%.*s/.build-id/%c%c/%s.debug", ++ size, dir, buildid[0], buildid[1], buildid + 2); ++ dimg = open_debug_file(debugpath, buildid, 0, rel_ok, NULL); ++ dir = sep ? sep + 1 : NULL; ++ } ++ + if (!dimg) { + ML_(dinfo_free)(debugpath); + debugpath = NULL; diff --git a/pkgs/development/tools/analysis/valgrind/default.nix b/pkgs/development/tools/analysis/valgrind/default.nix index 6e736df235f0..7aef87a2f0ef 100644 --- a/pkgs/development/tools/analysis/valgrind/default.nix +++ b/pkgs/development/tools/analysis/valgrind/default.nix @@ -1,6 +1,7 @@ { lib, stdenv, fetchurl, fetchpatch , autoreconfHook, perl , gdb, cctools, xnu, bootstrap_cmds +, setupDebugInfoDirs }: stdenv.mkDerivation rec { @@ -19,6 +20,7 @@ stdenv.mkDerivation rec { url = "https://bugsfiles.kde.org/attachment.cgi?id=143535"; sha256 = "036zyk30rixjvpylw3c7n171n4gpn6zcp7h6ya2dz4h5r478l9i6"; }) + ./debug-info-from-env.patch ]; outputs = [ "out" "dev" "man" "doc" ]; @@ -32,6 +34,10 @@ stdenv.mkDerivation rec { # Perl is also a native build input. nativeBuildInputs = [ autoreconfHook perl ]; + # Not propagatedNativeBuildInputs because of + # https://github.com/NixOS/nixpkgs/issues/64992. + propagatedBuildInputs = [ setupDebugInfoDirs ]; + enableParallelBuilding = true; separateDebugInfo = stdenv.isLinux; From 4bb779294e0cf7e45eea52c93c8ad97a6cf9a549 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Wed, 16 Feb 2022 23:14:34 -0800 Subject: [PATCH 2/3] libpsl: Add glibc.debug for valgrind tests Signed-off-by: Anders Kaseorg --- pkgs/development/libraries/libpsl/default.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkgs/development/libraries/libpsl/default.nix b/pkgs/development/libraries/libpsl/default.nix index 0a710d648fbf..e505651ab406 100644 --- a/pkgs/development/libraries/libpsl/default.nix +++ b/pkgs/development/libraries/libpsl/default.nix @@ -3,6 +3,7 @@ , autoreconfHook , docbook_xsl , docbook_xml_dtd_43 +, glibc , gtk-doc , lzip , libidn2 @@ -38,6 +39,7 @@ in stdenv.mkDerivation rec { python3 libxslt ] ++ lib.optionals enableValgrindTests [ + glibc.debug valgrind ]; From d65255675854b4d2bd367549a423988bf8ddc5e5 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Tue, 15 Feb 2022 20:00:14 -0800 Subject: [PATCH 3/3] separateDebugInfo: Use --strip-unneeded MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit According to https://stackoverflow.com/q/46197810/115030, --only-keep-debug preserves all the information stripped by --strip-unneeded. This reduces the size of the webkitgtk output by 22% (123 MB → 96 MB). Inspired by #159612. Signed-off-by: Anders Kaseorg --- pkgs/build-support/setup-hooks/separate-debug-info.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/build-support/setup-hooks/separate-debug-info.sh b/pkgs/build-support/setup-hooks/separate-debug-info.sh index 1a23e6b198ee..d910bce11af0 100644 --- a/pkgs/build-support/setup-hooks/separate-debug-info.sh +++ b/pkgs/build-support/setup-hooks/separate-debug-info.sh @@ -34,7 +34,7 @@ _separateDebugInfo() { # firmware blobs in QEMU.) ( $OBJCOPY --only-keep-debug "$i" "$dst/${id:0:2}/${id:2}.debug" - $STRIP --strip-debug "$i" + $STRIP --strip-unneeded "$i" # Also a create a symlink .debug. ln -sfn ".build-id/${id:0:2}/${id:2}.debug" "$dst/../$(basename "$i")"