|
Boost Users : |
Subject: [Boost-users] [regex] Segmentation fault on regex_search only on CentOS
From: Narinder Claire (narinder.claire_at_[hidden])
Date: 2011-07-14 18:53:45
Hi
I'll illustrate the problem I have seen in the past with an example.
It may or may not be directly or indirectly linked with the seg fault
issue you are seeing. Although mine is not a seg fault, it does
demonstrate very different behaviour between gcc on Centos (4.1.2)
and gcc on Ubuntu (4.5.2)
Consider the following 3 source files:
main.cpp ->
----------------------------------
#include<iostream>
#include"my_exception.h"
using namespace std;
void foo();
int main()
{
try
{
foo();
}
catch(const my_exception &err)
{
cout << err.what();
}
//catch(const exception &err)
//{
//cout << "OOPs unknown error ";
//}
cout <<"\n";
}
----------------------------------
dll.cpp ->
----------------------------------
#include"my_exception.h"
void __attribute__ ((visibility("default"))) foo()
{
throw my_exception();
}
----------------------------------
my_exception.h ->
----------------------------------
#include<exception>
class my_exception: public std::exception
{
public:
virtual const char* what() const throw()
{
return "my_exception";
}
my_exception()throw(){}
virtual ~my_exception()throw(){}
};
----------------------------------
and the following makefile
makefile ->
----------------------------------
CXX=g++
all:
$(CXX) dll.cpp -fvisibility=hidden -fPIC -shared -o libdll.so
$(CXX) main.cpp -fPIC -L./ -ldll -o main
clean:
rm -fr lib*.so main
----------------------------------
Compiled on Centos 5.6 with gcc with the following specs:
Using built-in specs.
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--enable-checking=release --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-libgcj-multifile
--enable-languages=c,c++,objc,obj-c++,java,fortran,ada
--enable-java-awt=gtk --disable-dssi --disable-plugin
--with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre
--with-cpu=generic --host=x86_64-redhat-linux
Thread model: posix
gcc version 4.1.2 20080704 (Red Hat 4.1.2-50)
The output is :
terminate called after throwing an instance of 'my_exception'
what(): my_exception
Aborted
However compiled with gcc on Ubuntu 11.04 with specs:
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro
4.5.2-8ubuntu4'
--with-bugurl=file:///usr/share/doc/gcc-4.5/README.Bugs
--enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr
--program-suffix=-4.5 --enable-shared --enable-multiarch
--with-multiarch-defaults=x86_64-linux-gnu --enable-linker-build-id
--with-system-zlib --libexecdir=/usr/lib/x86_64-linux-gnu
--without-included-gettext --enable-threads=posix
--with-gxx-include-dir=/usr/include/c++/4.5
--libdir=/usr/lib/x86_64-linux-gnu --enable-nls --with-sysroot=/
--enable-clocale=gnu --enable-libstdcxx-debug
--enable-libstdcxx-time=yes --enable-plugin --enable-gold
--enable-ld=default --with-plugin-ld=ld.gold --enable-objc-gc
--disable-werror --with-arch-32=i686 --with-tune=generic
--enable-checking=release --build=x86_64-linux-gnu
--host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.5.2 (Ubuntu/Linaro 4.5.2-8ubuntu4)
The output is :
my_exception
If I execute the Ubuntu compiled binary on Centos I still get the same
'Aborted' output.
If I execute the Centos compiled binary on Ubuntu I get the expected
output of the string 'my_exception'
This suggests that the 'difference' is not coming from the compiler
but from the runtime.
As stated before this may not be related to your seg fault issue but
the authors of regex could most likely tell straight away.
Best Wishes
N
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net