Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add libz.so.1 to whitelisted libraries #334

Merged
merged 4 commits into from
Sep 15, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
24 changes: 24 additions & 0 deletions auditwheel/elfutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,27 @@ def is_subdir(path: str, directory: str) -> bool:
if relative.startswith(os.pardir):
return False
return True


def filter_undefined_symbols(
path: str, symbols: Dict[str, List[str]]
) -> Dict[str, List[str]]:
if not symbols:
return {}
undef_symbols = set("*")
with open(path, "rb") as f:
elf = ELFFile(f)
section = elf.get_section_by_name(".dynsym")
if section is not None:
# look for all undef symbols
for sym in section.iter_symbols():
if sym["st_shndx"] == "SHN_UNDEF":
undef_symbols.add(sym.name)
Comment on lines +146 to +151
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: This could be made into a utility function to find undefined symbols. That would make this function more readable as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

will do.

Copy link
Member Author

Choose a reason for hiding this comment

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

done


result = {}
for lib in symbols:
intersection = set(symbols[lib]) & undef_symbols
mayeut marked this conversation as resolved.
Show resolved Hide resolved
if intersection:
result[lib] = sorted(intersection)

return result
7 changes: 7 additions & 0 deletions auditwheel/main_repair.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@ def execute(args, p):
)
p.error(msg)

if reqd_tag > get_priority_by_name(wheel_abi.blacklist_tag):
msg = (
'cannot repair "%s" to "%s" ABI because it depends on '
"black-listed symbols." % (args.WHEEL_FILE, args.PLAT)
)
p.error(msg)

abis = [policy["name"]] + policy["aliases"]
if not args.ONLY_PLAT:
if reqd_tag < get_priority_by_name(wheel_abi.overall_tag):
Expand Down
30 changes: 22 additions & 8 deletions auditwheel/main_show.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,26 @@ def execute(args, p):

for p in sorted(load_policies(), key=lambda p: p["priority"]):
if p["priority"] > get_priority_by_name(winfo.overall_tag):
printp(
(
'In order to achieve the tag platform tag "%s" '
"the following shared library dependencies "
"will need to be eliminated:"
libs = winfo.external_refs[p["name"]]["libs"]
if len(libs):
printp(
(
'In order to achieve the tag platform tag "%s" '
"the following shared library dependencies "
"will need to be eliminated:"
)
% p["name"]
)
% p["name"]
)
printp(", ".join(sorted(winfo.external_refs[p["name"]]["libs"].keys())))
printp(", ".join(sorted(libs.keys())))
blacklist = winfo.external_refs[p["name"]]["blacklist"]
if len(blacklist):
printp(
(
'In order to achieve the tag platform tag "%s" '
"the following black-listed symbol dependencies "
"will need to be eliminated:"
)
% p["name"]
)
for key in sorted(blacklist.keys()):
printp(f"From {key}: " + ", ".join(sorted(blacklist[key])))
12 changes: 10 additions & 2 deletions auditwheel/policy/external_references.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import re
from typing import Any, Dict, Generator, Set

from ..elfutils import is_subdir
from ..elfutils import filter_undefined_symbols, is_subdir
from . import load_policies

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -45,13 +45,17 @@ def get_req_external(libs: Set[str], whitelist: Set[str]) -> Set[str]:
ret = {} # type: Dict[str, Dict[str, Any]]
for p in policies:
needed_external_libs = set() # type: Set[str]
blacklist = {}

if not (p["name"] == "linux" and p["priority"] == 0):
# special-case the generic linux platform here, because it
# doesn't have a whitelist. or, you could say its
# whitelist is the complete set of all libraries. so nothing
# is considered "external" that needs to be copied in.
whitelist = set(p["lib_whitelist"])
blacklist_libs = set(p["blacklist"].keys()) & set(lddtree["needed"])
blacklist = {k: p["blacklist"][k] for k in blacklist_libs}
blacklist = filter_undefined_symbols(lddtree["realpath"], blacklist)
needed_external_libs = get_req_external(
set(filter_libs(lddtree["needed"], whitelist)), whitelist
)
Expand All @@ -66,5 +70,9 @@ def get_req_external(libs: Set[str], whitelist: Set[str]) -> Set[str]:
log.debug("RPATH FTW: %s", lib)
continue
pol_ext_deps[lib] = lddtree["libs"][lib]["realpath"]
ret[p["name"]] = {"libs": pol_ext_deps, "priority": p["priority"]}
ret[p["name"]] = {
"libs": pol_ext_deps,
"priority": p["priority"],
"blacklist": blacklist,
}
return ret
Loading