Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Dlopen the actual linked libpython #1592
Conversation
arr2036
and 1 other
commented on an outdated diff
Apr 25, 2016
| @@ -205,6 +206,58 @@ static void mod_error(void) | ||
| Py_XDECREF(pTraceback); | ||
| } | ||
| +static int dlopen_linked_libpython_cb(struct dl_phdr_info *info, | ||
| + UNUSED size_t size, void *data) | ||
| +{ | ||
| + const char *pattern = "/libpython" | ||
| + STRINGIFY(PY_MAJOR_VERSION) "." | ||
| + STRINGIFY(PY_MINOR_VERSION) ".so"; |
spbnick
Collaborator
|
arr2036
commented on an outdated diff
Apr 25, 2016
| @@ -205,6 +206,56 @@ static void mod_error(void) | ||
| Py_XDECREF(pTraceback); | ||
| } | ||
| +static int dlopen_linked_libpython_cb(struct dl_phdr_info *info, | ||
| + UNUSED size_t size, void *data) | ||
| +{ | ||
| + const char *pattern = "/libpython" | ||
| + STRINGIFY(PY_MAJOR_VERSION) "." | ||
| + STRINGIFY(PY_MINOR_VERSION) ".so"; | ||
| + char **ppath = (char **)data; | ||
| + | ||
| + if (strstr(info->dlpi_name, pattern) != NULL) { | ||
| + if (*ppath != NULL) { | ||
| + free(*ppath); |
|
|
arr2036
and 1 other
commented on an outdated diff
Apr 25, 2016
| @@ -205,6 +206,56 @@ static void mod_error(void) | ||
| Py_XDECREF(pTraceback); | ||
| } | ||
| +static int dlopen_linked_libpython_cb(struct dl_phdr_info *info, | ||
| + UNUSED size_t size, void *data) | ||
| +{ | ||
| + const char *pattern = "/libpython" | ||
| + STRINGIFY(PY_MAJOR_VERSION) "." | ||
| + STRINGIFY(PY_MINOR_VERSION) ".so"; | ||
| + char **ppath = (char **)data; | ||
| + | ||
| + if (strstr(info->dlpi_name, pattern) != NULL) { | ||
| + if (*ppath != NULL) { | ||
| + free(*ppath); | ||
| + *ppath = NULL; | ||
| + return EEXIST; | ||
| + } else { | ||
| + *ppath = strdup(info->dlpi_name); |
arr2036
Owner
|
arr2036
commented on an outdated diff
Apr 25, 2016
| + rc = dl_iterate_phdr(dlopen_linked_libpython_cb, &path); | ||
| + if (rc != 0) { | ||
| + WARN("Failed searching for libpython " | ||
| + "among linked libraries: %s", strerror(rc)); | ||
| + return NULL; | ||
| + } else if (path == NULL) { | ||
| + WARN("Libpython is not found among linked libraries"); | ||
| + return NULL; | ||
| + } | ||
| + | ||
| + /* Dlopen the found library */ | ||
| + handle = dlopen(path, flags); | ||
| + if (handle == NULL) { | ||
| + WARN("Failed loading %s: %s", path, dlerror()); | ||
| + } | ||
| + free(path); |
|
|
|
Alright, I switched the patch to talloc and removed the "so" from the end of the pattern to try to handle Cygwin. I wonder, should I also remove the slash? |
|
Not sure, was hunting for docs on dlopen to see if it included the extension... I guess try it and see? :) |
|
Right, I was wrong about dl_iterate_phdr being widely available. Apparently wishful thinking doesn't work :) So, it's not on Cygwin, and the other platform support appears to be spotty. Do we have any options except scrapping the whole patch? |
|
POSIX only give us:
So doesn't look like it. Could pass in |
|
Yeah, POSIX is limited and it's not there. No, -l wouldn't help as it only (but perfectly correctly) has "python2.7", which is essentially what you already ask for in your dlopen call. I suspect there are similar interfaces on all the target platforms, but branching and using them all would be too much. One last idea that I have is to check for dl_iterate_phdr at configure time and compile the lookup conditionally. |
|
Situation isn't that bad actually. Linux, FreeBSD and Solaris 11 all support For OSX you have:
https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man3/dyld.3.html |
|
Yeah, older FreeBSD and Solaris releases don't have it. |
|
Alright, I'll make a patch which does the same this one does, but only if dh_iterate_phdr is present. Otherwise it will fallback to what we already have. I'd like to do the Mac OS X support, but I wasn't able to find anywhere to test it. Expect a new patch not later than tomorrow. |
|
Alright, this version uses dl_iterate_phdr only if it is found by configure and otherwise falls back to the old way of loading libpython. |
arr2036
commented on an outdated diff
Apr 28, 2016
|
Doh, yes, thank you, Arran. Fixed. |
|
@arr2036, is there anything you'd like me to do to this pull request, or could it be merged? |
|
Repeating here why I think this should still be merged, posted earlier on the maillist. First, this is not very OS-specific. This is a problem on all Linux distros. The version-less libraries are only for development, and at runtime you shouldn't expect them to be present and load the fully-versioned library instead. For example, on Debian Testing, without libpython2.7-dev installed, I get the
Second, even if we add it as a build-time patch, it will be a pain to maintain, especially since it touches "configure" and "config.h.in" files, which are generated. |
spbnick commentedApr 25, 2016
In rlm_python, dlopen libpython shared library at the actual path it was
linked with on loading, instead of just the version-less SONAME.
This removes the need to have the version-less SONAME symlink (e.g.
"libpython2.7.so") in library directory, which is normally installed
only with the development packages. I.e. this removes the requirement of
having python-devel/libpython-dev installed, when loading rlm_python.