Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/auditwheel/elfutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,19 @@ def elf_read_rpaths(fn: Path) -> dict[str, list[str]]:

for t in section.iter_tags():
if t.entry.d_tag == "DT_RPATH":
result["rpaths"] = parse_ld_paths(t.rpath, root="/", path=str(fn))
result["rpaths"] = parse_ld_paths(
t.rpath,
root="/",
path=str(fn),
keep_non_exist=True,
)
elif t.entry.d_tag == "DT_RUNPATH":
result["runpaths"] = parse_ld_paths(t.runpath, root="/", path=str(fn))
result["runpaths"] = parse_ld_paths(
t.runpath,
root="/",
path=str(fn),
keep_non_exist=True,
)
Comment on lines 119 to +132
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new behavior (preserving non-existent RPATH/RUNPATH entries by passing keep_non_exist=True) is not currently covered by unit tests. Please add a test that exercises elf_read_rpaths when .dynamic contains DT_RPATH/DT_RUNPATH tags and asserts parse_ld_paths is called with keep_non_exist=True (or that non-existent paths are retained).

Copilot uses AI. Check for mistakes.

return result

Expand Down
11 changes: 9 additions & 2 deletions src/auditwheel/lddtree.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,12 @@ def dedupe(items: list[str]) -> list[str]:
return [seen.setdefault(x, x) for x in items if x not in seen]


def parse_ld_paths(str_ldpaths: str, path: str, root: str = "") -> list[str]:
def parse_ld_paths(
str_ldpaths: str,
path: str,
root: str = "",
keep_non_exist: bool = False, # noqa: FBT001, FBT002
) -> list[str]:
"""Parse the colon-delimited list of paths and apply ldso rules to each

Note the special handling as dictated by the ldso:
Expand All @@ -229,6 +234,8 @@ def parse_ld_paths(str_ldpaths: str, path: str, root: str = "") -> list[str]:
The path to prepend to all paths found
path
The object actively being parsed (used for $ORIGIN)
keep_non_exist
Do not eliminate non-exist rpath from result
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new keep_non_exist docstring text has a grammar issue (“non-exist rpath”). Consider rephrasing to “non-existent rpaths” (and it applies to RUNPATH too).

Suggested change
Do not eliminate non-exist rpath from result
Do not eliminate non-existent rpaths from the result

Copilot uses AI. Check for mistakes.

Returns
-------
Expand All @@ -245,7 +252,7 @@ def parse_ld_paths(str_ldpaths: str, path: str, root: str = "") -> list[str]:
else:
ldpath_ = root + ldpath
ldpaths.append(normpath(ldpath_))
return [p for p in dedupe(ldpaths) if os.path.isdir(p)]
return [p for p in dedupe(ldpaths) if keep_non_exist or os.path.isdir(p)]


@functools.lru_cache
Expand Down
26 changes: 25 additions & 1 deletion tests/unit/test_repair.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from unittest.mock import call, patch

from auditwheel.patcher import Patchelf
from auditwheel.repair import append_rpath_within_wheel
from auditwheel.repair import append_rpath_within_wheel, copylib


@patch("auditwheel.patcher._verify_patchelf")
Expand Down Expand Up @@ -115,3 +115,27 @@ def test_append_rpath_ignore_relative(self, check_call, check_output, _): # noq

assert check_output.call_args_list == check_output_expected_args
assert check_call.call_args_list == check_call_expected_args


@patch("auditwheel.patcher._verify_patchelf")
@patch("auditwheel.patcher.check_output")
@patch("auditwheel.patcher.check_call")
class TestCopylib:
@patch("auditwheel.repair.elf_read_rpaths")
def test_nonexistent_rpath(self, elf_read_rpaths, check_call, _0, _1, tmp_path): # noqa: PT019
# When a library has a non-existent runpath, copylib should still
# call set_rpath to replace it with $ORIGIN
patcher = Patchelf()
src_path = tmp_path / "b.so"
src_path.write_bytes(b"\x00")
dest_dir = tmp_path / "dest"
dest_dir.mkdir()
elf_read_rpaths.return_value = {"rpaths": [], "runpaths": ["/nonexistent/path"]}

copylib(src_path, dest_dir, patcher)

elf_read_rpaths.assert_called_once_with(src_path)
dest_path = next(dest_dir.iterdir())
check_call.assert_any_call(
["patchelf", "--force-rpath", "--set-rpath", "$ORIGIN", dest_path],
)