4
votes

Our project (in C++) needs to link against boost regex so we just locate the correct compiled libboost_regex_1.45.0 and tell g++ to link against it. Compiling is successful and we just get the right executable as expected. The problem is, each time we try to run the executable, it crashes before entering main() routine.

Attaching the generated core file with gdb, the backtrace command shows there's a segmentation fault during __bultin_strlen, which is resolved to strlen@@GLBC_2.2.5.

Since our executable is linked against several dynamic libraries, readelf -s is harnessed to identify the problematic symbol and it boils down to libboost_regex. However the referred symbol is already there in RHEL6 system folder /lib64/libc.so.

The question is, how can we get boost regex working properly?

  • OS: RHEL6.2
  • GCC: 4.3.2 / libstdc++6.0.13
  • Boost libraries is built by exactly the same toolset - user-config.bjam is customized

Static linking is not a good choice for us for various reasons.

The symbol info and ldd info is attached at https://gist.github.com/skyscribe/5184622

1
Have you looked at the complete backtrace? There's no constructor or static initialization of yours that is running?Some programmer dude
First make sure the compiler versions used to build your program and boost_regex match. Have you compiled boost from source, or did you install a precompiled version?Axel
@JoachimPileborg No, the backtrace just points to boost regex library - some RAII stuffs specific to Boost library's detail namespace, irrelevant with application logic. Even a very simple hello world program may crash, as long as this library is linked. Other libraries work fine though, like libboost_thread, which doesn't refer to symbols like xxx@@GLIBC_2.2.5Fei
Please post the traceback verbatim, and the output of ldd /path/to/libboost_regex.so.n. 1.8e9-where's-my-share m.
Please show line 28 (and the surrounding lines) of the file test.cpp. That's the origin of the crash, and inside your main function.Some programmer dude

1 Answers

0
votes

From the gdb backtrace, we see that the std::char_traits<char>::length method with argument \"http:\\\\/\\\\/localhostr.com\\\\/files\\\\/.+?\" is triggering the segmentation fault. g++ 4.3.2 introduced new Stack Smashing Protection features, which may interfere with the strlen length computation.

Recompile/relink your code with a recent g++ compiler and see if you solve this error. This sample code does not reproduce such error:

user@workstation ~
$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-pc-cygwin/4.5.3/lto-wrapper.exe
Target: i686-pc-cygwin
Configured with: /gnu/gcc/releases/respins/4.5.3-3/gcc4-4.5.3-3/src/gcc-4.5.3/configure --srcdir=/gnu/gcc/releases/respins/4.5.3-3/gcc4-4.5.3-3/src/gcc-4.5.3 --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --libexecdir=/usr/lib --datadir=/usr/share --localstatedir=/var --sysconfdir=/etc --datarootdir=/usr/share --docdir=/usr/share/doc/gcc4 -C --datadir=/usr/share --infodir=/usr/share/info --mandir=/usr/share/man -v --with-gmp=/usr --with-mpfr=/usr --enable-bootstrap --enable-version-specific-runtime-libs --libexecdir=/usr/lib --enable-static --enable-shared --enable-shared-libgcc --disable-__cxa_atexit --with-gnu-ld --with-gnu-as --with-dwarf2 --disable-sjlj-exceptions --enable-languages=ada,c,c++,fortran,java,lto,objc,obj-c++ --enable-graphite --enable-lto --enable-java-awt=gtk --disable-symvers --enable-libjava --program-suffix=-4 --enable-libgomp --enable-libssp --enable-libada --enable-threads=posix --with-arch=i686 --with-tune=generic --enable-libgcj-sublibs CC=gcc-4 CXX=g++-4 CC_FOR_TARGET=gcc-4 CXX_FOR_TARGET=g++-4 GNATMAKE_FOR_TARGET=gnatmake GNATBIND_FOR_TARGET=gnatbind --with-ecj-jar=/usr/share/java/ecj.jar
Thread model: posix
gcc version 4.5.3 (GCC)

user@workstation ~
$ cat test.cc
#include <iostream>
#include <string>

int main(int argc, char *argv[]) {
  char * a = "\"http:\\\\/\\\\/localhostr.com\\\\/files\\\\/.+?\"";
  int t =  std::char_traits<char>::length (a);
  std::cout << t << std::endl;
}

user@workstation ~
$ g++ -g test.cc
test.cc: In function ‘int main(int, char**)’:
test.cc:6:14: warning: deprecated conversion from string constant to ‘char*’

user@workstation ~
$ gdb a.exe
Reading symbols from /home/user/a.exe...done.
(gdb) b std::char_traits<char>::length
Breakpoint 1 at 0x4017f6: file /usr/lib/gcc/i686-pc-cygwin/4.5.3/include/c++/bits/char_traits.h, line 263.
(gdb) r
Starting program: /home/user/a.exe
[New Thread 764.0x5e4]
[New Thread 764.0x100c]

Breakpoint 1, std::char_traits<char>::length (__s=0x402080 "\"http:\\\\/\\\\/localhostr.com\\\\/files\\\\/.+?\"") at /usr/lib/gcc/i686-pc-cygwin/4.5.3/include/c++/bits/char_traits.h:263
263           { return __builtin_strlen(__s); }
(gdb) c
Continuing.
41
[Inferior 1 (process 764) exited normally]
(gdb)