From e2feb88415a99173986672b99d2883193daf1c13 Mon Sep 17 00:00:00 2001 From: Tony Kelman Date: Thu, 16 Jan 2025 11:44:37 -0800 Subject: [PATCH 1/5] handle lief 0.15 renaming of LOAD_COMMAND_TYPES https://lief.re/doc/stable/changelog.html#july-21th-2024 --- conda_build/os_utils/liefldd.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/conda_build/os_utils/liefldd.py b/conda_build/os_utils/liefldd.py index b3b155c6c5..0e60491158 100644 --- a/conda_build/os_utils/liefldd.py +++ b/conda_build/os_utils/liefldd.py @@ -44,6 +44,11 @@ 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 except ImportError: have_lief = False @@ -134,7 +139,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 = [ @@ -207,7 +212,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 From 340b6de9b53d67a4292c47a103e6e8efa9215988 Mon Sep 17 00:00:00 2001 From: Tony Kelman Date: Thu, 16 Jan 2025 11:48:24 -0800 Subject: [PATCH 2/5] Create 5595-more-lief-compat --- news/5595-more-lief-compat | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 news/5595-more-lief-compat diff --git a/news/5595-more-lief-compat b/news/5595-more-lief-compat new file mode 100644 index 0000000000..7e4fe53bed --- /dev/null +++ b/news/5595-more-lief-compat @@ -0,0 +1,19 @@ +### Enhancements + +* Additional compatibility fixes for LIEF>=0.15. (#5594 via #5595) + +### Bug fixes + +* + +### Deprecations + +* + +### Docs + +* + +### Other + +* From 46ee5ca4c8e8dd757d6d58b0e9f9855c86164e45 Mon Sep 17 00:00:00 2001 From: Tony Kelman Date: Thu, 16 Jan 2025 11:53:32 -0800 Subject: [PATCH 3/5] adapt rpath tests for LOAD_COMMAND_TYPES renaming --- tests/test-recipes/metadata/_rpath/meta.yaml | 2 +- tests/test-recipes/metadata/_rpath_symlink/meta.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test-recipes/metadata/_rpath/meta.yaml b/tests/test-recipes/metadata/_rpath/meta.yaml index 1a9ba6a97f..87459cfce6 100755 --- a/tests/test-recipes/metadata/_rpath/meta.yaml +++ b/tests/test-recipes/metadata/_rpath/meta.yaml @@ -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] diff --git a/tests/test-recipes/metadata/_rpath_symlink/meta.yaml b/tests/test-recipes/metadata/_rpath_symlink/meta.yaml index 8d50f711ab..ef7ec6a27b 100644 --- a/tests/test-recipes/metadata/_rpath_symlink/meta.yaml +++ b/tests/test-recipes/metadata/_rpath_symlink/meta.yaml @@ -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] ' From 513161d98fc39394cebddfce948e022926424257 Mon Sep 17 00:00:00 2001 From: Tony Kelman Date: Fri, 17 Jan 2025 01:45:57 -0800 Subject: [PATCH 4/5] lief.ELF.ELF_CLASS was moved to lief.ELF.Header.CLASS in lief 0.15 --- conda_build/os_utils/liefldd.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/conda_build/os_utils/liefldd.py b/conda_build/os_utils/liefldd.py index 0e60491158..156065c394 100644 --- a/conda_build/os_utils/liefldd.py +++ b/conda_build/os_utils/liefldd.py @@ -49,6 +49,11 @@ 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 @@ -199,8 +204,8 @@ def get_rpathy_thing_raw_partial(file, elf_attribute, elf_dyn_tag): 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 + binary_type == ELF_CLASS.CLASS32 + or binary_type == ELF_CLASS.CLASS64 ): rpaths = _get_elf_rpathy_thing(binary, elf_attribute, elf_dyn_tag) elif ( @@ -255,8 +260,8 @@ 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 @@ -344,7 +349,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" @@ -370,8 +375,8 @@ 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] @@ -488,7 +493,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", From 074df068c12f1a1ee3053834d52d9432f75566de Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 17 Jan 2025 14:50:13 +0000 Subject: [PATCH 5/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- conda_build/os_utils/liefldd.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/conda_build/os_utils/liefldd.py b/conda_build/os_utils/liefldd.py index 156065c394..c1938590e3 100644 --- a/conda_build/os_utils/liefldd.py +++ b/conda_build/os_utils/liefldd.py @@ -203,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 == ELF_CLASS.CLASS32 - or binary_type == 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 @@ -260,8 +257,7 @@ def set_rpath(old_matching, new_rpath, file): if not binary: return if binary.format == EXE_FORMATS.ELF and ( - binary.type == ELF_CLASS.CLASS32 - or binary.type == 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 @@ -375,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 == ELF_CLASS.CLASS32 - or binary.type == 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]