Skip to content

bpo-45433: Do not link libpython against libcrypt #28881

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
Oct 11, 2021

Conversation

floppym
Copy link
Contributor

@floppym floppym commented Oct 11, 2021

Save/restore LIBS when calling AC_SEARCH_LIBS(..., crypt). This avoid
linking libpython with libcrypt.

https://bugs.python.org/issue45433

@vstinner
Copy link
Member

Would you mind to add a NEWS entry? See https://devguide.python.org/

IMO it's worth it to mention the change in the "Build Changes" of What's New in Python 3.11: Doc/whatsnew/3.11.rst.

@floppym
Copy link
Contributor Author

floppym commented Oct 11, 2021

Added the NEWS entry.

@vstinner
Copy link
Member

Can you please also mention the change in the "Build Changes" of What's New in Python 3.11: Doc/whatsnew/3.11.rst?

Save/restore LIBS when calling AC_SEARCH_LIBS(..., crypt). This avoid
linking libpython with libcrypt.
@floppym
Copy link
Contributor Author

floppym commented Oct 11, 2021

Sorry, I thought adding the NEWS entry would somehow auto-update the whatsnew document. I added an entry to the latter.

@vstinner
Copy link
Member

How can I check https://bugs.python.org/issue45433 manually?

On Fedora, /usr/lib64/libpython3.10.so.1.0 is not linked to libcrypt.

@floppym
Copy link
Contributor Author

floppym commented Oct 11, 2021

I think most distros build with LDFLAGS="-Wl,--as-needed". That causes unused libraries to get automatically dropped by the linker.

There are a couple of alternate things to check:

python3.10-config --libs
pkg-config --libs --static python-3.10

@vstinner
Copy link
Member

I tested manually this PR and I confirm that it works as expected.

I build Python with ./configure --with-pydebug --enable-shared && make.

Without this change, libpython is linked to libcrypt by mistake:

$ ldd libpython3.11d.so
	linux-vdso.so.1 (0x00007fff4f370000)
	libcrypt.so.2 => /lib64/libcrypt.so.2 (0x00007fb4eb5e5000)
	libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fb4eb5c4000)
	libdl.so.2 => /lib64/libdl.so.2 (0x00007fb4eb5bd000)
	...

With this change, libcrypt is gone as expected:

$ ldd libpython3.11d.so
	linux-vdso.so.1 (0x00007fff74162000)
	libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f063ee18000)
	libdl.so.2 => /lib64/libdl.so.2 (0x00007f063ee11000)
	...

@vstinner vstinner merged commit be21706 into python:main Oct 11, 2021
@vstinner
Copy link
Member

Nicely spotted, thanks for the fix!

I prefer to not backport to avoid any risk of regression. In my experience, the build system is fragile.

colesbury referenced this pull request in colesbury/nogil Apr 2, 2023
Save/restore LIBS when calling AC_SEARCH_LIBS(..., crypt). This avoid
linking libpython with libcrypt.
indygreg added a commit to astral-sh/python-build-standalone that referenced this pull request Jan 8, 2024
libcrypt.so again makes an unwanted appearance.

It turns out CPython's configure up until 3.11 exhibited arguably
buggy behavior where as part of searching for libcrypt it always added
`-lcrypt` to LIBS, which got picked up by all linker invocations.

Partially applying the upstream patch on CPython < 3.11 makes the
problem go away. See also python/cpython#28881.

Closes #197.
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