Skip to content

Commit db7ec46

Browse files
[3.15] gh-160388: Load the copied library in the deleted-mapping test (GH-160396) (#160515)
gh-160388: Load the copied library in the deleted-mapping test (GH-160396) The deleted-`libpython` mapping test uses `LD_LIBRARY_PATH` to load a temporary copy of the library. On glibc, an interpreter's `DT_RPATH` can take precedence and load a different copy, so the test fails because the temporary copy was not mapped. Preload the temporary library explicitly so the subprocess maps the file that the test removes. Create the copy beneath the working directory and preload it through a relative path, since `LD_PRELOAD` treats spaces and colons as separators. (cherry picked from commit 3a440b6) Co-authored-by: Zanie Blue <contact@zanie.dev>
1 parent b8a5478 commit db7ec46

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

‎Lib/test/test_sys.py‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2367,16 +2367,20 @@ def test_remote_exec_deleted_libpython(self):
23672367
if not os.path.exists(source_libpython):
23682368
self.skipTest(f'{source_libpython!r} does not exist')
23692369

2370-
with os_helper.temp_dir() as lib_dir:
2371-
copied_libpython = os.path.join(lib_dir, instsoname)
2370+
with os_helper.temp_dir(os_helper.TESTFN) as lib_dir:
2371+
copied_libpython = os.path.abspath(
2372+
os.path.join(lib_dir, instsoname))
23722373
shutil.copy2(source_libpython, copied_libpython)
23732374
if ldlibrary != instsoname:
23742375
os.symlink(instsoname, os.path.join(lib_dir, ldlibrary))
23752376

23762377
env = os.environ.copy()
2377-
ld_library_path = env.get('LD_LIBRARY_PATH')
2378-
env['LD_LIBRARY_PATH'] = lib_dir if not ld_library_path else (
2379-
lib_dir + os.pathsep + ld_library_path)
2378+
# Preload the copy even when `RPATH` overrides `LD_LIBRARY_PATH`.
2379+
# Use a relative path to avoid spaces or colons in parent directories.
2380+
preload = os.path.join(os.curdir, lib_dir, instsoname)
2381+
ld_preload = env.get('LD_PRELOAD')
2382+
env['LD_PRELOAD'] = preload if not ld_preload else (
2383+
preload + os.pathsep + ld_preload)
23802384

23812385
self._run_remote_exec_with_deleted_mapping(copied_libpython,
23822386
env=env)

0 commit comments

Comments
 (0)