GNU bug report logs - #54728
Valgrind not working out of the box due to stripped ld.so

Previous Next

Package: guix;

Reported by: Denis 'GNUtoo' Carikli <GNUtoo <at> cyberdimension.org>

Date: Tue, 5 Apr 2022 15:01:02 UTC

Severity: normal

Done: Ludovic Courtès <ludo <at> gnu.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: Denis 'GNUtoo' Carikli <GNUtoo <at> cyberdimension.org>
Subject: bug#54728: closed (Re: bug#54728: Valgrind not working out of the
 box due to stripped ld.so)
Date: Mon, 09 May 2022 09:25:02 +0000
[Message part 1 (text/plain, inline)]
Your bug report

#54728: Valgrind not working out of the box due to stripped ld.so

which was filed against the guix package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to 54728 <at> debbugs.gnu.org.

-- 
54728: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=54728
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: Ludovic Courtès <ludo <at> gnu.org>
To: Denis 'GNUtoo' Carikli <GNUtoo <at> cyberdimension.org>
Cc: 54728-done <at> debbugs.gnu.org, maximedevos <at> telenet.be
Subject: Re: bug#54728: Valgrind not working out of the box due to stripped
 ld.so
Date: Mon, 09 May 2022 11:24:44 +0200
[Message part 3 (text/plain, inline)]
Hi Denis,

Denis 'GNUtoo' Carikli <GNUtoo <at> cyberdimension.org> skribis:

> * gnu/packages/valgrind.scm (valgrind/interactive)[native-inputs]:
>   Add libc:debug
>   [arguments]: Add patch-default-debuginfo-path phase
>   [source]: Add patch.
>   (valgrind-3.18)[source]: Add patch.
>
> * gnu/packages/commencement.scm (glibc-final): Export variable.
>
> Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo <at> cyberdimension.org>

I had lost track of it, so thanks for pinging.

I’ve applied it and confirmed it works.  I made the following cosmetic
changes (patch below):

  • removing the ‘glibc-final’ export, which is unnecessary;

  • in phases, refer to the ‘inputs’ parameter rather than the
    ‘%build-inputs’ global variable (which is deprecated);

  • avoid repetition of (string-append (assoc-ref …) "/lib/debug");

  • tweak indentation.

Thanks!

Ludo’.

[Message part 4 (text/x-patch, inline)]
diff --git a/gnu/packages/valgrind.scm b/gnu/packages/valgrind.scm
index 1269e07593..0da011087c 100644
--- a/gnu/packages/valgrind.scm
+++ b/gnu/packages/valgrind.scm
@@ -95,83 +95,71 @@ (define-public valgrind
 
 (define-public valgrind/interactive
   (package/inherit
-   valgrind
-   (version "3.17.0")
-   (source (origin
-             (method url-fetch)
-             (uri (list (string-append "https://sourceware.org/pub/valgrind"
-                                       "/valgrind-" version ".tar.bz2")
-                        (string-append "ftp://sourceware.org/pub/valgrind"
-                                       "/valgrind-" version ".tar.bz2")))
-             (sha256
-              (base32
-               "18l5jbk301j3462gipqn9bkfx44mdmwn0pwr73r40gl1irkfqfmd"))
-             (patches (search-patches
-                       "valgrind-enable-arm.patch"
-                       "valgrind-fix-default-debuginfo-path.patch"))))
-   (inputs
-    ;; GDB is needed to provide a sane default for `--db-command'.
-    `(("gdb" ,gdb)
-      ("glibc:debug" ,(canonical-package glibc) "debug")))
-   (arguments
+      valgrind
+    (version "3.17.0")
+    (source (origin
+              (method url-fetch)
+              (uri (list (string-append "https://sourceware.org/pub/valgrind"
+                                        "/valgrind-" version ".tar.bz2")
+                         (string-append "ftp://sourceware.org/pub/valgrind"
+                                        "/valgrind-" version ".tar.bz2")))
+              (sha256
+               (base32
+                "18l5jbk301j3462gipqn9bkfx44mdmwn0pwr73r40gl1irkfqfmd"))
+              (patches (search-patches
+                        "valgrind-enable-arm.patch"
+                        "valgrind-fix-default-debuginfo-path.patch"))))
+    (inputs
+     ;; GDB is needed to provide a sane default for `--db-command'.
+     `(("gdb" ,gdb)
+       ("glibc:debug" ,(canonical-package glibc) "debug")))
+    (arguments
      (substitute-keyword-arguments (package-arguments valgrind)
-       ((#:phases those-phases #~%standard-phases)
-        #~(let* ((those-phases #$those-phases)
-                 (unpack (assoc-ref those-phases 'unpack)))
-            (modify-phases
-              those-phases
-                (add-before 'configure 'patch-default-debuginfo-path
-                  (lambda _
-                    ;; This helps Valgrind find the debug symbols of ld.so.
-                    ;; Without it, Valgrind does not work in a Guix shell
-                    ;; container and cannot be used as-is during packages tests
-                    ;; phases
-                    (substitute* '
-                      ("coregrind/m_debuginfo/readelf.c"
-                       "docs/xml/manual-core-adv.xml"
-                       "docs/xml/manual-core.xml")
-                      (("DEFAULT_DEBUGINFO_PATH")
-                       (string-append (assoc-ref %build-inputs "glibc:debug")
-                                      "/lib/debug")))
-                    ;; We also need to account for the bigger path in
-                    ;; the malloc-ed variables
-                    (substitute* '
-                     ("coregrind/m_debuginfo/readelf.c")
-                     (("DEBUGPATH_EXTRA_BYTES_1")
-                      (number->string
-                       (+ (string-length
-                           (string-append
-                            (assoc-ref %build-inputs "glibc:debug")
-                            "/lib/debug"))
-                          (string-length "/.build-id//.debug")
-                          1))))
-                    (substitute* '
-                     ("coregrind/m_debuginfo/readelf.c")
-                     (("DEBUGPATH_EXTRA_BYTES_2")
-                      (number->string
-                       (+ (string-length
-                           (string-append
-                            (assoc-ref
-                             %build-inputs
-                             "glibc:debug")
-                            "/lib/debug"))
-                          (string-length
-                           "/usr/lib/debug")
-                          1)))))))))))
-   (properties '())))
+       ((#:phases phases #~%standard-phases)
+        #~(modify-phases #$phases
+            (add-before 'configure 'patch-default-debuginfo-path
+              (lambda* (#:key inputs #:allow-other-keys)
+                ;; This helps Valgrind find the debug symbols of ld.so.
+                ;; Without it, Valgrind does not work in a Guix shell
+                ;; container and cannot be used as-is during packages tests
+                ;; phases.
+                ;; TODO: Remove on the next rebuild cycle, when libc is not
+                ;; longer fully stripped.
+                (define libc-debug
+                  (string-append (assoc-ref inputs "glibc:debug")
+                                 "/lib/debug"))
+
+                (substitute* '("coregrind/m_debuginfo/readelf.c"
+                               "docs/xml/manual-core-adv.xml"
+                               "docs/xml/manual-core.xml")
+                  (("DEFAULT_DEBUGINFO_PATH")
+                   libc-debug))
+                ;; We also need to account for the bigger path in
+                ;; the malloc-ed variables.
+                (substitute* '("coregrind/m_debuginfo/readelf.c")
+                  (("DEBUGPATH_EXTRA_BYTES_1")
+                   (number->string
+                    (+ (string-length libc-debug)
+                       (string-length "/.build-id//.debug")
+                       1))))
+                (substitute* '("coregrind/m_debuginfo/readelf.c")
+                  (("DEBUGPATH_EXTRA_BYTES_2")
+                   (number->string
+                    (+ (string-length libc-debug)
+                       (string-length "/usr/lib/debug")
+                       1))))))))))
+    (properties '())))
 
 (define-public valgrind-3.18
   (package
     (inherit valgrind/interactive)
     (version "3.18.1")
     (source (origin
-              (method url-fetch)
+              (inherit (package-source valgrind/interactive))
               (uri (list (string-append "https://sourceware.org/pub/valgrind"
                                         "/valgrind-" version ".tar.bz2")
                          (string-append "ftp://sourceware.org/pub/valgrind"
                                         "/valgrind-" version ".tar.bz2")))
               (sha256
                (base32
-                "1xgph509i6adv9w2glviw3xrmlz0dssg8992hbvxsbkp7ahrm180"))
-              (patches (search-patches "valgrind-enable-arm.patch"
-                                       "valgrind-fix-default-debuginfo-path.patch"))))))
+                "1xgph509i6adv9w2glviw3xrmlz0dssg8992hbvxsbkp7ahrm180"))))))
[Message part 5 (message/rfc822, inline)]
From: Denis 'GNUtoo' Carikli <GNUtoo <at> cyberdimension.org>
To: bug-guix <at> gnu.org
Subject: Valgrind not working out of the box due to stripped ld.so
Date: Tue, 5 Apr 2022 17:01:32 +0200
[Message part 6 (text/plain, inline)]
Hi,

The fact that Valgrind doesn't work out of the box seems to already be
known[1] but I didn't find any bugreports on it.

The workaround[1] mentioned is extremely useful but it's far from ideal.

For instance if you have a software that uses Valgrind in its tests
(for instance in 'make check') you end up having to add something like
that in the native-inputs to refer to the right glibc debug symbols
directory:
> ("libc:debug", (@@ (gnu packages commencement) glibc-final) "debug")

In my case I'm using guix and a guix.scm for testing the build of a
library I maintain and I also wanted to automatically check for memory
safety.

I was helped a lot on #guix to solve the issue I had, and during that
mjw suggested to fix the root issue by keeping "the .symtab in ld.so"
without the full debug info (to save space) and if I understood right
mjw is a valgrind contributor.

According to mjw that could be done with strip -g or strip -d or -strip
-S.

Reference:
----------
[1]https://lists.gnu.org/archive/html/help-guix/2022-03/msg00036.html

Denis.
[Message part 7 (application/pgp-signature, inline)]

This bug report was last modified 3 years and 11 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.