Skip to content
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

Python plugin compiled with incomplete dependencies #420

Closed
jonmz opened this issue May 7, 2015 · 2 comments
Closed

Python plugin compiled with incomplete dependencies #420

jonmz opened this issue May 7, 2015 · 2 comments
Assignees
Labels
bug Unexpected problem or unintended behavior not reproduced The problem can not be reproduced

Comments

@jonmz
Copy link

jonmz commented May 7, 2015

Using WeeChat 1.1.1, compiled on CentOS 6 against a manually compiled Python 2.7 (because CentOS 6 only has Python 2.6), I've stumbled upon this problem loading the python.so plugin:

Error: unable to load plugin "/package/host/localhost/weechat-1.1.1/lib/weechat/plugins/python.so": /package/host/localhost/weechat-1.1.1/lib/weechat/plugins/python.so: undefined symbol: forkpty

ldd provides the following linker information on python.so:

$ ldd /package/host/localhost/weechat-1.1.1/lib/weechat/plugins/python.so
    linux-vdso.so.1 =>  (0x00007fff2fd9e000)
    libc.so.6 => /lib64/libc.so.6 (0x00007f58af344000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f58afafa000)

The undefined symbol: forkpty is a result of python.so not being linked to libutil.so. I could quickly verify that starting WeeChat like this ...

$ LD_PRELOAD=/lib64/libutil.so.1 weechat

... effectively fixed the problem. That was amazingly hard to debug because as soon as another plugin that correctly links to libutil.so - like, e.g., the perl.so plugin - is loaded before the python.so plugin, the problem silently disappears. This left me with the weird situation that exactly the same binaries, used on two identically installed CentOS 6 hosts, provided different results, based on the order of plugins in the plugins folder as provided by the underlying filesystem.

I have found out that cmake/FindPython.cmake uses this code to create the list of libraries to link python.so against:

  execute_process(
    COMMAND ${PYTHON_EXECUTABLE} -c "import sys; from distutils.sysconfig import *; sys.stdout.write(get_config_var('LINKFORSHARED'))"
    OUTPUT_VARIABLE PYTHON_LFLAGS
    )

I'm not pretty sure if that's the correct way to do it. The section Compiling and Linking under Unix-like systems of the official Python 2 docs states that one is expected to use the pythonX.Y-config script to find out which linker flags have to be used to compile against Python. These flags correctly include -lutil:

$ python2.7-config --ldflags
-L/package/host/localhost/python-2.7.3/lib/python2.7/config -ldl -lutil -lm -lpython2.7 -Xlinker -export-dynamic

In contrast, the LINKFORSHARED variable from the sysconfig module doesn't:

$ python2.7 -c "import sys; from distutils.sysconfig import *; sys.stdout.write(get_config_var('LINKFORSHARED'))"
-Xlinker -export-dynamic

The Python docs admit, however, that the pythonX.Y-config procedure is "not guaranteed to work for all Unix-like platforms" and also references LINKFORSHARED as an alternative way, but combines it together with the value of LIBS (which does provides -ldl -lutil). So ... for now I'm solving the problem by explicitly adding the LIBS value to the code generation:

--- weechat-1.1.1/cmake/FindPython.cmake.orig   2015-01-25 08:39:58.000000000 +0100
+++ weechat-1.1.1/cmake/FindPython.cmake    2015-05-07 16:19:30.026200107 +0200
@@ -57,7 +57,7 @@
     )

   execute_process(
-    COMMAND ${PYTHON_EXECUTABLE} -c "import sys; from distutils.sysconfig import *; sys.stdout.write(get_config_var('LINKFORSHARED'))"
+    COMMAND ${PYTHON_EXECUTABLE} -c "import sys; from distutils.sysconfig import *; sys.stdout.write(get_config_var('LIBS') + ' ' + get_config_var('LINKFORSHARED'))"
     OUTPUT_VARIABLE PYTHON_LFLAGS
     )

I'd be happy if somebody with better compiler knowledge could review this and possibly fix it in the code base.

@flashcode flashcode added the bug Unexpected problem or unintended behavior label May 8, 2015
@yegle
Copy link

yegle commented Sep 25, 2015

I'm using pkgsrc.org on Linux system to build and install weechat. Unfortunately I got the exact same error "undefined symbol forkpty"

@flashcode
Copy link
Member

Similar to #1383, which is closed: now that WeeChat uses pkg-config to find and compile with Python, the problem should be solved.
Closing the issue.

@flashcode flashcode added the not reproduced The problem can not be reproduced label May 9, 2020
@flashcode flashcode self-assigned this May 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unexpected problem or unintended behavior not reproduced The problem can not be reproduced
Projects
None yet
Development

No branches or pull requests

3 participants