Skip to content

Commit 153607e

Browse files
[3.15] gh-98894: Fix DTrace test_check_probes for shared builds (GH-151122) (#151235)
gh-98894: Fix DTrace test_check_probes for shared builds (GH-151122) When building with --enable-shared, the SystemTap/DTrace notes live in libpython. Add detection logic to be used by readelf. Force the C locale on readelf output. (cherry picked from commit 3a08e93) Co-authored-by: stratakis <cstratak@redhat.com>
1 parent 0b6adeb commit 153607e

1 file changed

Lines changed: 28 additions & 1 deletion

File tree

Lib/test/test_dtrace.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,11 +378,14 @@ def setUpClass(cls):
378378
def get_readelf_version():
379379
try:
380380
cmd = ["readelf", "--version"]
381+
# Force the C locale to disable localization.
382+
env = dict(os.environ, LC_ALL="C")
381383
proc = subprocess.Popen(
382384
cmd,
383385
stdout=subprocess.PIPE,
384386
stderr=subprocess.PIPE,
385387
universal_newlines=True,
388+
env=env,
386389
)
387390
with proc:
388391
version, stderr = proc.communicate()
@@ -405,12 +408,36 @@ def get_readelf_version():
405408
return int(match.group(1)), int(match.group(2))
406409

407410
def get_readelf_output(self):
408-
command = ["readelf", "-n", sys.executable]
411+
binary = sys.executable
412+
if sysconfig.get_config_var("Py_ENABLE_SHARED"):
413+
lib_dir = sysconfig.get_config_var("LIBDIR")
414+
if not lib_dir or sysconfig.is_python_build():
415+
lib_dir = os.path.abspath(os.path.dirname(sys.executable))
416+
417+
lib_names = []
418+
for name in (
419+
sysconfig.get_config_var("INSTSONAME"),
420+
sysconfig.get_config_var("LDLIBRARY"),
421+
):
422+
if name and name not in lib_names:
423+
lib_names.append(name)
424+
425+
if lib_dir:
426+
for name in lib_names:
427+
libpython_path = os.path.join(lib_dir, name)
428+
if os.path.exists(libpython_path):
429+
binary = libpython_path
430+
break
431+
432+
command = ["readelf", "-n", binary]
433+
# Force the C locale to disable localization.
434+
env = dict(os.environ, LC_ALL="C")
409435
stdout, _ = subprocess.Popen(
410436
command,
411437
stdout=subprocess.PIPE,
412438
stderr=subprocess.STDOUT,
413439
universal_newlines=True,
440+
env=env,
414441
).communicate()
415442
return stdout
416443

0 commit comments

Comments
 (0)