using own ld-linux loader in onedir mode

72 views
Skip to first unread message

Sleep_Walker

unread,
Jul 16, 2024, 5:16:31 AM7/16/24
to pyins...@googlegroups.com
Hello!

I'm trying to have very portable python tools using pyinstaller together with full dependency closure and custom built GlibC. I'm executing pyinstaller binary via direct call of ld-linux loader:

```
PREFIX/dist/bundle_name/_internal/ld-linux-x86-64.so.2 --library-path PREFIX/dist/bundle_name/_internal PREFIX/dist/bundle_name/app.py
```

The problem I see is that the second call of execvp is not using the ld-linux path I used in invocation and relies on the ELF interpreter specified in the ELF header instead (I found it when I intentionally set this to a non-existing file).


```
[50458] PyInstaller Bootloader 6.x
[50458] LOADER: resolved executable file PREFIX/dist/bundle_name/_internal/ld-linux-x86-64.so.2 is ld.so dynamic loader - ignoring it!
[50458] LOADER: resolving program path from argv[0]: PREFIX/dist/bundle_name/app.py
[50458] LOADER: executable file: PREFIX/dist/bundle_name/app.py
[50458] LOADER: trying to load executable-embedded archive...
[50458] LOADER: attempting to open archive PREFIX/dist/bundle_name/app.py
[50458] LOADER: cookie found at offset 0x2BD596
[50458] LOADER: archive file: PREFIX/dist/bundle_name/app.py
[50458] LOADER: application has onedir semantics...
[50458] LOADER: POSIX onedir process needs to set library seach path and restart itself.
[50458] LOADER: setting LD_LIBRARY_PATH=PREFIX/dist/bundle_name/_internal
[50458] LOADER: failed to restart process via execvp: No such file or directory
```
(I redacted PREFIX and app name, I hope you don't mind much)

Since the bootloader code on other places seems to be ready for this direct execution, I wonder if it's not working because of onedir mode or if I invoked it wrongly. Maybe it's just a bug on a path which hasn't been tried before and I should file new issue.

Thanks in advance for your advice,

Tomáš Čech

bwoodsend

unread,
Jul 16, 2024, 8:30:14 AM7/16/24
to PyInstaller
Any reason why you can't just use staticx or build on an old Docker container to make your application portable? I doubt anyone wants to support this case.

Sleep Walker

unread,
Jul 16, 2024, 9:00:24 AM7/16/24
to PyInstaller
1) staticx doesn't support onedir mode and I have more utilities to pack - having onefile would bloat the result a lot for no reason
2) docker is not present dependency in my usecase
3) rest of the code seems to be already ready for this scenario (but not onedir mode on POSIX platform)
4) fix is easy - just use the dynamic loader if it is already detected

Would the patch be accepted? I imagine that the change like:
- linker_filename would be added to PYI_CONTEXT
- linker_filename would be filled if dynamic loader is used for call (requires modification of function prototype so it can be filled in)
- if linker_filename is set, it would be used in _pyi_main_handle_posix_onedir()

Best regards,

Tomáš Čech


Dne úterý 16. července 2024 v 14:30:14 UTC+2 uživatel bwoodsend napsal:

Sleep Walker

unread,
Jul 17, 2024, 3:57:57 PM7/17/24
to PyInstaller

I believe that the result patch is straightforward and reasonable.

Thanks in advance for the consideration and review.

Tomáš Čech

Dne úterý 16. července 2024 v 15:00:24 UTC+2 uživatel Sleep Walker napsal:
Reply all
Reply to author
Forward
0 new messages