OpenCV 2.4.8: java ant example causes SIGSEGV on CentOS 6.5 (Bug #3489)
Description
When I try to run the OpenCV 2.4.8 java ant example (SimpleSample.jar) on CentOS 6.5 64-bit, I get a SIGSEGV:
[java] # [java] # A fatal error has been detected by the Java Runtime Environment: [java] # [java] # SIGSEGV (0xb) at pc=0x000000393380c380, pid=30957, tid=140227056252672 [java] # [java] # JRE version: Java(TM) SE Runtime Environment (7.0_51-b13) (build 1.7.0_51-b13) [java] # Java VM: Java HotSpot(TM) 64-Bit Server VM (24.51-b03 mixed mode linux-amd64 compressed oops) [java] # Problematic frame: [java] # C [libpthread.so.0+0xc380] pthread_spin_lock+0x0 [java] # [java] # Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again [java] #
I used cmake-2.8.12.1, python-2.7.3, and jdk-7u51-linux-x64. If you only have a Windows machine, you can reproduce this problem by loading a centos 6.5 iso into an Oracle VM VirtualBox. Here are the steps to reproduce the problem (centos requires a little extra work to get python 2.7 installed, because you can't uninstall python 2.6):
1. Download the opencv zip: http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.8/opencv-2.4.8.zip/download
2. Run the following commands:
sudo yum groupinstall "Development tools"
sudo yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gtk2-devel ant
wget http://www.cmake.org/files/v2.8/cmake-2.8.12.1.tar.gz
tar xf cmake-2.8.12.1.tar.gz
cd cmake-2.8.12.1
./bootstrap
make
sudo make install
cd ..
wget http://download.oracle.com/otn-pub/java/jdk/7u51-b13/jdk-7u51-linux-x64.rpm
sudo rpm -ihv jdk-7u51-linux-x64.rpm
wget http://python.org/ftp/python/2.7.3/Python-2.7.3.tar.bz2
tar xf Python-2.7.3.tar.bz2
cd Python-2.7.3
./configure --prefix=/usr/local --enable-shared
make
sudo make altinstall
sudo -s
echo "/usr/local/lib" > /etc/ld.so.conf.d/libpython2.7.conf
ldconfig
exit
cd ..
wget http://pypi.python.org/packages/source/d/distribute/distribute-0.6.35.tar.gz --no-check-certificate
tar xf distribute-0.6.35.tar.gz
cd distribute-0.6.35
sudo /usr/local/bin/python2.7 setup.py install
cd ..
sudo /usr/local/bin/easy_install-2.7 numpy
unzip opencv-2.4.8.zip
cd opencv-2.4.8
mkdir release
cd release
export JAVA_HOME=/usr/java/latest
cmake .. -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=/usr/local -DPYTHON_EXECUTABLE=/usr/local/bin/python2.7 -DPYTHON_INCLUDE_DIR=/usr/local/include/python2.7/ -DPYTHON_LIBRARY=/usr/local/lib/libpython2.7.so.1.0 -DPYTHON_NUMPY_INCLUDE_DIR=/usr/local/lib/python2.7/site-packages/numpy-1.8.0-py2.7-linux-x86_64.egg/numpy/core/include/ -DPYTHON_PACKAGES_PATH=/usr/local/lib/python2.7/site-packages/
make
sudo make install
cd ../samples/java/ant
ant -DocvJarDir=/usr/local/share/OpenCV/java/ -DocvLibDir=/usr/local/share/OpenCV/java/
Associated revisions
Fixed bug #3489: The code assumed that two global variables would be constructed in a particular order, but global variable initialization order is compiler-dependent.
Fixed bug #3489: The code assumed that two global variables would be constructed in a particular order, but global variable initialization order is compiler-dependent.
(cherry picked from commit 6bf599b1bca8a58c7a656ddc169f7be0fc3094c6)
History
Updated by Drew Jetter about 11 years ago
Here is a backtrace from gdb:
Program received signal SIGSEGV, Segmentation fault. [Switching to Thread 0x7f4736b19700 (LWP 14218)] 0x000000393380c380 in pthread_spin_lock () from /lib64/libpthread.so.0 (gdb) backtrace #0 0x000000393380c380 in pthread_spin_lock () from /lib64/libpthread.so.0 #1 0x00007f4719053e0c in cv::Mutex::Impl::lock (this=0x0) at /home/djetter/Downloads/opencv-2.4.8/modules/core/src/system.cpp:901 #2 0x00007f4719053f93 in cv::Mutex::lock (this=0x7f471a0ce080) at /home/djetter/Downloads/opencv-2.4.8/modules/core/src/system.cpp:953 #3 0x00007f4719051c4b in cv::AutoLock::AutoLock (this=0x7f4736b17560, m=...) at /home/djetter/Downloads/opencv-2.4.8/modules/core/include/opencv2/core/core.hpp:4815 #4 0x00007f4719054a94 in cv::TLSContainerStorage::allocateKey (this= 0x7f471a0ce080, pContainer=0x7f471a1668e0) at /home/djetter/Downloads/opencv-2.4.8/modules/core/src/system.cpp:1104 #5 0x00007f47190550b2 in cv::TLSDataContainer::TLSDataContainer (this= 0x7f471a1668e0) at /home/djetter/Downloads/opencv-2.4.8/modules/core/src/system.cpp:1137 #6 0x00007f4719758b2e in cv::TLSData<cv::ocl::CommandQueue>::TLSData (this= 0x7f471a1668e0) at /home/djetter/Downloads/opencv-2.4.8/modules/core/include/opencv2/core/core.hpp:4842 #7 0x00007f471975f6a7 in __static_initialization_and_destruction_0 ( __initialize_p=1, __priority=65535) at /home/djetter/Downloads/opencv-2.4.8/modules/ocl/src/cl_context.cpp:560 #8 0x00007f471975f843 in global constructors keyed to cl_context.cpp(void) () at /home/djetter/Downloads/opencv-2.4.8/modules/ocl/src/cl_context.cpp:924 #9 0x00007f4719a54276 in __do_global_ctors_aux () from /home/djetter/Downloads/opencv-2.4.8/samples/java/ant/build/jar/libopencv_java248.so #10 0x00007f4718d7a1bb in _init () from /home/djetter/Downloads/opencv-2.4.8/samples/java/ant/build/jar/libopencv_java248.so #11 0x0000003900000000 in ?? () #12 0x0000003932c0e555 in _dl_init_internal () from /lib64/ld-linux-x86-64.so.2 #13 0x0000003932c12cb5 in dl_open_worker () from /lib64/ld-linux-x86-64.so.2 #14 0x0000003932c0e1b6 in _dl_catch_error () from /lib64/ld-linux-x86-64.so.2 #15 0x0000003932c124fa in _dl_open () from /lib64/ld-linux-x86-64.so.2 #16 0x0000003933000f66 in dlopen_doit () from /lib64/libdl.so.2 #17 0x0000003932c0e1b6 in _dl_catch_error () from /lib64/ld-linux-x86-64.so.2 #18 0x000000393300129c in _dlerror_run () from /lib64/libdl.so.2 #19 0x0000003933000ee1 in dlopen@@GLIBC_2.2.5 () from /lib64/libdl.so.2 #20 0x00007f47372d262e in ?? () from /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.51.x86_64/jre/lib/amd64/server/libjvm.so #21 0x00007f473713c21d in JVM_LoadLibrary () from /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.51.x86_64/jre/lib/amd64/server/libjvm.so #22 0x00007f47365ed8b7 in Java_java_lang_ClassLoader_00024NativeLibrary_load () from /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.51.x86_64/jre/lib/amd64/libjava.so
Updated by Drew Jetter about 11 years ago
After inspecting the backtrace, I believe this is a case of "static initialization order fiasco". The two problem static variables are:
static TLSContainerStorage tlsContainerStorage; (at modules/core/src/system.cpp:1132) cv::TLSData<CommandQueue> commandQueueTLSData; (at modules/ocl/src/cl_context.cpp:560)
It looks like the code is assuming that tlsContainerStorage
will be constructed before commandQueueTLSData
, but in this case, commandQueueTLSData
is constructed before tlsContainerStorage
. The commandQueueTLSData
constructor attempts to call tlsContainerStorage.allocateKey
, and that function in turn tries to create an AutoLock
by passing in the mutex_
member variable.
However, since tlsContainerStorage
has not been constructed, then mutex_
has not been constructed either, and so its impl
variable is just pointing to random memory. When impl->lock()
gets called, pthread_spin_lock
is called on the sl
structure. However, since the impl
pointer is invalid, then the sl
structure must be invalid as well, and a segmentation fault occurs.
So, I believe I have identified the problem. Now I just need to figure out how to fix it...
Updated by Drew Jetter about 11 years ago
Submitted pull request 2171.
Updated by Alexander Smorkalov about 11 years ago
- Category set to core
- Target version set to 2.4.9
- Pull request set to https://github.com/Itseez/opencv/pull/2171
Updated by Andrew Senin about 11 years ago
Thank you for submitting the pull request!
- Status changed from New to Open
Updated by Andrey Pavlenko about 11 years ago
- Status changed from Open to Done