python-build-standalone icon indicating copy to clipboard operation
python-build-standalone copied to clipboard

Python scripts do not work under valgrind, including codspeed

Open geofft opened this issue 10 months ago • 1 comments

This is https://bugs.kde.org/show_bug.cgi?id=396415 , but opening it here just for tracking/visibility. When running a script under valgrind mis-reports /proc/self/exe as the path to the script itself instead of the path to the script interpreter. This means that, at least on glibc/Linux, the $ORIGIN-relative library paths that are used by python-build-standalone don't get resolved correctly for scripts installed in a different directory to the Python interpreter (notably, those installed in a venv), and the Python interpreter fails to launch.

The minimal reproduction is something like valgrind --tool=none some/venv/bin/pytest (or just plain valgrind).

This was reported specifically as codspeed run pytest (invoked by CodSpeedHQ/action in GHA) not working. CodSpeed internally uses valgrind.

A workaround is to invoke the interpreter directly instead of using a script, either with an appropriate python -m command (e.g. python -m pytest), or by passing the script as an argument to the interpreter (e.g., python some/venv/bin/pytest).

geofft avatar Jan 30 '25 00:01 geofft

Fixed in upstream valgrind: https://sourceware.org/git/?p=valgrind.git;a=commitdiff;h=1fefba79021779d840bbf8cebc43e40c74b40f31

I tested it and it seems to work, and I opened CodSpeedHQ/valgrind-codspeed#1 requesting that they backport this one patch, because from valgrind-announce archives, they seem to go anywhere from six months to a couple of years between releases.

geofft avatar Feb 06 '25 21:02 geofft