------- Comment #2 from mjtruog at fastmail dot ca  2010-01-10 18:16 -------
I have been trying to make a simple test case for the ostringstream problem but
have not yet found one.  However, I have been able to make a test case for the
crash when using std::cerr.  The problems are probably related in some way, but
the std::ostringstream one I found may be harder to recreate.  I have the files
to replicate the std::cerr crash scenario below:

main.cpp:

#include <dlfcn.h>
#include <iostream>

// compile with: g++ -g -O0 main.cpp -ldl

int main()
{
    char const * const library_name = "./library.so";
    void * handle = dlopen(library_name, RTLD_NOW | RTLD_LOCAL |
RTLD_DEEPBIND);
    char const * const dlopen_error = dlerror();
    if (! handle)
    {
        std::cerr << "dlopen error: " << dlopen_error << std::endl;
        return 1;
    }
    typedef void (*library_function_type)();
    void * function = dlsym(handle, "library_function");
    char const * const dlsym_error = dlerror();
    if (dlsym_error)
    {
        std::cerr << "dlsym error: " << dlsym_error << std::endl;
        dlclose(handle);
        return 1;
    }
    reinterpret_cast<library_function_type>(function)();
    dlclose(handle);
    return 0;
}

library1.cpp:

#include <sstream>
#include <iostream>

// example of SEGFAULT when writing to std::cerr

// compile with:
// g++ -g -O0 -rdynamic -c -fPIC -o library.o library1.cpp
// g++ -shared -Wl,-export-dynamic -o library.so library.o

extern "C"
{

void library_function()
{
    std::clog << "std::cerr will segfault" << std::endl;
    std::cerr << "crash me";
}

}


-- 

mjtruog at fastmail dot ca changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |UNCONFIRMED


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42679

Reply via email to