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

Properly handle RPATH $ORIGIN #75

Merged
merged 8 commits into from
Mar 10, 2019
Merged

Conversation

JonathonReinhart
Copy link
Owner

@JonathonReinhart JonathonReinhart commented Nov 19, 2018

This makes a number of fixes which all revolve around using ldd to discover dependencies:

  • Run ldd on executables in their original locations, rather than after they're copied temp directory. This is important if they use RPATH which includes $ORIGIN
  • PyInstaller:
    • Extract all binaries before scanning for dependencies. This is important if there are dependencies present in the PyInstaller archive
    • Set LD_LIBRARY_PATH to the temporary directory where we extract files from the PyInstaller archive

Fixes #61

@JonathonReinhart
Copy link
Owner Author

JonathonReinhart commented Nov 19, 2018

Note: I still need to test this on PyInstaller applications, like #61 referred to.

I'm pretty sure it won't work because pyinstaller.py calls get_shobj_deps(tmppath) where tmppath is not the original path. The same fix needs to be made there also.

@oz123
Copy link

oz123 commented Jan 9, 2019

@JonathonReinhart I just tested this branch with application built with pyinstaller. I can confirm that this fix won't work for pyinstaller bundles.

@cakebake
Copy link

cakebake commented Feb 18, 2019

I just tested this branch with application built with pyinstaller. I can confirm that this fix won't work for pyinstaller bundles.

I can confirm that too. What is the status here? Unfortunately I am not really in the topic in python.

btw: Thank you for this project ;)

Adding

sed -i 's/# Some shared objs might have no DT_NEEDED tags (see issue #67)/print("ldd, unexpected lin in ldd output: " + line)\n            continue/g' \
  /usr/local/lib/python3.7/dist-packages/staticx/elf.py

... results in

root@c41d9d88bc9c:/tmp# staticx /tmp/dist/weasyprint /workdir/dist/weasyprint
ldd, unexpected lin in ldd output: 	libjpeg-3fe7dfc0.so.9.3.0 => not found
ldd, unexpected lin in ldd output: 	libopenjp2-e366d6b0.so.2.1.0 => not found
ldd, unexpected lin in ldd output: 	libz-a147dcb0.so.1.2.3 => not found
ldd, unexpected lin in ldd output: 	libtiff-8267adfe.so.5.4.0 => not found
ldd, unexpected lin in ldd output: 	libwebp-db943ca4.so.7.0.3 => not found
ldd, unexpected lin in ldd output: 	libwebpmux-062931a1.so.3.0.3 => not found
ldd, unexpected lin in ldd output: 	libwebpdemux-cc0d17dd.so.2.0.5 => not found
ldd, unexpected lin in ldd output: 	statically linked
ldd, unexpected lin in ldd output: 	statically linked
ldd, unexpected lin in ldd output: 	statically linked
ldd, unexpected lin in ldd output: 	statically linked
ldd, unexpected lin in ldd output: 	libz-a147dcb0.so.1.2.3 => not found

Example

This should hopefully shake out bugs related to Pyinstaller + RPATH
Libraries and applications can use RPATH $ORIGIN to indicate that their
dependencies are in a path relative to them. If staticx moves/copies the
application, then ld.so won't be able to find the dependencies.

Fixes #61
Some of the dependencies may not have been extracted yet.
This emulates the behavior of the PyInstaller bootloader:

https://github.com/pyinstaller/pyinstaller/blob/v3.4/bootloader/src/pyi_utils.c#L808-L811

This is necessary because some shared objects may depend on other shared
objects in the PyInstaller archive. Without this change, Staticx would
still build a valid program (because there are no additional
dependencies in this case), but ldd would report a missing library.

Fixes additional cases reported in #61.
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.

Unexpected failure when wrapping executable due to missing line in ldd output
3 participants