Hello,
I am using log4cplus with my application in a following way:
make -C log4cplus
-std=c++11
NDC
and LOG4CPLUS_[DEBUG|INFO]
macros)The issue appears during app shutdown and produces following backtrace:
#0 0x00007fc9c530856b in malloc_consolidate () from /lib64/libc.so.6 #1 0x00007fc9c53090e7 in _int_free () from /lib64/libc.so.6 #2 0x00007fc9c5ea5189 in _M_dispose (__a=..., this=<optimized out>) at /usr/include/c++/4.8.2/bits/basic_string.h:249 #3 ~basic_string (this=0x1231c50, __in_chrg=<optimized out>) at /usr/include/c++/4.8.2/bits/basic_string.h:539 #4 ~basic_stringbuf (this=0x1231c08, __in_chrg=<optimized out>) at /usr/include/c++/4.8.2/sstream:64 #5 ~basic_ostringstream (this=0x1231c00, __in_chrg=<optimized out>, __vtt_parm=<optimized out>) at /usr/include/c++/4.8.2/sstream:453 #6 log4cplus::internal::per_thread_data::~per_thread_data (this=0x1231c00, __in_chrg=<optimized out>) at global-init.cxx:255 #7 0x00007fc9c5ea52e4 in log4cplus::threadCleanup () at global-init.cxx:391 #8 0x00007fc9c5ea530c in (anonymous namespace)::_static_log4cplus_initializer::~_static_log4cplus_initializer (this=<optimized out>, __in_chrg=<optimized out>) at global-init.cxx:553 #9 0x00007fc9c52c51ba in __cxa_finalize () from /lib64/libc.so.6 #10 0x00007fc9c5e8e063 in __do_global_dtors_aux () from /lib64/liblog4cplus-1.1.so.9 #11 0x00007ffecb9db980 in ?? () #12 0x00007fc9cc0a2b5a in _dl_fini () from /lib64/ld-linux-x86-64.so.2
NOTE: in case my app doesn't use dynamic plugins loading or all calls to log4cplus is wrapped (I mean there is no direct calls app->log4cplus, but only app->wrapper->log4cplus) the crash disappears.
Could you please point me to the reason of such behavior?
Diff:
The only thing I see imediately as odd is that your call stack contains references to
/lib64/liblog4cplus-1.1.so.9
. Is it the actual log4cplus that you have compiled or is it by a chance OS installed one?We build this lib. Our RHEL OS doesn't have this rpm from the box.
Could you please tell me what is wrong with this lib version?
btw, is this a proper way to build log4cplus for my app?
make -C log4cplus
Should I consider using multithreaded and c++11 version of log4cplus?
You definitely have to keep the same settings for the library and for your application, so either both C++11 or both not C++11.
I have compiled log4cplus and my wrapper with -std=c++11 flag - result is the same
I cannot tell what is going on. Can you try and run some os the tests that are built when the library is built? Do they crash? I think the easies it the
thread_test
test.The tests are passed successfully.
I guess there is a problem with static global variables and using htem from shared libraries, because once I have changed my plugins to be statically compiled into my app - the issue has gone.
Diff:
It seems I have found the root of this issue. This page describes it:
http://sofd.developer-works.com/article/28186806/Main+Program+and+Shared+Library+initializes+same+static+variable+in+__static_initialization_and_destruction_0
How do you figure that this is the case for us here? What if you modify the
~_static_log4cplus_initializer ()
and insert something likewrite(2,"dtor",4);
and run your test case? Does it actually printdtor
twice?For the time being the issue is not reproducible - I have changed my app to use static libs.