From 82d520840107d4dae02f6ec4814114e5a4902b9f Mon Sep 17 00:00:00 2001 From: Charalampos Stratakis Date: Tue, 9 Jun 2026 06:03:49 +0200 Subject: [PATCH 1/2] gh-98894: Fix DTrace test_check_probes for shared builds When building with --enable-shared, the SystemTap/DTrace notes live in libpython. Add detection logic to be used by readelf. --- Lib/test/test_dtrace.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_dtrace.py b/Lib/test/test_dtrace.py index 61320a472f3e02..710277a7d2e9b6 100644 --- a/Lib/test/test_dtrace.py +++ b/Lib/test/test_dtrace.py @@ -405,7 +405,28 @@ def get_readelf_version(): return int(match.group(1)), int(match.group(2)) def get_readelf_output(self): - command = ["readelf", "-n", sys.executable] + binary = sys.executable + if sysconfig.get_config_var("Py_ENABLE_SHARED"): + lib_dir = sysconfig.get_config_var("LIBDIR") + if not lib_dir or sysconfig.is_python_build(): + lib_dir = os.path.abspath(os.path.dirname(sys.executable)) + + lib_names = [] + for name in ( + sysconfig.get_config_var("INSTSONAME"), + sysconfig.get_config_var("LDLIBRARY"), + ): + if name and name not in lib_names: + lib_names.append(name) + + if lib_dir: + for name in lib_names: + libpython_path = os.path.join(lib_dir, name) + if os.path.exists(libpython_path): + binary = libpython_path + break + + command = ["readelf", "-n", binary] stdout, _ = subprocess.Popen( command, stdout=subprocess.PIPE, From cb21249c0006ebc63ad2f2bb8d9b36c46872b779 Mon Sep 17 00:00:00 2001 From: Charalampos Stratakis Date: Tue, 9 Jun 2026 22:57:18 +0200 Subject: [PATCH 2/2] Force the C locale on readelf output --- Lib/test/test_dtrace.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Lib/test/test_dtrace.py b/Lib/test/test_dtrace.py index 710277a7d2e9b6..6286b6d21b572e 100644 --- a/Lib/test/test_dtrace.py +++ b/Lib/test/test_dtrace.py @@ -378,11 +378,14 @@ def setUpClass(cls): def get_readelf_version(): try: cmd = ["readelf", "--version"] + # Force the C locale to disable localization. + env = dict(os.environ, LC_ALL="C") proc = subprocess.Popen( cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, + env=env, ) with proc: version, stderr = proc.communicate() @@ -427,11 +430,14 @@ def get_readelf_output(self): break command = ["readelf", "-n", binary] + # Force the C locale to disable localization. + env = dict(os.environ, LC_ALL="C") stdout, _ = subprocess.Popen( command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True, + env=env, ).communicate() return stdout