From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30064 invoked by alias); 4 Jan 2013 10:28:58 -0000 Received: (qmail 30018 invoked by uid 48); 4 Jan 2013 10:28:39 -0000 From: "gauryogesh.nsit at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/55872] New: Crash issue with RTLD_DEEPBIND usage with stdc++ library Date: Fri, 04 Jan 2013 10:28:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Keywords: X-Bugzilla-Severity: major X-Bugzilla-Who: gauryogesh.nsit at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2013-01/txt/msg00284.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55872 Bug #: 55872 Summary: Crash issue with RTLD_DEEPBIND usage with stdc++ library Classification: Unclassified Product: gcc Version: 4.4.3 Status: UNCONFIRMED Severity: major Priority: P3 Component: libstdc++ AssignedTo: unassigned@gcc.gnu.org ReportedBy: gauryogesh.nsit@gmail.com Created attachment 29080 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=29080 LD_DEBUG=all output of failure executable Hello All, I faced crash issue while opening one library dynamically using RTLD_DEEPBIND flag. Scenario: I have one library.so which is having un-initiliazed variable of data type 'std::string' and main file is also having another variable of same data type i.e. 'std::string'. Both files are written in C++ code. If I execute this code then it result in crash resulting in free() call of libc. crash log: *** glibc detected *** ./a.out: free(): invalid pointer: 0x00007f1229894140 *** ======= Backtrace: ========= /lib/libc.so.6(+0x77806)[0x7f1228ded806] /lib/libc.so.6(cfree+0x73)[0x7f1228df40d3] /usr/lib/libstdc++.so.6(_ZNSs9_M_mutateEmmm+0x1ae)[0x7f122963cb0e] /usr/lib/libstdc++.so.6(_ZNSs14_M_replace_auxEmmmc+0x4a)[0x7f122963cdaa] ./library.so(library_function+0x36)[0x7f1228b74a66] ./a.out[0x400a89] /lib/libc.so.6(__libc_start_main+0xfd)[0x7f1228d94c4d] ./a.out[0x400959] If I initiliazed std::string variable in library code like " std::string empty_lib=""; then no crash is obeserved. I have checked output of LD_DEBUG=all for both case executable and checked that there is binding issue in crash scenario wrt to std::string. Please find exact test code: =============================================================== cat main.cpp #include #include int main() { char const * const library_name = "./library.so"; void * handle = dlopen(library_name, RTLD_NOW | RTLD_LOCAL | RTLD_DEEPBIND); std::string empty_main=""; typedef void (*library_function_type)(); void * function = dlsym(handle, "library_function"); reinterpret_cast(function)(); dlclose(handle); return 0; } cat library.cpp #include #include extern "C" { void library_function() { std::string empty_lib; char c = '/'; empty_lib = c; } } =============================================================== ---------------------------------------------------------------- Compilation commands: g++ -g -O2 -rdynamic -c -Wall -Wextra -fPIC -o library.o library.cpp ; g++ -shared -Wl,-export-dynamic -o library.so library.o g++ -g -O2 -Wall -Wextra main.cpp -ldl ---------------------------------------------------------------- Can someone please help in this regard and let me know what went wrong and how to solve this issue. Please note that if I remove RTLD_DEEPBIND flag while opening this library then I didn't get any crash. If I write same code in .c file instead of .cpp then no issues observed. Thanks in advance. Attached LD_DEBUG=all output for both working and non-working case: -- Regards, Yogesh Gaur.