Opened 7 years ago
Closed 7 years ago
#3869 closed defect (fixed)
PostGIS fails to link with the gold linker due to underlinking
Reported by: | mjo | Owned by: | pramsey |
---|---|---|---|
Priority: | medium | Milestone: | PostGIS 2.3.4 |
Component: | postgis | Version: | master |
Keywords: | Cc: |
Description
"gold" is a modern linker intended to (eventually) replace the traditional "BFD" linker:
https://en.wikipedia.org/wiki/Gold_%28linker%29
However, gold is more strict about underlinking than the BFD linker was, and unused symbols are omitted from the resulting binary. This causes a problem for PostGIS, where something — probably liblwgeom.so — is using symbols from the math library but is not linking it in with "-lm". I've reported this on the Gentoo bug tracker along with a full build log:
The fix is most likely simple, to add "-lm" to the linker command of any binary that uses the math functions. I've confirmed that this affects the latest SVN revision, and would be happy to test a patch.
For convenience, I'll reproduce the error message here:
libtool: link: x86_64-pc-linux-gnu-gcc -I ../liblwgeom -march=native -O2 -pipe -fPIC -DPIC -Wall -Wmissing-prototypes shpopen.o dbfopen.o getopt.o shpcommon.o safileio.o shp2pgsql-core.o shp2pgsql-cli.o -o .libs/shp2pgsql -Wl,-O1 -Wl,-rpath -Wl,/usr/lib64/postgresql-9.4/lib64 -Wl,--enable-new-dtags ../liblwgeom/.libs/liblwgeom.so -L/usr/lib64 -lgeos_c -lproj -ljson-c -L/usr/lib64/postgresql-9.4/lib64 -Wl,--as-needed -lc ../liblwgeom/.libs/liblwgeom.so: error: undefined reference to 'sqrt' ../liblwgeom/.libs/liblwgeom.so: error: undefined reference to 'atan' ../liblwgeom/.libs/liblwgeom.so: error: undefined reference to 'floor' ../liblwgeom/.libs/liblwgeom.so: error: undefined reference to 'atan2' ../liblwgeom/.libs/liblwgeom.so: error: undefined reference to 'sincos' ../liblwgeom/.libs/liblwgeom.so: error: undefined reference to 'remainder' ../liblwgeom/.libs/liblwgeom.so: error: undefined reference to 'acos' ../liblwgeom/.libs/liblwgeom.so: error: undefined reference to 'asin' ../liblwgeom/.libs/liblwgeom.so: error: undefined reference to 'sin' ../liblwgeom/.libs/liblwgeom.so: error: undefined reference to 'cos' ../liblwgeom/.libs/liblwgeom.so: error: undefined reference to 'log10' ../liblwgeom/.libs/liblwgeom.so: error: undefined reference to 'log' ../liblwgeom/.libs/liblwgeom.so: error: undefined reference to 'tan' collect2: error: ld returned 1 exit status make[1]: *** [Makefile:103: shp2pgsql] Error 1 make[1]: Leaving directory '/var/tmp/portage/dev-db/postgis-2.1.8-r1/work/postgis-2.1.8/loader'
(Adding "-lm" to the linker command above fixes the problem, but that may not be the best place to do it if liblwgeom is the one trying to use the math functions.)
Change History (8)
comment:2 by , 7 years ago
Okay your above shows postgis-2.1.8 which is pretty ancient. Have you tried this with postgis-2.3.3?
I tried it with 2.1.8, 2.3.3, SVN trunk, and a few versions in between. They all crash at the same spot.
comment:4 by , 7 years ago
Can you please try r15864 = 6a05f66d449fc313752016aa022076ef5d3dfa58 (refs/remotes/svn/trunk) ? The math link was already used in liblwgeom/cunit, not sure why it wasn't used in liblwgeom. Maybe because PostgreSQL link line would add it in when putting everything together in the postgis module…
If confirmed to fix the problem this should likely be backported back up to 2.2 branch
Okay your above shows postgis-2.1.8 which is pretty ancient. Have you tried this with postgis-2.3.3? I think we've reworked liblwgeom links since postgis-2.1 days but not sure if those fix your issue or not.
I should also note that postgis-2.1.9 was the last release we will ever do for postgis-2.1 chain. We EOL'd it last week.
Thanks, Regina