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
Undefined references when compiling ctypes on binutils 2.29.1 with gcc -Wl,-z,undefs (Fedora 28) #76828
Comments
Original bug report: https://bugzilla.redhat.com/show_bug.cgi?id=1537489 As soon as strict symbol checking was enabled on the development branch of Fedora, our build of CPython started failing due to undefined symbols when compiling ctypes. Build log is attached. That seems to be because ctypes are not explicitly linked against -ldl. This can be fixed by adding the -ldl flag at https://github.com/python/cpython/blob/master/setup.py#L1935 , not sure though how portable that is. |
The attached file is 1.3 MB and your build is using Fedora-specific patches. Please post the relevant part from a vanilla build without Fedora patches. |
Relevant part from the build log: running build_ext |
Unfortunately when trying to reproduce it by compiling from source and adding the '-z defs' flag to the linker, undefined symbol issues appeared for all the extension modules of the stdlib. |
I'm unable to reproduce the issue on Fedora 27 (binutils-2.29-6.fc27.src.rpm, gcc-7.2.1-2.fc27.src.rpm). _ctypes.cpython-37dm-x86_64-linux-gnu.so is generated whereas it's not linked to libdl.so (as expected). The flag seems to be ignored. https://src.fedoraproject.org/rpms/redhat-rpm-config/c/078af192613e1beec34824a94dc5f6feeeea1568?branch=master says "The latter needs binutils 2.29.1-12.fc28 or later. I understand that my binutils are too old (2.29 vs 2.29.1). |
-ldl is the correct fix here. https://fedoraproject.org/wiki/UnderstandingDSOLinkChange explains the problem. tl;dr linking with dl is required because the linker no longer adds indirect dependencies. We can't just add dl unconditionally. You have to add a check. |
dlopen() is not used on Windows nor macOS older than 10.3. On old macOS, functions like NSCreateObjectFileImageFromFile() are used. I don't think that the master branch still supports macOS 10.2. Mac OS X 10.2 was released in 2002 and unsupported as of 2006. |
So what would be the best way to proceed from here? Add a check or just link to dl unconditionally? |
configure.ac already contains the check: AC_CHECK_LIB(dl, dlopen) It should be enough to add: if sysconfig.get_config_var('HAVE_LIBDL'):
libs.append('dl') to ctypes. |
I use Fedora 27, Please, could you give the instructions for your build, I could test locally and check if the patch fixes the issue. Thank you |
Stéphane, the issue is only reproducible with latest Fedora rawhide. |
maybe I miss something but I have downloaded the last fedora:rawhide with docker, just update it via dnf update and install all the dependencies for git and python docker --rm -it fedora:rawhide /bin/bash dnf update git clone --depth=1 https://github.com/python/cpython and I have no issue with ctypes. What are your instructions for the build? Thank you |
Currently the flag has been disabled on rawhide due to too many breakages but the bug is still there if you add '-z defs' to the linker flags. |
Just tested it for python3 on a rawhide system with the flag enabled and it works, ctypes is compiled successfully. python2 is not affected the same way though, various modules fail there with different undefined references issues when setting the flag. |
Attaching the build log from python2. Near the end you can see the undefined references errors. |
Tested the fix and ctypes is linked successfully with libdl when utilizing the strict symbol check. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: