Skip to content

Commit 3a440b6

Browse files
authored
gh-160388: Load the copied library in the deleted-mapping test (#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.
1 parent b77cb89 commit 3a440b6

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

2389-
with os_helper.temp_dir() as lib_dir:
2390-
copied_libpython = os.path.join(lib_dir, instsoname)
2389+
with os_helper.temp_dir(os_helper.TESTFN) as lib_dir:
2390+
copied_libpython = os.path.abspath(
2391+
os.path.join(lib_dir, instsoname))
23912392
shutil.copy2(source_libpython, copied_libpython)
23922393
if ldlibrary != instsoname:
23932394
os.symlink(instsoname, os.path.join(lib_dir, ldlibrary))
23942395

23952396
env = os.environ.copy()
2396-
ld_library_path = env.get('LD_LIBRARY_PATH')
2397-
env['LD_LIBRARY_PATH'] = lib_dir if not ld_library_path else (
2398-
lib_dir + os.pathsep + ld_library_path)
2397+
# Preload the copy even when `RPATH` overrides `LD_LIBRARY_PATH`.
2398+
# Use a relative path to avoid spaces or colons in parent directories.
2399+
preload = os.path.join(os.curdir, lib_dir, instsoname)
2400+
ld_preload = env.get('LD_PRELOAD')
2401+
env['LD_PRELOAD'] = preload if not ld_preload else (
2402+
preload + os.pathsep + ld_preload)
23992403

24002404
self._run_remote_exec_with_deleted_mapping(copied_libpython,
24012405
env=env)

0 commit comments

Comments
 (0)