Solved failed: /usr/local/openjdk8/jre/lib/amd64/server/libjvm.so: Undefined symbol "pthread_set_name_np"

Dear members,
I am trying to install pljava (java PL support for PostgreSQL, triggers), I have successfully built pljava, and installed it, but when I try to create the extension I get :
Code:
[local] [448] 5bed6f0c.1c0 2018-11-15 15:10:36.784 EET psql postgres@dynacom line:15 WARNING:  Java virtual machine not yet loaded
[local] [448] 5bed6f0c.1c0 2018-11-15 15:10:36.784 EET psql postgres@dynacom line:16 DETAIL:  dlopen (/usr/local/openjdk8/jre/lib/amd64/server/libjvm.so) failed: /usr/local/openjdk8/jre/lib/amd64/server/libjvm.so: Undefined symbol "pthread_set_name_np"
[local] [448] 5bed6f0c.1c0 2018-11-15 15:10:36.784 EET psql postgres@dynacom line:17 HINT:  SET pljava.libjvm_location TO the correct path to the jvm library (libjvm.so or jvm.dll, etc.)
[local] [448] 5bed6f0c.1c0 2018-11-15 15:10:36.784 EET psql postgres@dynacom line:18 CONTEXT:  PL/pgSQL function call_weeklycheck_before() line 6 at assignment
[local] [448] 5bed6f0c.1c0 2018-11-15 15:10:36.784 EET psql postgres@dynacom line:19 ERROR:  cannot use PL/Java before successfully completing its setup

It used to work with openjdk7, by doing :
Code:
postgres@smadev:~% ldd /usr/local/openjdk8/jre/lib/amd64/server/libjvm.so
/usr/local/openjdk8/jre/lib/amd64/server/libjvm.so:
        libm.so.5 => /lib/libm.so.5 (0x801dd8000)
        libc++.so.1 => /usr/lib/libc++.so.1 (0x802005000)
        libcxxrt.so.1 => /lib/libcxxrt.so.1 (0x8022d3000)
        libc.so.7 => /lib/libc.so.7 (0x800823000)
        libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x8024f2000)
postgres@smadev:~%
I see no linking to libthr, whereas if I ldd jdk7 I get :
Code:
postgres@smadev:~% ldd /pgsqlbig/SMADEV_BACKUP/usr/local/openjdk7/jre/lib/amd64/server/libjvm.so
/pgsqlbig/SMADEV_BACKUP/usr/local/openjdk7/jre/lib/amd64/server/libjvm.so:
        libm.so.5 => /lib/libm.so.5 (0x801d42000)
        libc++.so.1 => /usr/lib/libc++.so.1 (0x801f6f000)
        libcxxrt.so.1 => /lib/libcxxrt.so.1 (0x80223d000)
        libthr.so.3 => /lib/libthr.so.3 (0x80245c000)
        libc.so.7 => /lib/libc.so.7 (0x800823000)
        libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x802684000)
postgres@smadev:~%
And it indeed runs with jd7.

However, jdk7 is no more on this machine, and also pljava was compiled with jdk8. Any ideas?
 
Pasting the fine response and solution from the pljava developers :

https://github.com/tada/pljava/issues/202

This seems to suggest a problem with that build of openjdk8, in that somewhere the code must contain a reference to pthread_set_name_np but the DT_NEEDED for libthr was not included in libjvm.so. Perhaps readelf -s /usr/local/openjdk8/jre/lib/amd64/server/libjvm.so would show an UND reference to pthread_set_name_np ... that would be the simplest case, and make a concise bug report for the openjdk 8 package. I wonder how something like that would have escaped testing though. Perhaps there is a libthr DT_NEEDED in /usr/local/openjdk8/jre/bin/java or in /usr/local/openjdk8/jre/lib/amd64/jli/libjli.so, and so the library is found when java is invoked from the command line, and there was no test for loading libjvm.so dynamically. In any case, a simple example C program that tries to dlopen libjvm.so and launch a VM ought to demonstrate the problem; that could perhaps be added in the openjdk 8 freebsd package build as a regression test. Workarounds if the openjdk 8 package can't be fixed? On Mac OS X, it seems to be possible (or was at one time) to load PL/Java by pointing pljava.libjvm_location at libjli instead of libjvm. I don't think that works on every platform, but it could be worth trying; if it works, it is an easy workaround. It might not be very difficult to create an otherwise-empty shared object that has DT_NEEDED entries for libthr and libjvm, and then point pljava.libjvm_location at that. Or libthr could be added to an LD_PRELOAD variable in PostgreSQL's starting environment.

Indeed LD_PRELOAD solved this. I'll post it over at freebsd-java .
 
Back
Top