You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Install script does not use pg_config's LIBDIR for runtime linking #1356
But the psycopg2 install script ignores everything that doesn't start with "-L", therefore it ignores the rpath configuration. Then, when psycopg2 is loaded by a uwsgi executable that has its own rpath the process exits with a "missing name" error because the fact that the executable has its own rpath prevents it from loading the psycopg2 library even though ldconfig has run and has properly configured the system.
See #1357. My original suggestion to pass pg_config's LDFLAGS to the linker was not correct because those flags are the ones that were used to build postgres so it doesn't follow that they should be used to build psycopg2 too. My solution in #1357 is to take just the LIBDIR from pg_config (which psycopg2's setup already used for compile-time linking) and use it for runtime linking.
changed the title [-]Install script does not pass pg_config's LDFLAGS to the linker[/-][+]Install script does not use pg_config's LIBDIR for runtime linking[/+]on Sep 22, 2021
My original suggestion to pass pg_config's LDFLAGS to the linker was not correct because those flags are the ones that were used to build postgres so it doesn't follow that they should be used to build psycopg2 too.
So, the real problem is that some "smarter" linking systems like libtool would use list of library directories to generate LDFLAGS for the linker in such a way, that if the library is already on the default linker path, then this path will be omitted, and if it is not, then it will be passed along with the -rpath flag to the linker, like -Wl,-rpath,'/usr/pgsql-12/lib', so that this path will be remembered in the shared module and used later at the load time.
For better or worse, distutils does not do those libtool dances, so what happens here is that the linking is successful, but loading at runtime fails, because in your case Postgres libdir is not on the loader path for whatever reason (broken installation, broken package, genius plan gone south, ...).
A more "correct" solution as compared to #1357, where you are adding libdir to rpath unconditionally on Linux, would be to actually replicate some of the libtool logic and write platform-specific code to check whether the libdir where libpq resides (or even all library_dirs — how about other dependencies of pscycopg?) is on the default loader path, and if not, then to add those paths that aren't to self.rpath. This would be platform-specific, e.g. on Linux something like the following would work to obtain the loader paths:
Your system is configured in a way that Postgres is not on the loader path, and if you don't like it, then you should fix your system by adding it, or else, if you have reasons why you configured it this way, then you have to live with the consequences of this choice by either supplying LDFLAGS=-Wl,-rpath,'/usr/pgsql-12/lib' at the compile time or adding libdir to LD_LIBRARY_PATH when you run the software depending on libpq.
Anyway, I would not complicate the world to support obscure edge cases like this with a lot of effort, or by adding libdir to rpath for everyone, which is bound to introduce a whole set of different problems and security issues... especially because if such systems are really configured this way for a reason, the best idea maybe would be to not interfere with that.
Activity
dvarrazzo commentedon Sep 22, 2021
Have you got a MR to suggest?
gtzampanakis commentedon Sep 22, 2021
See #1357. My original suggestion to pass pg_config's LDFLAGS to the linker was not correct because those flags are the ones that were used to build postgres so it doesn't follow that they should be used to build psycopg2 too. My solution in #1357 is to take just the LIBDIR from pg_config (which psycopg2's setup already used for compile-time linking) and use it for runtime linking.
[-]Install script does not pass pg_config's LDFLAGS to the linker[/-][+]Install script does not use pg_config's LIBDIR for runtime linking[/+]zyv commentedon Sep 25, 2022
So, the real problem is that some "smarter" linking systems like
libtoolwould use list of library directories to generateLDFLAGSfor the linker in such a way, that if the library is already on the default linker path, then this path will be omitted, and if it is not, then it will be passed along with the-rpathflag to the linker, like-Wl,-rpath,'/usr/pgsql-12/lib', so that this path will be remembered in the shared module and used later at the load time.For better or worse,
distutilsdoes not do thoselibtooldances, so what happens here is that the linking is successful, but loading at runtime fails, because in your case Postgreslibdiris not on the loader path for whatever reason (broken installation, broken package, genius plan gone south, ...).A more "correct" solution as compared to #1357, where you are adding
libdirtorpathunconditionally on Linux, would be to actually replicate some of thelibtoollogic and write platform-specific code to check whether thelibdirwherelibpqresides (or even alllibrary_dirs— how about other dependencies of pscycopg?) is on the default loader path, and if not, then to add those paths that aren't toself.rpath. This would be platform-specific, e.g. on Linux something like the following would work to obtain the loader paths:Your system is configured in a way that Postgres is not on the loader path, and if you don't like it, then you should fix your system by adding it, or else, if you have reasons why you configured it this way, then you have to live with the consequences of this choice by either supplying
LDFLAGS=-Wl,-rpath,'/usr/pgsql-12/lib'at the compile time or addinglibdirtoLD_LIBRARY_PATHwhen you run the software depending onlibpq.Anyway, I would not complicate the world to support obscure edge cases like this with a lot of effort, or by adding
libdirtorpathfor everyone, which is bound to introduce a whole set of different problems and security issues... especially because if such systems are really configured this way for a reason, the best idea maybe would be to not interfere with that.