Mantis - Resin
Viewing Issue Advanced Details
485 minor always 12-06-05 18:21 02-02-06 15:39
spatula1  
ferg FreeBSD  
normal 6.0  
closed 3.0.14  
fixed  
none    
none 3.0.18  
0000485: Resin on FreeBSD may compile against the wrong threading library
Starting in FreeBSD 5.1, users may choose from one of three threading libraries, the default of which is libpthread, no longer libc_r. The other choice is libthr. To make matters more interesting, libmap.conf allows users to specify which threading library to substitute for another at runtime. So even if a binary is compiled against libpthread, it can be coerced to run against libc_r at runtime.

Unfortunately, if multiple threading libraries are in use in a single program, chaos results. This can happen with the Resin JNI library if it is compiled against a different threading library than the one used by Java. It is necessary to detect which threading library is in use and compile against that one.

The default threading library in FreeBSD 5 and later is libpthread.
Here's a patch, albeit a bit messy, that illustrates a way to detect the correct threading library to use:

--- configure.orig Tue Dec 6 16:25:21 2005
+++ configure Tue Dec 6 17:58:29 2005
@@ -8739,7 +8739,65 @@
        ;;
 
   *freebsd*)
- PROXY_LIBS='-lc_r'
+
+ freebsd_version_major=`uname -r | sed -e 's/\([0-9]\{1,\}\).*/\1/'`
+ freebsd_version_minor=`uname -r | sed -e 's/^[0-9]\{1,\}\.\([0-9]\{1,\}\).*/\1/'`
+
+ if [ \( $freebsd_version_major -gt 5 \) -o \( $freebsd_version_major -eq 5 -a $freebsd_version_minor -ge 1 \) ]
+ then
+ echo Using FreeBSD ${freebsd_version_major}.${freebsd_version_minor}\; checking which threading library to use
+
+ if [ `file -L $JAVA_HOME/bin/java | grep -c "shell script"` -eq 1 ]
+ then
+ echo "You must specify --with-java-home ($JAVA_HOME/bin/java is a wrapper script)"
+ exit
+ fi
+
+ if [ `file -L $JAVA_HOME/bin/java | grep -c "Linux"` -eq 1 -a "${enable_jni+set}" = set ]
+ then
+ echo "Cannot build JNI library for Linux VM (use native FreeBSD VM or disable JNI)"
+ exit
+ fi
+
+ if [ `file -L $JAVA_HOME/bin/java | grep -c "Linux"` -eq 0 ]
+ then
+ thread_lib=`ldd $JAVA_HOME/bin/java | sed 's/.*=>//' | grep -c libc_r`
+ thread_lib=${thread_lib}`ldd $JAVA_HOME/bin/java | sed 's/.*=>//' | grep -c libpthread`
+ thread_lib=${thread_lib}`ldd $JAVA_HOME/bin/java | sed 's/.*=>//' | grep -c libthr`
+ case "$thread_lib" in
+ 100)
+ PROXY_LIBS='-lc_r'
+ ;;
+ 010)
+ PROXY_LIBS='-lpthread'
+ ;;
+ 001)
+ PROXY_LIBS='-lthr'
+ ;;
+ *)
+ echo "Can't figure out which threading library is in use by Java!"
+ exit;
+ ;;
+ esac
+
+ echo
+ echo Using ${PROXY_LIBS} for threading.
+ echo
+ echo "NOTE: If you change Java's thread library via libmap.conf(5) or a recompile,"
+ echo you MUST configure and compile Resin again!
+ echo
+ echo "ALSO NOTE: if you're using the threading MP model in Apache 2, you must use"
+ echo the same threading library for Apache as you use in Java, or manually edit
+ echo the Makefile to ensure that the correct threading library is linked to
+ echo mod_caucho. Use ldd on the httpd binary to determine which threading
+ echo library is in use.
+ echo
+
+ fi
+ else
+ PROXY_LIBS='-lc_r'
+ fi
+
         jni_os=freebsd
        ;;
 

There are no notes attached to this issue.