From 2358acb4a27da39dca44f8a110776406843726b3 Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Fri, 23 Oct 2026 14:52:46 -0700 Subject: [PATCH] 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 3a440b65695615e9fd9912342b79cdd54fced0d2) Co-authored-by: Zanie Blue --- Lib/test/test_sys.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py index 7dbb10526095e8..c571e04c8a1f94 100644 --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -2367,16 +2367,20 @@ def test_remote_exec_deleted_libpython(self): if not os.path.exists(source_libpython): self.skipTest(f'{source_libpython!r} does not exist') - with os_helper.temp_dir() as lib_dir: - copied_libpython = os.path.join(lib_dir, instsoname) + with os_helper.temp_dir(os_helper.TESTFN) as lib_dir: + copied_libpython = os.path.abspath( + os.path.join(lib_dir, instsoname)) shutil.copy2(source_libpython, copied_libpython) if ldlibrary != instsoname: os.symlink(instsoname, os.path.join(lib_dir, ldlibrary)) env = os.environ.copy() - ld_library_path = env.get('LD_LIBRARY_PATH') - env['LD_LIBRARY_PATH'] = lib_dir if not ld_library_path else ( - lib_dir + os.pathsep + ld_library_path) + # Preload the copy even when `RPATH` overrides `LD_LIBRARY_PATH`. + # Use a relative path to avoid spaces or colons in parent directories. + preload = os.path.join(os.curdir, lib_dir, instsoname) + ld_preload = env.get('LD_PRELOAD') + env['LD_PRELOAD'] = preload if not ld_preload else ( + preload + os.pathsep + ld_preload) self._run_remote_exec_with_deleted_mapping(copied_libpython, env=env)