Skip to content

Fix path to libpython shared-library in python binaries - #785

Merged
tianon merged 1 commit into
docker-library:masterfrom
infosiftr:libpython
Jan 17, 2023
Merged

tianon merged 1 commit into
docker-library:masterfrom
infosiftr:libpython

Conversation

@yosifkit

@yosifkit yosifkit commented Jan 13, 2023 •

Copy link
Copy Markdown
Member
  • prevent accidental usage of a system installed libpython of the same version

This makes the lookup for libpython dependent on where the binary is, so you can do silly things to see that it works:

$ docker run -it --rm 11314a7451b3 sh
/ # ldd /usr/local/bin/python3.11
	/lib/ld-musl-x86_64.so.1 (0x7f9295da7000)
	libpython3.11.so.1.0 => /usr/local/bin/../lib/libpython3.11.so.1.0 (0x7f92957d9000)
	libc.musl-x86_64.so.1 => /lib/ld-musl-x86_64.so.1 (0x7f9295da7000)
/ # mv /usr/local/ /opt/things/
/ # ldd /opt/things/bin/python3.11
	/lib/ld-musl-x86_64.so.1 (0x7f388530a000)
	libpython3.11.so.1.0 => /opt/things/bin/../lib/libpython3.11.so.1.0 (0x7f3884d3c000)
	libc.musl-x86_64.so.1 => /lib/ld-musl-x86_64.so.1 (0x7f388530a000)
/ # 

Fixes #784

Comment thread Dockerfile-linux.template Outdated
{{ ) else "" end -}}
LDFLAGS="-Wl,--strip-all,-rpath='$\$ORIGIN/../lib'" \
{{ ) else ( -}}
LDFLAGS="-Wl,-rpath='$\$ORIGIN/../lib'" \

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

  • \$ because of the double quotes in the shell to prevent interpolation
  • $$ for make to not interpret the $O
  • " because it needed the ' around the path, but I didn't want ='-Wl,-rpath='"'"'$$ORIGIN/../lib'"'"

Comment thread Dockerfile-linux.template Outdated
{{ if is_slim or is_alpine then ( -}}
LDFLAGS="-Wl,--strip-all" \
{{ ) else "" end -}}
LDFLAGS="-Wl,--strip-all,-rpath='$\$ORIGIN/../lib'" \

@tianon tianon Jan 13, 2023 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
LDFLAGS="-Wl,--strip-all,-rpath='$\$ORIGIN/../lib'" \
# \$ because of the double quotes in the shell to prevent interpolation
# $$ for make to not interpret the $O
# " because it needed the ' around the path, but I didn't want ='-Wl,-rpath='"'"'$$ORIGIN/../lib'"'"
LDFLAGS="-Wl,-rpath='\$\$ORIGIN/../lib'{{ if is_slim or is_alpine then ",--strip-all" else "" end }}" \

(and then dropping the outer if? 👀)

- prevent accidental usage of a system installed libpython of the same version
@tianon
tianon merged commit 2592ad8 into docker-library:master Jan 17, 2023
@tianon
tianon deleted the libpython branch January 17, 2023 19:17
docker-library-bot added a commit to docker-library-bot/official-images that referenced this pull request Jan 17, 2023
Changes:

- docker-library/python@2592ad8: Merge pull request docker-library/python#785 from infosiftr/libpython
- docker-library/python@0db1a5b: Fix path to libpython shared-library in python binaries
@yosifkit yosifkit mentioned this pull request Jan 20, 2023
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.

Built Python prefers system packaged libpython when installed; local install should be built with rpath?

2 participants