Skip to content

Commit

Permalink
adapt for api changes in py-lief 0.15 (#5565)
Browse files Browse the repository at this point in the history
* adapt for api changes in py-lief 0.15

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* make rpath tests work with either new or old lief

add news file

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
tkelman and pre-commit-ci[bot] authored Jan 8, 2025
1 parent b8724c6 commit 57c3397
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
19 changes: 11 additions & 8 deletions conda_build/os_utils/liefldd.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
except AttributeError:
# Fallback for lief<0.14.
EXE_FORMATS = lief.EXE_FORMATS
try:
ELF_DYNAMIC_TAGS = lief.ELF.DynamicEntry.TAG
except AttributeError:
# Fallback for lief<0.15.
ELF_DYNAMIC_TAGS = lief.ELF.DYNAMIC_TAGS
except ImportError:
have_lief = False

Expand Down Expand Up @@ -155,15 +160,15 @@ def _set_elf_rpathy_thing(binary, old_matching, new_rpath, set_rpath, set_runpat
for e in dynamic_entries:
if (
set_runpath
and e.tag == lief.ELF.DYNAMIC_TAGS.RUNPATH
and e.tag == ELF_DYNAMIC_TAGS.RUNPATH
and fnmatch(e.runpath, old_matching)
and e.runpath != new_rpath
):
e.runpath = new_rpath
changed = True
elif (
set_rpath
and e.tag == lief.ELF.DYNAMIC_TAGS.RPATH
and e.tag == ELF_DYNAMIC_TAGS.RPATH
and fnmatch(e.rpath, old_matching)
and e.rpath != new_rpath
):
Expand Down Expand Up @@ -196,7 +201,7 @@ def get_rpathy_thing_raw_partial(file, elf_attribute, elf_dyn_tag):
elif (
binary_format == EXE_FORMATS.MACHO
and binary.has_rpath
and elf_dyn_tag == lief.ELF.DYNAMIC_TAGS.RPATH
and elf_dyn_tag == ELF_DYNAMIC_TAGS.RPATH
):
rpaths.extend(
[
Expand All @@ -210,12 +215,12 @@ def get_rpathy_thing_raw_partial(file, elf_attribute, elf_dyn_tag):
get_runpaths_raw = partial(
get_rpathy_thing_raw_partial,
elf_attribute="runpath",
elf_dyn_tag=lief.ELF.DYNAMIC_TAGS.RUNPATH,
elf_dyn_tag=ELF_DYNAMIC_TAGS.RUNPATH,
)
get_rpaths_raw = partial(
get_rpathy_thing_raw_partial,
elf_attribute="rpath",
elf_dyn_tag=lief.ELF.DYNAMIC_TAGS.RPATH,
elf_dyn_tag=ELF_DYNAMIC_TAGS.RPATH,
)
else:

Expand Down Expand Up @@ -364,9 +369,7 @@ def get_uniqueness_key(filename, file):
or binary.type == lief.ELF.ELF_CLASS.CLASS64
):
dynamic_entries = binary.dynamic_entries
result = [
e.name for e in dynamic_entries if e.tag == lief.ELF.DYNAMIC_TAGS.SONAME
]
result = [e.name for e in dynamic_entries if e.tag == ELF_DYNAMIC_TAGS.SONAME]
if result:
return result[0]
return filename
Expand Down
19 changes: 19 additions & 0 deletions news/5565-lief-0.15-compat
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
### Enhancements

* Add compatibility for LIEF=0.15. (#5564 via #5565)

### Bug fixes

* <news item>

### Deprecations

* <news item>

### Docs

* <news item>

### Other

* <news item>
4 changes: 2 additions & 2 deletions tests/test-recipes/metadata/_rpath/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ test:
requires:
- py-lief
commands:
- python -c "import lief; binary = lief.parse(\"${PREFIX}/bin/rpath\"); print([e.rpath for e in binary.dynamic_entries if e.tag == lief.ELF.DYNAMIC_TAGS.RPATH])" # [linux]
- python -c "import lief; binary = lief.parse(\"${PREFIX}/bin/rpath\"); print([e.rpath for e in binary.dynamic_entries if e.tag == lief.ELF.DYNAMIC_TAGS.RPATH])" | grep \$ORIGIN/../previous:\$ORIGIN/../lib:\$ORIGIN/../plugins:\$ORIGIN/../successive # [linux]
- python -c "import lief; binary = lief.parse(\"${PREFIX}/bin/rpath\"); print([e.rpath for e in binary.dynamic_entries if e.tag == getattr(lief.ELF, 'DYNAMIC_TAGS', getattr(lief.ELF.DynamicEntry, 'TAG', None)).RPATH])" # [linux]
- python -c "import lief; binary = lief.parse(\"${PREFIX}/bin/rpath\"); print([e.rpath for e in binary.dynamic_entries if e.tag == getattr(lief.ELF, 'DYNAMIC_TAGS', getattr(lief.ELF.DynamicEntry, 'TAG', None)).RPATH])" | grep \$ORIGIN/../previous:\$ORIGIN/../lib:\$ORIGIN/../plugins:\$ORIGIN/../successive # [linux]
- python -c "import lief; binary = lief.parse(\"${PREFIX}/bin/rpath\"); print(':'.join([command.path.rstrip('/') for command in binary.commands if command.command == lief.MachO.LOAD_COMMAND_TYPES.RPATH]))" | grep ${PREFIX}/../previous:${PREFIX}/../lib:${PREFIX}/plugins:${PREFIX}/../successive # [osx]
2 changes: 1 addition & 1 deletion tests/test-recipes/metadata/_rpath_symlink/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ test:
python -c '
import os, lief
lib = lief.parse(os.environ["PREFIX"] + "/lib/{{ lib_file }}")
assert {"$ORIGIN/."} == {e.rpath for e in lib.dynamic_entries if e.tag == lief.ELF.DYNAMIC_TAGS.RPATH} # [linux]
assert {"$ORIGIN/."} == {e.rpath for e in lib.dynamic_entries if e.tag == getattr(lief.ELF, "DYNAMIC_TAGS", getattr(lief.ELF.DynamicEntry, "TAG", None)).RPATH} # [linux]
assert {"@loader_path/"} == {command.path for command in lib.commands if command.command == lief.MachO.LOAD_COMMAND_TYPES.RPATH} # [osx]
'

0 comments on commit 57c3397

Please sign in to comment.