This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libstdc++/55872] New: Crash issue with RTLD_DEEPBIND usage with stdc++ library


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 <dlfcn.h>
#include <iostream>

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<library_function_type>(function)();
    dlclose(handle);
    return 0;
}

cat library.cpp
#include <sstream>
#include <iostream>

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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]