From 1c181b39a9d76c818cf5f9884a69f8927897cd34 Mon Sep 17 00:00:00 2001 From: stratakis Date: Tue, 1 Sep 2026 08:22:05 +0200 Subject: [PATCH] gh-156703: Set LD_LIBRARY_PATH in SystemTap trace commands (GH-156424) Prefix commands passed to stap -c with LD_LIBRARY_PATH via env, when probes reside in libpython. This allows the interpreter to find libpython when staprun does not preserve the loader path. (cherry picked from commit faf4e524356634ac95d9de3f7f115603f7440a9b) Co-authored-by: stratakis --- Lib/test/test_dtrace.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Lib/test/test_dtrace.py b/Lib/test/test_dtrace.py index 4967a18053057b3..126e47a20cb7c61 100644 --- a/Lib/test/test_dtrace.py +++ b/Lib/test/test_dtrace.py @@ -229,6 +229,17 @@ def render_script(self, filename): return script.replace(self.PROBE_PLACEHOLDER, self.python_probe()) + def generate_trace_command(self, script_file, subcommand=None): + probe_binary = get_probe_binary() + if subcommand and probe_binary != sys.executable: + library_path = os.path.dirname(probe_binary) + if existing_path := os.environ.get("LD_LIBRARY_PATH"): + library_path = os.pathsep.join((library_path, existing_path)) + env = shlex.join(["env", f"LD_LIBRARY_PATH={library_path}"]) + subcommand = f"{env} {subcommand}" + + return super().generate_trace_command(script_file, subcommand) + def trace(self, script_file, subcommand=None, *, timeout=None, check_returncode=False): with tempfile.NamedTemporaryFile(