Skip to content

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

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

Merged
merged 1 commit into from
Jan 17, 2023

Conversation

yosifkit
Copy link
Member

@yosifkit yosifkit commented Jan 13, 2023

  • 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

{{ ) else "" end -}}
LDFLAGS="-Wl,--strip-all,-rpath='$\$ORIGIN/../lib'" \
{{ ) else ( -}}
LDFLAGS="-Wl,-rpath='$\$ORIGIN/../lib'" \
Copy link
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'"'"

@@ -173,8 +173,10 @@ RUN set -eux; \
EXTRA_CFLAGS="-DTHREAD_STACK_SIZE=0x100000" \
{{ ) else "" end -}}
{{ if is_slim or is_alpine then ( -}}
LDFLAGS="-Wl,--strip-all" \
{{ ) else "" end -}}
LDFLAGS="-Wl,--strip-all,-rpath='$\$ORIGIN/../lib'" \
Copy link
Member

@tianon tianon Jan 13, 2023

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