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

  • Done
  • quality assurance status badge
Details
3 participants
  • Denis 'GNUtoo' Carikli
  • Ludovic Courtès
  • Maxime Devos
Owner
unassigned
Submitted by
Denis 'GNUtoo' Carikli
Severity
normal
D
D
Denis 'GNUtoo' Carikli wrote on 5 Apr 2022 17:01
(address . bug-guix@gnu.org)
20220405170132.49b23163@primarylaptop.localdomain
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:
Toggle quote (2 lines)
> ("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:
----------

Denis.
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCAAdFiEEeC+d2+Nrp/PU3kkGX138wUF34mMFAmJMWc0ACgkQX138wUF3
4mNUiA//VmQ6ebtuslIgtGLVAsMvcBvQkte6ANrJOVazIiVda5TcvYaApmLYrznl
DsDtWhvEO/S0ZgQsKxbTliY6Yr0gPJAkRUtOvlQmysN0AEyhvg/GQxMT/CJz7lFM
YYuaCciKKkOzB/HPW9Ft0OwKA1Q8ZgFMd8/uB8tQ8PO9SH9Pqbw+Ahqql20jXLKn
zBpkinmD0CmRFauaLgH+WGyk4pp2ePMzg6XH7vaIy9qNFgBiHoNAy2zsRc05/VSP
XUXUAwMkqyv1UIvZ3XW7ZcVr2Se+4H8Tg+Rklk4viNkhmqgfIGIQO2X0zxVCg8bY
fUxhtT3WYgZNw29oiU+fmnLqZXLTt56AxIN7AU2Q1lDW9VzVWO2/Z2UxIl7BqR+M
1VChnbFkDSJcun2wr09Jee7HgW4O+Yv5BUFcDHtYinHD0KiQTbfHSzy+ILA7OqSo
uQW0IexVI36qrsgASnBh4mxzgIpzR26m4eR34nPyvCoEOOPDaqxU8Gun2R6LphHs
t7xp1J9CVFoz8Rew7mJWBjh3ZAFCjdIRH5spijDJeViHjgoD4qXv+o1ekFLZqZfT
axYLPuHbWjKqNp/sScjtQypHlaylSeUSd1UUaaScNqgsYJeO/6ZyHMOapCiV68RL
GNEPoR45rin15Wjq5qbTe8k3TudxAqQyANlZH+6yxKZOOChD7l4=
=41RV
-----END PGP SIGNATURE-----


L
L
Ludovic Courtès wrote on 7 Apr 2022 18:40
(name . Denis 'GNUtoo' Carikli)(address . GNUtoo@cyberdimension.org)(address . 54728@debbugs.gnu.org)
87mtgwetjr.fsf@gnu.org
Hi,

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

Toggle quote (3 lines)
> 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.

Indeed. Fixed in 6b6fb78724869c03394d0e6dc2f50f0777f6d467 on
‘core-updates’ as discussed with Mark (mjw) a couple of days ago on IRC.

Unfortunately, until that branch is merge (most likely a few months from
now), we’ll have to use the workaround you mentioned.

Alternatively, maybe we could temporarily patch the ‘valgrind’ package
such that it has ‘--extra-debuginfo-path=…’ by default. Would you like
to give it a try?

Thanks,
Ludo’.
D
D
Denis 'GNUtoo' Carikli wrote on 15 Apr 2022 01:26
(name . Ludovic Courtès)(address . ludo@gnu.org)(address . 54728@debbugs.gnu.org)
20220415012611.6edbf92c@primarylaptop.localdomain
On Thu, 07 Apr 2022 18:40:08 +0200
Ludovic Courtès <ludo@gnu.org> wrote:

Toggle quote (1 lines)
> Hi,
Hi,

Toggle quote (6 lines)
> Unfortunately, until that branch is merge (most likely a few months
> from now), we’ll have to use the workaround you mentioned.
>
> Alternatively, maybe we could temporarily patch the ‘valgrind’ package
> such that it has ‘--extra-debuginfo-path=…’ by default. Would you
> like to give it a try?
That is a good idea. As I need it anyway[1], I've actually worked on
doing that through patching Valgrind source code to use better defaults
than /usr/lib/debug but there is a couple of things I'm unsure with my
patch:
- First it works fine in 'guix shell -C' but it still fails
in packages. Maybe I didn't patch the right Valgrind?

- Then for some reasons guix style messes up the whitespaces with the
following command:
$ ./pre-inst-env guix style -e \
'(@@ (gnu packages valgrind) valgrind/interactive)';
So I did the style by hand instead, so it might contain mistakes.

- And finally I'm not comfortable enough with Valgrind or how it's been
used in Guix. As I understand from the comment in the first Valgrind
being defined in valgrind.scm, it seems to be depended on by a lot of
packages. In addition I've not looked why there is a
valgrind/interactive or how it works yet, so someone would need to
double check my patch carefuly.

I've attached a libsamsung-ipc.scm file as I used that for testing my
patch (in addition of just running Valgrind in a Guix shell container
and while building this package it fails.

I'll send the patch as a response to this mail.

References:
-----------
[1] At the end of the day I need it to work in both standalone mode and
also in package builds as I use a guix.scm to run various
compilation and runtime for libsamsung-ipc before pushing patches
to the main branch.

Denis.
;;; Copyright © 2022 Denis Carikli <GNUtoo@cyberdimension.org> ;;; ;;; This file is free software; you can redistribute it and/or modify it ;;; under the terms of the GNU General Public License as published by ;;; the Free Software Foundation; either version 3 of the License, or (at ;;; your option) any later version. ;;; ;;; This file is distributed in the hope that it will be useful, but ;;; WITHOUT ANY WARRANTY; without even the implied warranty of ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;;; GNU General Public License for more details. ;;; ;;; You should have received a copy of the GNU General Public License. ;;; If not, see <http://www.gnu.org/licenses/>. ;;; ;;; This file is meant to test valgrind support in Guix. ;;; ;;; The libsamsung-ipc library is not ready to be packaged in general ;;; purpose distributions as right now as it requires either a vendor ;;; kernel or the compbinaison of a recent upstream kernel with on top ;;; work in progress out of tree modem drivers, out of tree ;;; libsamsung-ipc code to support theses drivers and kernel patches ;;; to support the nonfree bootloader of the Galaxy SIII ;;; (GT-I9300). Beside the library, the tools are of very limited use ;;; beside testing or reverse engineering. (use-modules (ice-9 popen) (ice-9 rdelim) (sxml ssax input-parse) ((guix licenses) #:prefix license:) (guix build-system android-ndk) (guix build-system gnu) (guix gexp) (guix git-download) (guix packages) (gnu packages android) (gnu packages autotools) (gnu packages commencement) (gnu packages curl) (gnu packages disk) (gnu packages linux) (gnu packages llvm) (gnu packages pkg-config) (gnu packages python) (gnu packages python-xyz) (gnu packages tls) (gnu packages valgrind)) (define-public libsamsung-ipc (package (name "libsamsung-ipc") ;; we use a work in progress version that has support for --with-valgrind-tests (version (git-version "0.0" "HEAD" "4d3062db15783c188d6952f7b9b794b65cd93f66")) (source (origin (method git-fetch) (uri (git-reference (url "https://git.replicant.us/replicant-next/hardware_replicant_libsamsung-ipc") (commit "4d3062db15783c188d6952f7b9b794b65cd93f66"))) (sha256 (base32 "1jzv9z5rkgcx394akf2svja586z54vhd46pvdmzm3ilmspnvjcdx")) (file-name (git-file-name name version)))) (build-system gnu-build-system) (native-inputs `(("autoreconf" ,autoconf) ("aclocal" ,automake) ("libcurl" ,curl) ("ddrescue", ddrescue) ;; ("libc:debug", (@@ (gnu packages commencement) glibc-final) "debug") ("libtool" ,libtool) ("pkgconfig" ,pkg-config) ("python" ,python) ("python-sh" ,python-sh) ("valgrind" ,valgrind))) (inputs `(("openssl" ,openssl))) (arguments `(#:phases (modify-phases %standard-phases (add-before 'build 'patch-python (lambda _ (substitute* (find-files "." ".*\\.py$") (("/usr/bin/env python") (which "python3"))) #t)) (add-after 'patch-python 'fix-valgrind (lambda _ (substitute* (find-files "." ".*\\.py$") (("'--leak-check=full',") "'-v', '--leak-check=full',")) #t)) ;; (add-after 'patch-python 'fix-valgrind ;; (lambda _ ;; (substitute* (find-files "." ".*\\.py$") ;; (("'--leak-check=full',") ;; (string-append ;; "'--leak-check=full', '--extra-debuginfo-path=" ;; (assoc-ref %build-inputs "libc:debug") ;; "/lib/debug',"))) ;; #t)) ) #:configure-flags (list "--enable-debug" "--enable-valgrind-tests"))) (synopsis "libsamsung-ipc is a free software implementation of the Samsung IPC modem protocol") (description "libsamsung-ipc is a free software implementation of the Samsung IPC modem protocol, found in many Samsung smartphones and tablets.") (home-page "https://www.replicant.us") (license license:gpl2+))) (list libsamsung-ipc)
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCAAdFiEEeC+d2+Nrp/PU3kkGX138wUF34mMFAmJYrZMACgkQX138wUF3
4mN2CQ/+No31c3weO3B+yyBBA/iShQrAKv+RYIhT/q+echeLljF5mFMInis0pa5s
31l1BP2AWYaf6sQHuw6ZTcqW46Cm8xQZwk+QzWaD9aRr7hDVlWYzmRFvOwBujuoJ
AYCd0TEB2DaaKszhxOh4doyMItRS7ozKmyand2rMiDPIOetHE6TyGQ0K0y8gXhAd
V4BtrFUGCOR5M7aJ2TpA2nBRRAeao1A9ncfbAXyCQ5L5X9cXIluyC9VgdyBM/eEi
WZ945rTJaMAMEmvCSsCRvkm/ssJ3DLqwfRSYK39jQzsZJE7qP0Z8flEQKc5EItFz
iB4Jov/bcdGC3/XKOgCyhA8R8W1WrTzuuLMdNOiQ95Pja6LiMlxIwZCxrotIVSmg
GDkw+yfc3ivlvitfaEbbD55Pyp8ylqNdLUs7dJ8+CVrTr8Eh18qIzt9pr+Bv32KD
fcWQ17ri8FkK7tDw3dORtgFPWQPZOecrOJs7l1wYL6mvl/b6y1XTW1VgaoBQ5O4V
0+rYFjQlRKrLNJfB1qcTt6VoLCnFNyg7+KWcPhbRRrU64/EaVgmTLsvZWLleb2gy
qk+3jCiGrKI+UcTE7IFeH8ii+kTNodiSaGVrEajyEBa75+r8dJBrrFsNXOq/EUkP
XngySueC6wngXhwB4RmuTinAQciG8pDkQPJD4roR+tW/AG/PrNI=
=l1aH
-----END PGP SIGNATURE-----


D
D
Denis 'GNUtoo' Carikli wrote on 15 Apr 2022 01:30
[PATCH 1/2] gnu: valgrind: impots: sort imports alphabetically
(name . Ludovic Courtès)(address . ludo@gnu.org)
20220414233012.13243-1-GNUtoo@cyberdimension.org
* gnu/packages/valgrind.scm: sort imports alphabetically

Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
---
gnu/packages/valgrind.scm | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)

Toggle diff (32 lines)
diff --git a/gnu/packages/valgrind.scm b/gnu/packages/valgrind.scm
index 1cdc0f3b71..6648f17dfa 100644
--- a/gnu/packages/valgrind.scm
+++ b/gnu/packages/valgrind.scm
@@ -5,6 +5,7 @@
;;; Copyright © 2016, 2020, 2022 Efraim Flashner <efraim@flashner.co.il>
;;; Copyright © 2018 Tobias Geerinckx-Rice <me@tobias.gr>
;;; Copyright © 2020 Marius Bakke <marius@gnu.org>
+;;; Copyright © 2022 Denis Carikli <GNUtoo@cyberdimension.org>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -22,13 +23,13 @@
;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
(define-module (gnu packages valgrind)
- #:use-module (guix packages)
- #:use-module (guix download)
#:use-module (guix build-system gnu)
+ #:use-module (guix download)
#:use-module (guix licenses)
+ #:use-module (guix packages)
+ #:use-module (gnu packages)
#:use-module (gnu packages gdb)
- #:use-module (gnu packages perl)
- #:use-module (gnu packages))
+ #:use-module (gnu packages perl))
(define-public valgrind
(package
--
2.35.1
D
D
Denis 'GNUtoo' Carikli wrote on 15 Apr 2022 01:30
[PATCH 2/2] gnu: valgrind: fix ld.so symbols not found
(name . Ludovic Courtès)(address . ludo@gnu.org)
20220414233012.13243-2-GNUtoo@cyberdimension.org
* gnu/packages/valgrind.scm (valgrind/interactive)[native-inputs]:
Add libc:debug
[arguments]: Add patch-default-debuginfo-path phase
* gnu/packages/commencement.scm (glibc-final): Export variable.

Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
---
gnu/packages/commencement.scm | 2 +-
gnu/packages/valgrind.scm | 66 +++++++++++++++++++++++++++++++----
2 files changed, 61 insertions(+), 7 deletions(-)

Toggle diff (101 lines)
diff --git a/gnu/packages/commencement.scm b/gnu/packages/commencement.scm
index e8b47fbeab..c2de02411c 100644
--- a/gnu/packages/commencement.scm
+++ b/gnu/packages/commencement.scm
@@ -3381,7 +3381,7 @@ (define gettext-boot0
(("^PROGRAMS =.*$")
"PROGRAMS =\n")))))))))
-(define glibc-final
+(define-public glibc-final
;; The final glibc, which embeds the statically-linked Bash built above.
;; Use 'package/inherit' so we get the 'replacement' of 'glibc', if any.
(package/inherit
diff --git a/gnu/packages/valgrind.scm b/gnu/packages/valgrind.scm
index 6648f17dfa..a09721071d 100644
--- a/gnu/packages/valgrind.scm
+++ b/gnu/packages/valgrind.scm
@@ -25,8 +25,10 @@
(define-module (gnu packages valgrind)
#:use-module (guix build-system gnu)
#:use-module (guix download)
+ #:use-module (guix gexp)
#:use-module (guix licenses)
#:use-module (guix packages)
+ #:use-module (guix utils)
#:use-module (gnu packages)
#:use-module (gnu packages gdb)
#:use-module (gnu packages perl))
@@ -91,12 +93,64 @@ (define-public valgrind
(properties '((hidden? . #t)))))
(define-public valgrind/interactive
- (package/inherit
- valgrind
- (inputs
- ;; GDB is needed to provide a sane default for `--db-command'.
- `(("gdb" ,gdb)))
- (properties '())))
+ (package/inherit valgrind
+ (inputs
+ ;; GDB is needed to provide a sane default for `--db-command'.
+ `(("gdb" ,gdb)
+ ("libc:debug" ,(@@ (gnu packages commencement) glibc-final) "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 'build '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")
+ (("/usr/lib/debug")
+ (string-append
+ (assoc-ref %build-inputs "libc:debug")
+ "/lib/debug")))
+ ;; We also need to account for the bigger path in
+ ;; the malloc-ed variables
+ (substitute* '
+ ("coregrind/m_debuginfo/readelf.c")
+ (("VG_\\(strlen\\)\\(buildid\\) \\+ 33")
+ (string-append
+ "VG_(strlen)(buildid) + "
+ (number->string
+ (+ (string-length
+ (string-append
+ (assoc-ref %build-inputs "libc:debug")
+ "/lib/debug"))
+ (string-length "/.build-id//.debug")
+ 1)))))
+ (substitute* '
+ ("coregrind/m_debuginfo/readelf.c")
+ ((string-append
+ "VG_\\(strlen\\)\\(objdir\\) \\+ "
+ "VG_\\(strlen\\)\\(debugname\\) \\+ 64")
+ (string-append
+ "VG_(strlen)(objdir) + VG_(strlen)(debugname) + "
+ (number->string
+ (+ (string-length
+ (string-append
+ (assoc-ref
+ %build-inputs
+ "libc:debug")
+ "/lib/debug"))
+ (string-length
+ "/usr/lib/debug")
+ 1)))))
+ #t)))))))
+ (properties '())))
(define-public valgrind-3.18
(package
--
2.35.1
L
L
Ludovic Courtès wrote on 15 Apr 2022 18:21
(name . Denis 'GNUtoo' Carikli)(address . GNUtoo@cyberdimension.org)(address . 54728@debbugs.gnu.org)
87czhi48s2.fsf@gnu.org
Hello!

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

Toggle quote (13 lines)
> (define-public valgrind/interactive
> - (package/inherit
> - valgrind
> - (inputs
> - ;; GDB is needed to provide a sane default for `--db-command'.
> - `(("gdb" ,gdb)))
> - (properties '())))
> + (package/inherit valgrind
> + (inputs
> + ;; GDB is needed to provide a sane default for `--db-command'.
> + `(("gdb" ,gdb)
> + ("libc:debug" ,(@@ (gnu packages commencement) glibc-final) "debug")))

Rather: ("libc:debug" ,(canonical-package glibc) "debug").

Toggle quote (52 lines)
> + (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 'build '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")
> + (("/usr/lib/debug")
> + (string-append
> + (assoc-ref %build-inputs "libc:debug")
> + "/lib/debug")))
> + ;; We also need to account for the bigger path in
> + ;; the malloc-ed variables
> + (substitute* '
> + ("coregrind/m_debuginfo/readelf.c")
> + (("VG_\\(strlen\\)\\(buildid\\) \\+ 33")
> + (string-append
> + "VG_(strlen)(buildid) + "
> + (number->string
> + (+ (string-length
> + (string-append
> + (assoc-ref %build-inputs "libc:debug")
> + "/lib/debug"))
> + (string-length "/.build-id//.debug")
> + 1)))))
> + (substitute* '
> + ("coregrind/m_debuginfo/readelf.c")
> + ((string-append
> + "VG_\\(strlen\\)\\(objdir\\) \\+ "
> + "VG_\\(strlen\\)\\(debugname\\) \\+ 64")
> + (string-append
> + "VG_(strlen)(objdir) + VG_(strlen)(debugname) + "
> + (number->string
> + (+ (string-length
> + (string-append
> + (assoc-ref
> + %build-inputs
> + "libc:debug")
> + "/lib/debug"))
> + (string-length
> + "/usr/lib/debug")
> + 1)))))

I find this patch-as-code snippet rather difficult to follow; it might
also break easily if minor things change in those C files.

How about making it an actual patch? In the patch, you’d have
placeholders for the store file names, like @LIBC_DEBUG_DIRECTORY@; the
phase would replace those placeholders with ‘substitute*’.

How does that sound?

Thanks,
Ludo’.
D
D
Denis 'GNUtoo' Carikli wrote on 25 Apr 2022 18:39
(name . Ludovic Courtès)(address . ludo@gnu.org)(address . 54728@debbugs.gnu.org)
20220425183909.0cbc7cd0@primarylaptop.localdomain
On Fri, 15 Apr 2022 18:21:33 +0200
Ludovic Courtès <ludo@gnu.org> wrote:
Toggle quote (1 lines)
> Hello!
Hi,

[...]
Toggle quote (6 lines)
> I find this patch-as-code snippet rather difficult to follow; it might
> also break easily if minor things change in those C files.
>
> How about making it an actual patch? In the patch, you’d have
> placeholders for the store file names, like @LIBC_DEBUG_DIRECTORY@;
> the phase would replace those placeholders with ‘substitute*’.
Thanks, I've done that and now the code is much easier to read.

Toggle quote (1 lines)
> Rather: ("libc:debug" ,(canonical-package glibc) "debug").
The issue with that is that importing "gnu packages commencement" fails
with the following error:
Toggle quote (72 lines)
> $ ./pre-inst-env guix build hello
> error: tcc: unbound variable
> hint: Did you forget a `use-modules' form?
>
> error: googletest: unbound variable
> hint: Did you forget a `use-modules' form?
>
> error: bzip2: unbound variable
> hint: Did you forget a `use-modules' form?
>
> error: binutils: unbound variable
> hint: Did you forget a `use-modules' form?
>
> error: gcc-4.9: unbound variable
> hint: Did you forget a `use-modules' form?
>
> error: xz: unbound variable
> hint: Did you forget a `use-modules' form?
>
> error: gnu-make: unbound variable
> hint: Did you forget a `use-modules' form?
>
> error: binutils: unbound variable
> hint: Did you forget a `use-modules' form?
>
> error: perl: unbound variable
> hint: Did you forget a `use-modules' form?
>
> error: coreutils: unbound variable
> hint: Did you forget a `use-modules' form?
>
> Throw to key `unbound-variable' with args `("resolve-interface" "no
> binding `~A' in module ~A" (python (gnu packages python)) #f)'.
> Backtrace: In guix/store.scm:
> 658:37 19 (thunk)
> 1320:8 18 (call-with-build-handler #<procedure 995c6f0 at guix/u?>
> ?) In guix/scripts/build.scm:
> 499:2 17 (_)
> In srfi/srfi-1.scm:
> 673:15 16 (append-map _ _ . _)
> 586:17 15 (map1 ((argument . "hello") (build-mode . 0) (# . #t) ?))
> In guix/scripts/build.scm:
> 519:31 14 (_ _)
> In gnu/packages.scm:
> 480:2 13 (%find-package "hello" "hello" #f)
> 365:6 12 (find-best-packages-by-name _ _)
> 295:56 11 (_ "hello" _)
> In unknown file:
> 10 (force #<promise #<procedure 9a81870 at
> gnu/packages.sc?>) In gnu/packages.scm:
> 242:33 9 (fold-packages #<procedure b45e1e78 at gnu/packages.sc?>
> ?) In guix/discovery.scm:
> 159:11 8 (all-modules _ #:warn _)
> In srfi/srfi-1.scm:
> 460:18 7 (fold #<procedure 9814390 at guix/discovery.scm:143:8 ?>
> ?) In guix/discovery.scm:
> 149:19 6 (_ _ ())
> 116:5 5 (scheme-modules _ _ #:warn _)
> In srfi/srfi-1.scm:
> 691:23 4 (filter-map #<procedure 98142e0 at guix/discovery.sc?> .
> #) In guix/discovery.scm:
> 124:24 3 (_ . _)
> In guix/ui.scm:
> 319:2 2 (report-unbound-variable-error _ #:frame _)
> In ice-9/boot-9.scm:
> 1685:16 1 (raise-exception _ #:continuable? _)
> 1685:16 0 (raise-exception _ #:continuable? _)
>
> ice-9/boot-9.scm:1685:16: In procedure raise-exception:
> Throw to key `match-error' with args `("match" "no matching pattern"
> (unbound-variable "resolve-interface" "no binding `~A' in module ~A"
> (python (gnu packages python)) #f))'.
So I need to not import gnu packages commencement globally.

I can also do something like that instead:
Toggle quote (4 lines)
> ("glibc:debug"
> ,((@@ (gnu packages commencement) canonical-package)
> (@@ (gnu packages commencement) glibc)) "debug")

Which form is the best?

Beside the glibc:debug input, the new patch is ready to be sent. I also
successfully managed to run tests that use valgrind transparently (by
using valgrind/interactive in the native inputs).

Denis.
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCAAdFiEEeC+d2+Nrp/PU3kkGX138wUF34mMFAmJmzq4ACgkQX138wUF3
4mPpeg/+LA9MHXMp7RlYwjHeAg9zMWOdUiLknWq6BXJ632CwUeXskeL9x0x0Baki
qwRv3wc5QfK9CipBTRLkX8065jPG4kP8IYLuEUKrEBo+00HKmDBPXC+cAw7YGk2H
+U69V1DWpDPThE6vwy0GOmFYXNUo2aMhnSpvV9jBYTKc4U/zsMueB/blp238Bol6
NzC+pgKHEywGdcKcxzoTN7/FQHco/BcmrZfO0VgfzWhcmNBNZOZetFZDgL8A5lMJ
iEFUTXXUhGl6W3Xp5PmjAwBVSUNIYS7lFUqlU3Wp/qV15HmYo+rrApht7e/pEv3k
752A47lO9JJMGHlvfFARBKyXucUSalw25j0eZDElnQMj8aFsnRE/zFlMGLBqFfl2
uIoh1G/kEQV6oJgdPF08sP8nIAOhYWOuv8vj2Xjx/ix/86qeBjQnKDIjjV2nyZJA
mI3+6ZEZfmU9eHe9Z7u1LEgJZ9cVd504Hwsiy+OpKYoPkBG3JpRH0/YUr6uh4T7V
XYpcqKv1xD99hUhbOlOJkC5OszEOzrD1swCn+GzU0juLg2zbFMnVPGbSaWqTgfaA
Z74EP3XijcHWOfSJi4AKJU36n3vj8LnrAjekFHDMWBzBsPRPFfiubc9UCJ4g31Rp
+dBQa1IrT7desPpvzUauuUfvIr4bBczELM2IsPd2kWp1CapMklk=
=Y/3V
-----END PGP SIGNATURE-----


M
M
Maxime Devos wrote on 25 Apr 2022 19:41
Re: bug#54728: [PATCH 2/2] gnu: valgrind: fix ld.so symbols not found
(address . 54728@debbugs.gnu.org)
2d69d3b032cea71f038fad9bacd7d060d323c110.camel@telenet.be
Denis 'GNUtoo' Carikli schreef op ma 25-04-2022 om 18:39 [+0200]:
Toggle quote (4 lines)
> The issue with that is that importing "gnu packages commencement"
> fails
> with the following error:

This does not work (due to import cycles I think)?
From (gnu packages commencement)

;;; To avoid circular dependencies, this module should not be imported
;;; directly from anywhere.

Instead, try using the 'canonical-package' defined in (gnu packages
base).

Greetings,
Maxime.
-----BEGIN PGP SIGNATURE-----

iI0EABYKADUWIQTB8z7iDFKP233XAR9J4+4iGRcl7gUCYmbdOBccbWF4aW1lZGV2
b3NAdGVsZW5ldC5iZQAKCRBJ4+4iGRcl7jDCAP4lNHz5/MgaYjFJWBQo0y/NLhVH
G0Y2VAh/6G4h4BpMqgEAsyiPi9pZIF3OD0vSQe3OpGG5uvEi8661BSljCVveWws=
=gSty
-----END PGP SIGNATURE-----


D
D
Denis 'GNUtoo' Carikli wrote on 26 Apr 2022 03:39
20220426013913.20117-1-GNUtoo@cyberdimension.org
Hi,

I've now managed to make a proper patch. I've used 'v2' for more
clarity.

I'll send the files used to test them in a subsequent mails.

As for the tests, I've done them in Guix system, once installed
valgrind works fine:
Toggle quote (87 lines)
> $ make check
> valgrind -v --leak-check=full ./main
> ==20324== Memcheck, a memory error detector
> ==20324== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
> ==20324== Using Valgrind-3.18.1-42b08ed5bd-20211015 and LibVEX; rerun with -h for copyright info
> ==20324== Command: ./main
> ==20324==
> --20324-- Valgrind options:
> --20324-- -v
> --20324-- --leak-check=full
> --20324-- Contents of /proc/version:
> --20324-- Linux version 5.16.20-gnu (guix@guix) (gcc (GCC) 10.3.0, GNU ld (GNU Binutils) 2.37) #1 SMP PREEMPT 1
> --20324--
> --20324-- Arch and hwcaps: X86, LittleEndian, x86-mmxext-sse1-sse2-sse3
> --20324-- Page sizes: currently 4096, max supported 4096
> --20324-- Valgrind library directory: /gnu/store/gkrqxqxs20mzxwxqpasy1q3w7a1v42w6-valgrind-3.18.1/libexec/valgrind
> --20324-- Reading syms from /gnu/store/0iapawfss4xnxls622g23qpk4mwb9ihp-glibc-2.33/lib/ld-2.33.so
> --20324-- Considering /gnu/store/wznq4d1i3znqjhcribfr2m9ljyyrsdyd-glibc-2.33-debug/lib/debug/gnu/store/0iapawfss4xnxls622g23qpk4mwb9ihp-glibc-2.33/lib/ld-2.33.so.debug ..
> --20324-- .. CRC is valid
> --20324-- Reading syms from /home/gnutoo/work/projects/guix/valgrind-test/main
> --20324-- Reading syms from /gnu/store/gkrqxqxs20mzxwxqpasy1q3w7a1v42w6-valgrind-3.18.1/libexec/valgrind/memcheck-x86-linux
> --20324-- object doesn't have a symbol table
> --20324-- object doesn't have a dynamic symbol table
> --20324-- Scheduler: using generic scheduler lock implementation.
> --20324-- Reading suppressions file: /gnu/store/gkrqxqxs20mzxwxqpasy1q3w7a1v42w6-valgrind-3.18.1/libexec/valgrind/default.supp
> ==20324== embedded gdbserver: reading from /tmp/vgdb-pipe-from-vgdb-to-20324-by-gnutoo-on-???
> ==20324== embedded gdbserver: writing to /tmp/vgdb-pipe-to-vgdb-from-20324-by-gnutoo-on-???
> ==20324== embedded gdbserver: shared mem /tmp/vgdb-pipe-shared-mem-vgdb-20324-by-gnutoo-on-???
> ==20324==
> ==20324== TO CONTROL THIS PROCESS USING vgdb (which you probably
> ==20324== don't want to do, unless you know exactly what you're doing,
> ==20324== or are doing some strange experiment):
> ==20324== /gnu/store/gkrqxqxs20mzxwxqpasy1q3w7a1v42w6-valgrind-3.18.1/libexec/valgrind/../../bin/vgdb --pid=20324 ...command...
> ==20324==
> ==20324== TO DEBUG THIS PROCESS USING GDB: start GDB like this
> ==20324== /path/to/gdb ./main
> ==20324== and then give GDB the following command
> ==20324== target remote | /gnu/store/gkrqxqxs20mzxwxqpasy1q3w7a1v42w6-valgrind-3.18.1/libexec/valgrind/../../bin/vgdb --pid=20324
> ==20324== --pid is optional if only one valgrind process is running
> ==20324==
> --20324-- REDIR: 0x4021570 (ld-linux.so.2:strlen) redirected to 0x580a1f4a (???)
> --20324-- REDIR: 0x40212d0 (ld-linux.so.2:index) redirected to 0x580a1f25 (???)
> --20324-- Reading syms from /gnu/store/gkrqxqxs20mzxwxqpasy1q3w7a1v42w6-valgrind-3.18.1/libexec/valgrind/vgpreload_core-x86-linux.so
> --20324-- object doesn't have a symbol table
> --20324-- Reading syms from /gnu/store/gkrqxqxs20mzxwxqpasy1q3w7a1v42w6-valgrind-3.18.1/libexec/valgrind/vgpreload_memcheck-x86-linux.so
> --20324-- object doesn't have a symbol table
> ==20324== WARNING: new redirection conflicts with existing -- ignoring it
> --20324-- old: 0x04021570 (strlen ) R-> (0000.0) 0x580a1f4a ???
> --20324-- new: 0x04021570 (strlen ) R-> (2007.0) 0x04043ca0 strlen
> --20324-- Reading syms from /gnu/store/r7n4snily34ld9nm4crzc0z65jr2y26c-gcc-10.3.0-lib/lib/libgcc_s.so.1
> --20324-- object doesn't have a symbol table
> --20324-- Reading syms from /gnu/store/0iapawfss4xnxls622g23qpk4mwb9ihp-glibc-2.33/lib/libc-2.33.so
> --20324-- Considering /gnu/store/wznq4d1i3znqjhcribfr2m9ljyyrsdyd-glibc-2.33-debug/lib/debug/gnu/store/0iapawfss4xnxls622g23qpk4mwb9ihp-glibc-2.33/lib/libc-2.33.so.debug ..
> --20324-- .. CRC is valid
> ==20324== WARNING: new redirection conflicts with existing -- ignoring it
> --20324-- old: 0x040f08c0 (memalign ) R-> (1011.0) 0x04043084 memalign
> --20324-- new: 0x040f08c0 (memalign ) R-> (1017.0) 0x0404303d aligned_alloc
> ==20324== WARNING: new redirection conflicts with existing -- ignoring it
> --20324-- old: 0x040f08c0 (memalign ) R-> (1011.0) 0x04043084 memalign
> --20324-- new: 0x040f08c0 (memalign ) R-> (1017.0) 0x04042ff6 aligned_alloc
> ==20324== WARNING: new redirection conflicts with existing -- ignoring it
> --20324-- old: 0x040f08c0 (memalign ) R-> (1011.0) 0x04043084 memalign
> --20324-- new: 0x040f08c0 (memalign ) R-> (1017.0) 0x0404303d aligned_alloc
> ==20324== WARNING: new redirection conflicts with existing -- ignoring it
> --20324-- old: 0x040f08c0 (memalign ) R-> (1011.0) 0x04043084 memalign
> --20324-- new: 0x040f08c0 (memalign ) R-> (1017.0) 0x04042ff6 aligned_alloc
> --20324-- REDIR: 0x40f49e0 (libc.so.6:strncasecmp) redirected to 0x40351e6 (_vgnU_ifunc_wrapper)
> --20324-- REDIR: 0x40fa870 (libc.so.6:memrchr) redirected to 0x40351e6 (_vgnU_ifunc_wrapper)
> --20324-- REDIR: 0x410df30 (libc.so.6:wcslen) redirected to 0x40351e6 (_vgnU_ifunc_wrapper)
> --20324-- REDIR: 0x410d5c0 (libc.so.6:__GI_strrchr) redirected to 0x4043730 (__GI_strrchr)
> --20324-- REDIR: 0x410da60 (libc.so.6:__GI_strlen) redirected to 0x4043c20 (__GI_strlen)
> --20324-- REDIR: 0x40efb60 (libc.so.6:malloc) redirected to 0x403e5ae (malloc)
> Hello world
> --20324-- REDIR: 0x40f0190 (libc.so.6:free) redirected to 0x40409fc (free)
> ==20324==
> ==20324== HEAP SUMMARY:
> ==20324== in use at exit: 0 bytes in 0 blocks
> ==20324== total heap usage: 1 allocs, 1 frees, 1,024 bytes allocated
> ==20324==
> ==20324== All heap blocks were freed -- no leaks are possible
> ==20324==
> ==20324== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 5 from 5)
> --20324--
> --20324-- used_suppression: 5 dl-hack3-cond-1 /gnu/store/gkrqxqxs20mzxwxqpasy1q3w7a1v42w6-valgrind-3.18.1/libexec/valgrind/default.supp:1232
> ==20324==
> ==20324== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 5 from 5)

In addition it also works fine with either valgrind/interactive or
valgrind-3.18 as dependency, when it is used in the tests of a
package.

I've used the 'make && ./pre-inst-env guix build -f
libsamsung-ipc.scm' command for that (with a libsamsung-ipc.scm that
is slightly modified since last time).

Denis.
D
D
Denis 'GNUtoo' Carikli wrote on 26 Apr 2022 03:39
[PATCH v2 1/2] gnu: valgrind: impots: sort imports alphabetically
(name . Denis 'GNUtoo' Carikli)(address . GNUtoo@cyberdimension.org)
20220426013913.20117-2-GNUtoo@cyberdimension.org
* gnu/packages/valgrind.scm: sort imports alphabetically

Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
---
gnu/packages/valgrind.scm | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)

Toggle diff (32 lines)
diff --git a/gnu/packages/valgrind.scm b/gnu/packages/valgrind.scm
index 1cdc0f3b71..6648f17dfa 100644
--- a/gnu/packages/valgrind.scm
+++ b/gnu/packages/valgrind.scm
@@ -5,6 +5,7 @@
;;; Copyright © 2016, 2020, 2022 Efraim Flashner <efraim@flashner.co.il>
;;; Copyright © 2018 Tobias Geerinckx-Rice <me@tobias.gr>
;;; Copyright © 2020 Marius Bakke <marius@gnu.org>
+;;; Copyright © 2022 Denis Carikli <GNUtoo@cyberdimension.org>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -22,13 +23,13 @@
;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
(define-module (gnu packages valgrind)
- #:use-module (guix packages)
- #:use-module (guix download)
#:use-module (guix build-system gnu)
+ #:use-module (guix download)
#:use-module (guix licenses)
+ #:use-module (guix packages)
+ #:use-module (gnu packages)
#:use-module (gnu packages gdb)
- #:use-module (gnu packages perl)
- #:use-module (gnu packages))
+ #:use-module (gnu packages perl))
(define-public valgrind
(package
--
2.35.1
D
D
Denis 'GNUtoo' Carikli wrote on 26 Apr 2022 03:39
[PATCH v2 2/2] gnu: valgrind: fix ld.so symbols not found
(name . Denis 'GNUtoo' Carikli)(address . GNUtoo@cyberdimension.org)
20220426013913.20117-3-GNUtoo@cyberdimension.org
* 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@cyberdimension.org>
---
gnu/local.mk | 3 +-
gnu/packages/commencement.scm | 2 +-
.../valgrind-fix-default-debuginfo-path.patch | 100 ++++++++++++++++++
gnu/packages/valgrind.scm | 67 +++++++++++-
4 files changed, 168 insertions(+), 4 deletions(-)
create mode 100644 gnu/packages/patches/valgrind-fix-default-debuginfo-path.patch

Toggle diff (229 lines)
diff --git a/gnu/local.mk b/gnu/local.mk
index 9bad87710c..c28efcab32 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1919,7 +1919,8 @@ dist_patch_DATA = \
%D%/packages/patches/util-linux-tests.patch \
%D%/packages/patches/util-linux-CVE-2021-3995.patch \
%D%/packages/patches/util-linux-CVE-2021-3996.patch \
- %D%/packages/patches/valgrind-enable-arm.patch \
+ %D%/packages/patches/valgrind-enable-arm.patch \
+ %D%/packages/patches/valgrind-fix-default-debuginfo-path.patch \
%D%/packages/patches/vboot-utils-fix-format-load-address.patch \
%D%/packages/patches/vboot-utils-fix-tests-show-contents.patch \
%D%/packages/patches/vboot-utils-skip-test-workbuf.patch \
diff --git a/gnu/packages/commencement.scm b/gnu/packages/commencement.scm
index 1fed8bcd6e..769139e779 100644
--- a/gnu/packages/commencement.scm
+++ b/gnu/packages/commencement.scm
@@ -3381,7 +3381,7 @@ (define gettext-boot0
(("^PROGRAMS =.*$")
"PROGRAMS =\n")))))))))
-(define glibc-final
+(define-public glibc-final
;; The final glibc, which embeds the statically-linked Bash built above.
;; Use 'package/inherit' so we get the 'replacement' of 'glibc', if any.
(package/inherit
diff --git a/gnu/packages/patches/valgrind-fix-default-debuginfo-path.patch b/gnu/packages/patches/valgrind-fix-default-debuginfo-path.patch
new file mode 100644
index 0000000000..f78dec02dc
--- /dev/null
+++ b/gnu/packages/patches/valgrind-fix-default-debuginfo-path.patch
@@ -0,0 +1,100 @@
+From a7f17b57a94e9cde6d7fa96ac86be5c4fc4f9211 Mon Sep 17 00:00:00 2001
+From: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
+Date: Sun, 24 Apr 2022 22:20:50 +0200
+Subject: [PATCH] valgrind: fix default debuginfo path
+
+Description: Workaround for missing symbol in Guix's ld.so. The
+ correct fix (not stripping all the ld.so symbols) will be done in the
+ next Guix release as it requires to recompile a lot of packages.
+
+Forwarded: not-needed
+Bug-Guix: https://issues.guix.gnu.org/54728
+Author: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
+---
+ coregrind/m_debuginfo/readelf.c | 11 ++++++-----
+ docs/xml/manual-core-adv.xml | 4 ++--
+ docs/xml/manual-core.xml | 2 +-
+ 3 files changed, 9 insertions(+), 8 deletions(-)
+
+diff --git a/coregrind/m_debuginfo/readelf.c b/coregrind/m_debuginfo/readelf.c
+index c586e3f33..947fcc500 100644
+--- a/coregrind/m_debuginfo/readelf.c
++++ b/coregrind/m_debuginfo/readelf.c
+@@ -1509,9 +1509,9 @@ DiImage* find_debug_file( struct _DebugInfo* di,
+
+ if (buildid != NULL) {
+ debugpath = ML_(dinfo_zalloc)("di.fdf.1",
+- VG_(strlen)(buildid) + 33);
++ VG_(strlen)(buildid) + DEBUGPATH_EXTRA_BYTES_1);
+
+- VG_(sprintf)(debugpath, "/usr/lib/debug/.build-id/%c%c/%s.debug",
++ VG_(sprintf)(debugpath, "DEFAULT_DEBUGINFO_PATH/.build-id/%c%c/%s.debug",
+ buildid[0], buildid[1], buildid + 2);
+
+ dimg = open_debug_file(debugpath, buildid, 0, rel_ok, NULL);
+@@ -1536,7 +1536,8 @@ DiImage* find_debug_file( struct _DebugInfo* di,
+
+ debugpath = ML_(dinfo_zalloc)(
+ "di.fdf.3",
+- VG_(strlen)(objdir) + VG_(strlen)(debugname) + 64
++ VG_(strlen)(objdir) + VG_(strlen)(debugname)
++ + VG_(strlen)("DEFAULT_DEBUGINFO_PATH/") + 1
+ + (extrapath ? VG_(strlen)(extrapath) : 0)
+ + (serverpath ? VG_(strlen)(serverpath) : 0));
+
+@@ -1561,7 +1562,7 @@ DiImage* find_debug_file( struct _DebugInfo* di,
+
+ TRY_OBJDIR_USRMERGE_OBJDIR("%s/%s");
+ TRY_OBJDIR_USRMERGE_OBJDIR("%s/.debug/%s");
+- TRY_OBJDIR_USRMERGE_OBJDIR("/usr/lib/debug%s/%s");
++ TRY_OBJDIR_USRMERGE_OBJDIR("DEFAULT_DEBUGINFO_PATH%s/%s");
+
+ if (extrapath) {
+ TRY_OBJDIR("%s%s/%s", extrapath, objdir, debugname);
+@@ -1631,7 +1632,7 @@ DiImage* find_debug_file_ad_hoc( const DebugInfo* di,
+
+ debugpath = ML_(dinfo_zalloc)(
+ "di.fdfah.3",
+- VG_(strlen)(objdir) + 64
++ VG_(strlen)(objdir) + DEBUGPATH_EXTRA_BYTES_2
+ + (extrapath ? VG_(strlen)(extrapath) : 0)
+ + (serverpath ? VG_(strlen)(serverpath) : 0));
+
+diff --git a/docs/xml/manual-core-adv.xml b/docs/xml/manual-core-adv.xml
+index 1fa801edc..a7c01d5e6 100644
+--- a/docs/xml/manual-core-adv.xml
++++ b/docs/xml/manual-core-adv.xml
+@@ -447,7 +447,7 @@ Valgrind embedded gdbserver:</para>
+ Remote debugging using | vgdb
+ relaying data between gdb and process 2418
+ Reading symbols from /lib/ld-linux.so.2...done.
+-Reading symbols from /usr/lib/debug/lib/ld-2.11.2.so.debug...done.
++Reading symbols from DEFAULT_DEBUGINFO_PATH/lib/ld-2.11.2.so.debug...done.
+ Loaded symbols for /lib/ld-linux.so.2
+ [Switching to Thread 2418]
+ 0x001f2850 in _start () from /lib/ld-linux.so.2
+@@ -475,7 +475,7 @@ Remote communication error: Resource temporarily unavailable.
+ Remote debugging using | vgdb --pid=2479
+ relaying data between gdb and process 2479
+ Reading symbols from /lib/ld-linux.so.2...done.
+-Reading symbols from /usr/lib/debug/lib/ld-2.11.2.so.debug...done.
++Reading symbols from DEFAULT_DEBUGINFO_PATH/lib/ld-2.11.2.so.debug...done.
+ Loaded symbols for /lib/ld-linux.so.2
+ [Switching to Thread 2479]
+ 0x001f2850 in _start () from /lib/ld-linux.so.2
+diff --git a/docs/xml/manual-core.xml b/docs/xml/manual-core.xml
+index dc33e1269..f6eb60086 100644
+--- a/docs/xml/manual-core.xml
++++ b/docs/xml/manual-core.xml
+@@ -1409,7 +1409,7 @@ that can report errors, e.g. Memcheck, but not Cachegrind.</para>
+ <listitem>
+ <para>By default Valgrind searches in several well-known paths
+ for debug objects, such
+- as <computeroutput>/usr/lib/debug/</computeroutput>.</para>
++ as <computeroutput>DEFAULT_DEBUGINFO_PATH/</computeroutput>.</para>
+
+ <para>However, there may be scenarios where you may wish to put
+ debug objects at an arbitrary location, such as external storage
+--
+2.35.1
+
diff --git a/gnu/packages/valgrind.scm b/gnu/packages/valgrind.scm
index 6648f17dfa..1269e07593 100644
--- a/gnu/packages/valgrind.scm
+++ b/gnu/packages/valgrind.scm
@@ -25,9 +25,12 @@
(define-module (gnu packages valgrind)
#:use-module (guix build-system gnu)
#:use-module (guix download)
+ #:use-module (guix gexp)
#:use-module (guix licenses)
#:use-module (guix packages)
+ #:use-module (guix utils)
#:use-module (gnu packages)
+ #:use-module (gnu packages base)
#:use-module (gnu packages gdb)
#:use-module (gnu packages perl))
@@ -93,9 +96,68 @@ (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)))
+ `(("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 '())))
(define-public valgrind-3.18
@@ -111,4 +173,5 @@ (define-public valgrind-3.18
(sha256
(base32
"1xgph509i6adv9w2glviw3xrmlz0dssg8992hbvxsbkp7ahrm180"))
- (patches (search-patches "valgrind-enable-arm.patch"))))))
+ (patches (search-patches "valgrind-enable-arm.patch"
+ "valgrind-fix-default-debuginfo-path.patch"))))))
--
2.35.1
D
D
Denis 'GNUtoo' Carikli wrote on 27 Apr 2022 00:37
20220427003717.7106b97a@primary_laptop
For some reasons I didn't receive a copy of the cover letter patch I
sent with git-send-email yet, so I can't reply to the cover letter, so
I'm replying to the patch instead.

In any case the patches and the cover letter are in the bug[1] report
and so as promised here's the libsamsung-ipc.scm I used for the tests.

References:
-----------

Denis.
;;; Copyright © 2022 Denis Carikli <GNUtoo@cyberdimension.org> ;;; ;;; This file is free software; you can redistribute it and/or modify it ;;; under the terms of the GNU General Public License as published by ;;; the Free Software Foundation; either version 3 of the License, or (at ;;; your option) any later version. ;;; ;;; This file is distributed in the hope that it will be useful, but ;;; WITHOUT ANY WARRANTY; without even the implied warranty of ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;;; GNU General Public License for more details. ;;; ;;; You should have received a copy of the GNU General Public License. ;;; If not, see <http://www.gnu.org/licenses/>. ;;; ;;; This file is meant to test valgrind support in Guix. ;;; ;;; The libsamsung-ipc library is not ready to be packaged in general ;;; purpose distributions as right now as it requires either a vendor ;;; kernel or the compbinaison of a recent upstream kernel with on top ;;; work in progress out of tree modem drivers, out of tree ;;; libsamsung-ipc code to support theses drivers and kernel patches ;;; to support the nonfree bootloader of the Galaxy SIII ;;; (GT-I9300). Beside the library, the tools are of very limited use ;;; beside testing or reverse engineering. (use-modules (ice-9 popen) (ice-9 rdelim) (sxml ssax input-parse) ((guix licenses) #:prefix license:) (guix build-system android-ndk) (guix build-system gnu) (guix gexp) (guix git-download) (guix packages) (gnu packages android) (gnu packages autotools) (gnu packages curl) (gnu packages disk) (gnu packages linux) (gnu packages llvm) (gnu packages pkg-config) (gnu packages python) (gnu packages python-xyz) (gnu packages tls) (gnu packages valgrind)) (define-public libsamsung-ipc (package (name "libsamsung-ipc") ;; we use a work in progress version that has support for --with-valgrind-tests (version (git-version "0.0" "HEAD" "92de58c3ecd3f6a40323161dd28f2c9ad075ca62")) (source (origin (method git-fetch) (uri (git-reference (url "https://git.replicant.us/replicant-next/hardware_replicant_libsamsung-ipc") (commit "92de58c3ecd3f6a40323161dd28f2c9ad075ca62"))) (sha256 (base32 "0glm8hvb46iq1dhhbhymckxi6lcxn5k30lywcppbs7s8r4bnkwvy")) (file-name (git-file-name name version)))) (build-system gnu-build-system) (native-inputs (list autoconf automake curl ddrescue libtool pkg-config python python-sh valgrind/interactive)) (inputs (list openssl)) (arguments `(#:phases (modify-phases %standard-phases (add-before 'build 'patch-python (lambda _ (substitute* (find-files "." ".*\\.py$") (("/usr/bin/env python") (which "python3"))) #t))) #:tests? #t #:configure-flags (list "--enable-debug" "--enable-valgrind-tests"))) (synopsis "libsamsung-ipc is a free software implementation of the Samsung IPC modem protocol") (description "libsamsung-ipc is a free software implementation of the Samsung IPC modem protocol, found in many Samsung smartphones and tablets.") (home-page "https://www.replicant.us") (license license:gpl2+))) (list libsamsung-ipc)
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCAAdFiEEeC+d2+Nrp/PU3kkGX138wUF34mMFAmJodB0ACgkQX138wUF3
4mPzNBAAjWEARL0tkLOED8Yn08ldPf3P75iZytUkwFh85+qP7hYC29dgSV9iH7LD
MsqQEqRGS1wfpfABeuP2ySkBj18clMhuR3aLSpYBjgSu4ZAmrSh1Y04JwDkLJjsd
JCTQuuv8PoS3lP3zf2VujhG562jw8EcSEpAYtFkazESH1TP/KylxUPLvXFF7r03l
ZaT48R4+WTbZIV+y3XnpNF4Rd/25PWSmEHcOf22jAHqnqgbBuwXU89iIXk0AuPbF
cP+32fjMyp12yC6+w4V8YHaQIFTrDOTW7U7Sm7IAYFgaefx2ELaxIGQ6xAAVfU7i
iu8zBmkOutgS1ZaF650QBO+aSxiz2AftY27b+JDG9YtgP1aokgtLneTSnIJRuhKt
2wIckloMd5OBsj+o3hjOto6QUvEUZ3uH6YonQctvUvtqrGrD1MJ7DTxoZGv7eTWg
Mb2/fNsdv0Klj2lTxOkyUVxIkozBCaeMPkafRZFyFh5ZVkX0/G6cKE8xpcJfKxbX
Kb6THRS8Rde5tYQdgcdnGo8htJaCZ7Xz0XYvg+SZKLgXjk8CD9gKWfLLlQFyOxe+
X1D5AXUA3TEWADV+3yCp7eeHUpcxkW2P4g+sL10lBM1CT9ClbjEMYDmkXdhk6T3f
l/xpn5Y3qMCf9dA+rotJn/nkDz2sZsc4ASJjWTC5UpzQV9XXIJI=
=c/ld
-----END PGP SIGNATURE-----


D
D
Denis 'GNUtoo' Carikli wrote on 6 May 2022 22:16
20220506221622.6a49ac7c@primarylaptop.localdomain
Hi,

Did you manage to receive the patches, or were they lost somehow[1]?

At least I see them on https://issues.guix.gnu.org/54728.

References:
-----------
[1]Personally for some reason I didn't receive a copy of the patches I
sent through git-send-email in my mail.

Denis.
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCAAdFiEEeC+d2+Nrp/PU3kkGX138wUF34mMFAmJ1ghYACgkQX138wUF3
4mOq4A//c7ixVm32ge7s9l134keynIJ5efAx9arNK7dWIhkb9VjHAMVlfcuqSe5T
veFtIltjbww9ohCvcI5URR8oTVj4BEaoKGdE+l1+3R5i6vDPEyNh3kQw8vZaCc7K
vRsEvgfqm17vTpxSsY57ee5tJ2oJRQRzc+uv9l9Q0vp1TazXF6qwsvFUdwP9W74g
6Xk/edwtLSkie1TmWGw8YveDP/P9crQZ4fWzgPHCju0ZGNAqukl8Z8DopjUlL4g+
zNGzDZi1RYb1IgQDjVqRuRDUQjy9gZWZd5UJa40u8xHfKiBczPbPwk5duBqZnfqR
NTgh5ASC2VfVE7lRYQUne9Rn5WtI45wC03+zHwcpxJE5nCsVS/M7oGVZJ6b2ae26
7GeWlKixgh8u6ZiQmZ9kowQSO4zfhVvhUtw8jTmBBRwdBb8AsCbEOCzvUv4amyAc
wJ5lQof8pR+pNPQC2whc8qDoyHtBrYpxdw8L8IwmaUDJCpZfDIlI1rHKhnSFp5GC
dX34TMevZXgwDLwzelKHcCK84MUuR3fk8V7WLXIvNbUYG2u0gwCp4D5E+1EupgVi
Nw9JG2EdvArtzt1cxlIxNc5Z4jzCLULHPWOiO+P235foFrn8ItncekR2xDM3qQ/2
4PgCWcdeCCkMDcHEAgh6qOQt1l+8tRGL0Hok3Zgb8G03Kxis0cI=
=wFb6
-----END PGP SIGNATURE-----


M
M
Maxime Devos wrote on 6 May 2022 22:20
16df04c6e52f074ab68ccabb63be2db985301278.camel@telenet.be
Denis 'GNUtoo' Carikli schreef op vr 06-05-2022 om 22:16 [+0200]:
Toggle quote (7 lines)
> Hi,
>
> Did you manage to receive the patches, or were they lost somehow[1]?
>
> At least I see them on https://issues.guix.gnu.org/54728 .
>

I've received ‘https://issues.guix.gnu.org/54728#11’(at least,
received it now, via issues.guix.gnu.org) but this is way outside my
expertise and I'm currently to busy for reviewing something like that.

Greetings,
Maxime.
-----BEGIN PGP SIGNATURE-----

iI0EABYKADUWIQTB8z7iDFKP233XAR9J4+4iGRcl7gUCYnWDAhccbWF4aW1lZGV2
b3NAdGVsZW5ldC5iZQAKCRBJ4+4iGRcl7kDZAP9H0T/ZXXqJKavn9N+XPQRFoLPx
qILPlbpTD57TXSUZTgEAmDi1Q8pBwTVgo9FmPTL3IlZfQi2+dKVyExp96fs6jwY=
=s70b
-----END PGP SIGNATURE-----


L
L
Ludovic Courtès wrote on 9 May 2022 11:24
Re: bug#54728: Valgrind not working out of the box due to stripped ld.so
(name . Denis 'GNUtoo' Carikli)(address . GNUtoo@cyberdimension.org)
87czgnrrc3.fsf_-_@gnu.org
Hi Denis,

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

Toggle quote (10 lines)
> * 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@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’.
Attachment: file
Closed
?
Your comment

This issue is archived.

To comment on this conversation send an email to 54728@debbugs.gnu.org

To respond to this issue using the mumi CLI, first switch to it
mumi current 54728
Then, you may apply the latest patchset in this issue (with sign off)
mumi am -- -s
Or, compose a reply to this issue
mumi compose
Or, send patches to this issue
mumi send-email *.patch