Skip to content

Add libdl on Unix-like systems. #10310

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 26, 2018
Merged

Add libdl on Unix-like systems. #10310

merged 1 commit into from
Jan 26, 2018

Conversation

QuLogic
Copy link
Member

@QuLogic QuLogic commented Jan 24, 2018

PR Summary

Not linking with libdl causes errors when -z defs is in the linker flags.

PR Checklist

  • Has Pytest style unit tests
  • Code is PEP 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@anntzer
Copy link
Contributor

anntzer commented Jan 25, 2018

We (and every python extension module) are already linking against libpython, which itself loads libdl. If that's not sufficient to you I'd argue you need to raise the issue upstream (with distutils)...

@QuLogic
Copy link
Member Author

QuLogic commented Jan 25, 2018

This is not a general addition; we are calling dl* functions in the TkAgg extension, thus this is making the linkage explicit.

@anntzer
Copy link
Contributor

anntzer commented Jan 25, 2018

Why is this different? Does -z defs not look into transitively loaded libraries? Should it not? (Perhaps it should indeed not, I just don't know)

@QuLogic
Copy link
Member Author

QuLogic commented Jan 25, 2018

Here is what the build looks like with -z defs:

g++ -pthread -shared -Wl,-z,relro -Wl,-z,defs -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -g -Wl,-z,relro -Wl,-z,defs -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -g -flto -fuse-linker-plugin -ffat-lto-objects -flto-partition=none build/temp.linux-x86_64-3.6/src/py_converters.o build/temp.linux-x86_64-3.6/src/_tkagg.o -L/usr/local/lib -L/usr/local/lib64 -L/usr/lib -L/usr/lib64 -L/usr/lib64 -lpython3.6m -o build/lib.linux-x86_64-3.6/matplotlib/backends/_tkagg.cpython-36m-x86_64-linux-gnu.so
build/temp.linux-x86_64-3.6/src/_tkagg.o: In function `_dfunc(void*, char const*)':
/builddir/build/BUILD/matplotlib-2.1.2/src/_tkagg.cpp:371: undefined reference to `dlerror'
/builddir/build/BUILD/matplotlib-2.1.2/src/_tkagg.cpp:372: undefined reference to `dlsym'
/builddir/build/BUILD/matplotlib-2.1.2/src/_tkagg.cpp:374: undefined reference to `dlerror'
build/temp.linux-x86_64-3.6/src/_tkagg.o: In function `load_tkinter_funcs()':
/builddir/build/BUILD/matplotlib-2.1.2/src/_tkagg.cpp:409: undefined reference to `dlopen'
/builddir/build/BUILD/matplotlib-2.1.2/src/_tkagg.cpp:433: undefined reference to `dlopen'
/builddir/build/BUILD/matplotlib-2.1.2/src/_tkagg.cpp:441: undefined reference to `dlclose'
collect2: error: ld returned 1 exit status
error: command 'g++' failed with exit status 1

@anntzer
Copy link
Contributor

anntzer commented Jan 25, 2018

OK, looks like that's a fedora thing: https://fedoraproject.org/wiki/UnderstandingDSOLinkChange

@QuLogic
Copy link
Member Author

QuLogic commented Jan 25, 2018

The default for building shared libraries is to ignore undefined things. From the man page:

The default behaviour is to report errors for any undefined symbols referenced in shared libraries if the linker is being used to create an executable, but to allow them if the linker is being used to create a shared library.

But as you've also found, transitive deps are not searched for, and I believe the --copy-dt-needed-entries was switched quite a while back to disable it. (That page is from Fedora 13, which is almost 7 years ago.)

setupext.py Outdated
@@ -1493,6 +1493,8 @@ def add_flags(self, ext):
if sys.platform == 'win32':
# PSAPI library needed for finding Tcl / Tk at run time
ext.libraries.extend(['psapi'])
elif sys.platform != 'darwin':
Copy link
Contributor

Choose a reason for hiding this comment

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

seems to be a slightly obfuscated way to say "startswith('linux')"...

Copy link
Member Author

Choose a reason for hiding this comment

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

I had assumed it was needed on BSD, but I think that was wrong now.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

Not linking with libdl causes errors when -z defs is in the linker
flags.
@anntzer anntzer merged commit 4e140c8 into matplotlib:master Jan 26, 2018
@QuLogic QuLogic deleted the libdl branch January 26, 2018 08:04
@QuLogic QuLogic added this to the v2.2 milestone Jan 26, 2018
@QuLogic QuLogic modified the milestones: needs sorting, v2.2.0 Feb 12, 2018
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