Skip to content

Commit 53002b9

Browse files
[3.14] gh-160388: Load the copied library in the deleted-mapping test (GH-160396) (#160516)
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 6600984 commit 53002b9

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
@@ -2333,16 +2333,20 @@ def test_remote_exec_deleted_libpython(self):
23332333
if not os.path.exists(source_libpython):
23342334
self.skipTest(f'{source_libpython!r} does not exist')
23352335

2336-
with os_helper.temp_dir() as lib_dir:
2337-
copied_libpython = os.path.join(lib_dir, instsoname)
2336+
with os_helper.temp_dir(os_helper.TESTFN) as lib_dir:
2337+
copied_libpython = os.path.abspath(
2338+
os.path.join(lib_dir, instsoname))
23382339
shutil.copy2(source_libpython, copied_libpython)
23392340
if ldlibrary != instsoname:
23402341
os.symlink(instsoname, os.path.join(lib_dir, ldlibrary))
23412342

23422343
env = os.environ.copy()
2343-
ld_library_path = env.get('LD_LIBRARY_PATH')
2344-
env['LD_LIBRARY_PATH'] = lib_dir if not ld_library_path else (
2345-
lib_dir + os.pathsep + ld_library_path)
2344+
# Preload the copy even when `RPATH` overrides `LD_LIBRARY_PATH`.
2345+
# Use a relative path to avoid spaces or colons in parent directories.
2346+
preload = os.path.join(os.curdir, lib_dir, instsoname)
2347+
ld_preload = env.get('LD_PRELOAD')
2348+
env['LD_PRELOAD'] = preload if not ld_preload else (
2349+
preload + os.pathsep + ld_preload)
23462350

23472351
self._run_remote_exec_with_deleted_mapping(copied_libpython,
23482352
env=env)

0 commit comments

Comments
 (0)