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

handle lief 0.15 renaming of LOAD_COMMAND_TYPES and ELF_CLASS #5595

Open
wants to merge 5 commits into
base: 25.1.x
Choose a base branch
from
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
29 changes: 17 additions & 12 deletions conda_build/os_utils/liefldd.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@
except AttributeError:
# Fallback for lief<0.15.
ELF_DYNAMIC_TAGS = lief.ELF.DYNAMIC_TAGS
try:
LOAD_COMMAND_TYPES = lief.MachO.LoadCommand.TYPE
except AttributeError:
# Fallback for lief<0.15.
LOAD_COMMAND_TYPES = lief.MachO.LOAD_COMMAND_TYPES
try:
ELF_CLASS = lief.ELF.Header.CLASS
except AttributeError:
# Fallback for lief<0.15.
ELF_CLASS = lief.ELF.ELF_CLASS
except ImportError:
have_lief = False

Expand Down Expand Up @@ -134,7 +144,7 @@ def get_libraries(file):
binary_name = [
command.name
for command in binary.commands
if command.command == lief.MachO.LOAD_COMMAND_TYPES.ID_DYLIB
if command.command == LOAD_COMMAND_TYPES.ID_DYLIB
]
binary_name = binary_name[0] if len(binary_name) else None
result = [
Expand Down Expand Up @@ -193,10 +203,7 @@ def get_rpathy_thing_raw_partial(file, elf_attribute, elf_dyn_tag):
binary_format = binary.format
if binary_format == EXE_FORMATS.ELF:
binary_type = binary.type
if (
binary_type == lief.ELF.ELF_CLASS.CLASS32
or binary_type == lief.ELF.ELF_CLASS.CLASS64
):
if binary_type == ELF_CLASS.CLASS32 or binary_type == ELF_CLASS.CLASS64:
rpaths = _get_elf_rpathy_thing(binary, elf_attribute, elf_dyn_tag)
elif (
binary_format == EXE_FORMATS.MACHO
Expand All @@ -207,7 +214,7 @@ def get_rpathy_thing_raw_partial(file, elf_attribute, elf_dyn_tag):
[
command.path
for command in binary.commands
if command.command == lief.MachO.LOAD_COMMAND_TYPES.RPATH
if command.command == LOAD_COMMAND_TYPES.RPATH
]
)
return rpaths, binary_format, binary_type
Expand Down Expand Up @@ -250,8 +257,7 @@ def set_rpath(old_matching, new_rpath, file):
if not binary:
return
if binary.format == EXE_FORMATS.ELF and (
binary.type == lief.ELF.ELF_CLASS.CLASS32
or binary.type == lief.ELF.ELF_CLASS.CLASS64
binary.type == ELF_CLASS.CLASS32 or binary.type == ELF_CLASS.CLASS64
):
if _set_elf_rpathy_thing(
binary, old_matching, new_rpath, set_rpath=True, set_runpath=False
Expand Down Expand Up @@ -339,7 +345,7 @@ def from_os_varnames(binary_format, binary_type, input_):
.replace("@rpath", "$RPATH")
)
elif binary_format == EXE_FORMATS.ELF:
if binary_type == lief.ELF.ELF_CLASS.CLASS64:
if binary_type == ELF_CLASS.CLASS64:
libdir = "/lib64"
else:
libdir = "/lib"
Expand All @@ -365,8 +371,7 @@ def get_uniqueness_key(filename, file):
elif binary.format == EXE_FORMATS.MACHO:
return filename
elif binary.format == EXE_FORMATS.ELF and ( # noqa
binary.type == lief.ELF.ELF_CLASS.CLASS32
or binary.type == lief.ELF.ELF_CLASS.CLASS64
binary.type == ELF_CLASS.CLASS32 or binary.type == ELF_CLASS.CLASS64
):
dynamic_entries = binary.dynamic_entries
result = [e.name for e in dynamic_entries if e.tag == ELF_DYNAMIC_TAGS.SONAME]
Expand Down Expand Up @@ -483,7 +488,7 @@ def inspect_linkages_lief(
if not binary:
default_paths = []
elif binary.format == EXE_FORMATS.ELF:
if binary.type == lief.ELF.ELF_CLASS.CLASS64:
if binary.type == ELF_CLASS.CLASS64:
default_paths = [
"$SYSROOT/lib64",
"$SYSROOT/usr/lib64",
Expand Down
19 changes: 19 additions & 0 deletions news/5595-more-lief-compat
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
### Enhancements

* Additional compatibility fixes for LIEF>=0.15. (#5594 via #5595)

### Bug fixes

* <news item>

### Deprecations

* <news item>

### Docs

* <news item>

### Other

* <news item>
2 changes: 1 addition & 1 deletion tests/test-recipes/metadata/_rpath/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ test:
commands:
- 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]
- python -c "import lief; binary = lief.parse(\"${PREFIX}/bin/rpath\"); print(':'.join([command.path.rstrip('/') for command in binary.commands if command.command == getattr(lief.MachO, 'LOAD_COMMAND_TYPES', getattr(lief.MachO.LoadCommand, 'TYPE', None)).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 @@ -35,5 +35,5 @@ test:
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 == 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]
assert {"@loader_path/"} == {command.path for command in lib.commands if command.command == getattr(lief.MachO, "LOAD_COMMAND_TYPES", getattr(lief.MachO.LoadCommand, "TYPE", None)).RPATH} # [osx]
'
Loading