Skip to content

Commit aaf6baf

Browse files
authored
fix: respect DT_NEEDED entries order in lddtree (#586)
1 parent cc13f53 commit aaf6baf

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

src/auditwheel/lddtree.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class DynamicLibrary:
7575
path: str | None
7676
realpath: Path | None
7777
platform: Platform | None = None
78-
needed: frozenset[str] = frozenset()
78+
needed: tuple[str, ...] = ()
7979

8080

8181
@dataclass(frozen=True)
@@ -85,7 +85,7 @@ class DynamicExecutable:
8585
path: str
8686
realpath: Path
8787
platform: Platform
88-
needed: frozenset[str]
88+
needed: tuple[str, ...]
8989
rpath: tuple[str, ...]
9090
runpath: tuple[str, ...]
9191
libraries: dict[str, DynamicLibrary]
@@ -447,7 +447,7 @@ def ldd(
447447

448448
interpreter: str | None = None
449449
libc: Libc | None = None
450-
needed: set[str] = set()
450+
needed: list[str] = []
451451
rpaths: list[str] = []
452452
runpaths: list[str] = []
453453

@@ -496,7 +496,7 @@ def ldd(
496496
elif t.entry.d_tag == "DT_RUNPATH":
497497
runpaths = parse_ld_paths(t.runpath, path=str(path), root=root)
498498
elif t.entry.d_tag == "DT_NEEDED":
499-
needed.add(t.needed)
499+
needed.append(t.needed)
500500
if runpaths:
501501
# If both RPATH and RUNPATH are set, only the latter is used.
502502
rpaths = []
@@ -586,7 +586,7 @@ def ldd(
586586
str(path) if display is None else display,
587587
path,
588588
platform,
589-
frozenset(needed - _excluded_libs),
589+
tuple(soname for soname in needed if soname not in _excluded_libs),
590590
tuple(rpaths),
591591
tuple(runpaths),
592592
_all_libs,

src/auditwheel/policy/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import logging
55
import re
66
from collections import defaultdict
7-
from collections.abc import Generator
7+
from collections.abc import Generator, Iterable
88
from dataclasses import dataclass
99
from pathlib import Path
1010
from typing import Any
@@ -192,7 +192,7 @@ def lddtree_external_references(
192192
self, lddtree: DynamicExecutable, wheel_path: Path
193193
) -> dict[str, ExternalReference]:
194194
def filter_libs(
195-
libs: frozenset[str], whitelist: frozenset[str]
195+
libs: Iterable[str], whitelist: frozenset[str]
196196
) -> Generator[str]:
197197
for lib in libs:
198198
if "ld-linux" in lib or lib in ["ld64.so.2", "ld64.so.1"]:
@@ -232,7 +232,7 @@ def get_req_external(libs: set[str], whitelist: frozenset[str]) -> set[str]:
232232
# whitelist is the complete set of all libraries. so nothing
233233
# is considered "external" that needs to be copied in.
234234
whitelist = p.whitelist
235-
blacklist_libs = set(p.blacklist.keys()) & lddtree.needed
235+
blacklist_libs = set(p.blacklist.keys()) & set(lddtree.needed)
236236
blacklist_reduced = {k: p.blacklist[k] for k in blacklist_libs}
237237
blacklist = filter_undefined_symbols(
238238
lddtree.realpath, blacklist_reduced

tests/unit/test_policy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def test_filter_libs(self):
187187
platform=Platform(
188188
"", 64, True, "EM_X86_64", Architecture.x86_64, None, None
189189
),
190-
needed=frozenset(libs),
190+
needed=tuple(libs),
191191
libraries={
192192
lib: DynamicLibrary(lib, f"/path/to/{lib}", Path(f"/path/to/{lib}"))
193193
for lib in libs

0 commit comments

Comments
 (0)