Skip to content

WIP: Experiment to use LIEF #187

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

Closed
wants to merge 3 commits into from
Closed

WIP: Experiment to use LIEF #187

wants to merge 3 commits into from

Conversation

lkollar
Copy link
Contributor

@lkollar lkollar commented Aug 7, 2019

Testing out LIEF for #174.

This will fail CI at the moment because of the missing wheel for CentOS 5.

Add a new flag to make it possible to use the LIEF library to patch ELF
files instead of using `patchelf`.
requirements.txt Outdated
@@ -1,2 +1,3 @@
wheel == 0.31.1
pyelftools >=0.24
https://lief-project.github.io/packages/lief/lief-0.10.0.dev0-cp37-cp37m-manylinux1_x86_64.whl
Copy link

Choose a reason for hiding this comment

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

lief has been published in pypi. Why don't you install it from there?

Copy link
Contributor Author

@lkollar lkollar Dec 25, 2019

Choose a reason for hiding this comment

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

I am, but I haven't yet pushed the latest changes. I just did now. Note that this is still a work in progress.

@figroc
Copy link

figroc commented Dec 27, 2019

I have to build on manylinux2010. So I applied this patch and built the patched auditwheel on figroc/dockcross:manylinux2010 derived from dockcross/manylinux2010-x64:latest. When I invoked auditwheel repair with lief, the new cp36-cp36m-manylinux2010_x86_64 was built but with the following error:

Traceback (most recent call last):
  File "/usr/local/bin/auditwheel", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.6/site-packages/auditwheel/main.py", line 50, in main
    rval = args.func(args, p)
  File "/usr/local/lib/python3.6/site-packages/auditwheel/main_repair.py", line 97, in execute
    analyzed_tag = analyze_wheel_abi(out_wheel).overall_tag
  File "/usr/local/lib/python3.6/site-packages/auditwheel/wheel_abi.py", line 191, in analyze_wheel_abi
    uses_PyFPE_jbuf) = get_wheel_elfdata(wheel_fn)
  File "/usr/local/lib/python3.6/site-packages/auditwheel/wheel_abi.py", line 58, in get_wheel_elfdata
    for key, value in elf_find_versioned_symbols(elf):
  File "/usr/local/lib/python3.6/site-packages/auditwheel/elfutils.py", line 47, in elf_find_versioned_symbols
    for verneed, verneed_iter in section.iter_versions():
  File "/usr/local/lib/python3.6/site-packages/elftools/elf/gnuversions.py", line 154, in iter_versions
    for verneed, vernaux in super(GNUVerNeedSection, self).iter_versions():
  File "/usr/local/lib/python3.6/site-packages/elftools/elf/gnuversions.py", line 116, in iter_versions
    count_field, str(entry)))
  File "/usr/local/lib/python3.6/site-packages/elftools/common/utils.py", line 77, in elf_assert
    _assert_with_exception(cond, msg, ELFError)
  File "/usr/local/lib/python3.6/site-packages/elftools/common/utils.py", line 109, in _assert_with_exception
    raise exception_type(msg)
elftools.common.exceptions.ELFError: Expected number of version auxiliary entries (vn_cnt) to be > 0for the following version entry: Container({'vn_version': 1162, 'vn_cnt': 0, 'vn_file': 0, 'vn_aux': 16, 'vn_next': 0})

On importing the package on python:3.6-slim, I got the error:

Inconsistency detected by ld.so: dl-version.c: 205: _dl_check_map_versions: Assertion `needed != NULL' failed!

You can checkout the corresponding scripts and Dockerfile which I use. Hope it would be helpful.

@lkollar
Copy link
Contributor Author

lkollar commented Dec 28, 2019

Inconsistency detected by ld.so: dl-version.c: 205: _dl_check_map_versions: Assertion `needed != NULL' failed!

I came across the same issue while I was testing LIEF with auditwheel. I think this might be due to a bug in LIEF but I can't reproduce the issue right now. What would be most useful is a concrete reproducer including the exact LIEF version, vendored library name and version and the environment, so we can further investigate this. I am not able to dedicate much time to this at the moment but I am planning to follow up soon.

@figroc if you could upload the wheel somewhere (before invoking auditwheel on it) I can check if I can reproduce the issue.

@figroc
Copy link

figroc commented Dec 29, 2019

@lkollar You can build the wheel with the command:

docker run --rm -v $(pwd):/work --entrypoint bash figroc/dockcross:manylinux2010 -c 'pip3.6 -v wheel s2geometry'

The non-audited wheel file s2geometry-0.9.0-cp36-cp36m-linux_x86_64.whl will be generated in $(pwd).

The commit I applied to build the auditwheel is lkollar/auditwheel@0e0016e.

@lkollar
Copy link
Contributor Author

lkollar commented Dec 29, 2019

@figroc thanks, I managed to reproduce the issue with libcrpyto.so. Opened an issue in LIEF: lief-project/LIEF#374.

logger.info("Replacing needed library: %s with %s",
lib.name, new_so_name)
lib.name = new_so_name
elf.write(file_name)
Copy link

Choose a reason for hiding this comment

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

In my case I also needed to:

for sym in elf.symbols_version_requirement:
    if sym.name == so_name:
        sym.name = new_so_name

@lkollar
Copy link
Contributor Author

lkollar commented May 20, 2020

Closing this in favour of #240 which retains the interface for ELF patching as discussed in #174.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants