Public bug reported:

Binary package hint: gcc-4.4

I have main in c, which dlopens a c++ shared object. Upon calling a
function (obtained with dlsym) in this c++ lib which uses cerr, there is
segmentation fault. It happens only if the shared object links to some
other libraries (like gomp or GL, even if unused). It doesn't happen if
the main program is compiled with g++ however.

Here are sources (I will attach those as well) and below is backtrace
from the debug version of libstdc++.

I am running fully updated karmic; the same problem occurs at an updated
hardy and Debian lenny (I don't have access to other systems).

This is minimal testcase, I have this problem when importing c++
(boost::python) module into python.

=== main.c ===
#include<dlfcn.h>
int main(void){
        void* handle=dlopen("./libfoo.so",RTLD_NOW);
        void(*foo)()=(void(*)())dlsym(handle,"foo");
        foo();
        return 0;
}

=== foo.cc ===
#include<iostream>
extern "C" {
        void foo() { std::cerr<<"foo"<<std::endl; }
}

=== regular run ===
$ g++ foo.cc -o libfoo.so -fPIC -rdynamic -shared
$ gcc main.c -o main -ldl
$ ./main
foo

=== link libfoo.so to another lib ===
$ g++ foo.cc -o libfoo.so -fPIC -rdynamic -shared -lgomp # might be GL, perhaps 
others as well
$ gcc main.c -o main -ldl
$ ./main 
foozsh: segmentation fault (core dumped)  ./main

=== compile main with g++, still link with gomp ===
$ g++ foo.cc -o libfoo.so -fPIC -rdynamic -shared -lgomp
$ g++ main.c -o main -ldl
$ ./main
foo

=== gdb bt from the crasher ===
$ g++ foo.cc -o libfoo.so -fPIC -rdynamic -shared -lgomp -g
$ gcc main.c -o main -ldl -g
$ LD_LIBRARY_PATH=/usr/lib/debug ./main
foozsh: segmentation fault (core dumped)  LD_LIBRARY_PATH=/usr/lib/debug ./main
$ gdb main core

[ ... ]

(gdb) bt
#0  0x00007f81582c9e49 in std::uncaught_exception () at 
../../../../src/libstdc++-v3/libsupc++/eh_catch.cc:136
#1  0x00007f8158294e04 in ~sentry (this=0x7fff3c47bbc0, __in_chrg=<value 
optimized out>) at 
/build/buildd/gcc-4.4-4.4.1/build/x86_64-linux-gnu/libstdc++-v3/include/ostream:408
#2  0x00007f8158295445 in std::__ostream_insert<char, std::char_traits<char> > 
(__out=..., __s=0x7f81590cf3be "foo", __n=3)
    at 
/build/buildd/gcc-4.4-4.4.1/build/x86_64-linux-gnu/libstdc++-v3/include/bits/ostream_insert.h:110
#3  0x00007f815829502e in std::operator<< <std::char_traits<char> > (__out=..., 
__s=0x7f81590cf3be "foo")
    at 
/build/buildd/gcc-4.4-4.4.1/build/x86_64-linux-gnu/libstdc++-v3/include/ostream:510
#4  0x00007f81590cf2e6 in foo () at foo.cc:3
#5  0x00000000004003a2 in main () at main.c:5

ProblemType: Bug
Architecture: amd64
Date: Tue Dec  1 09:56:47 2009
DistroRelease: Ubuntu 9.10
NonfreeKernelModules: fglrx
Package: libstdc++6 4.4.1-4ubuntu8
ProcEnviron:
 PATH=(custom, user)
 LANG=cs_CZ.UTF-8
 SHELL=/bin/zsh
ProcVersionSignature: Ubuntu 2.6.31-16.51~pre2-generic
SourcePackage: gcc-4.4
Uname: Linux 2.6.31-16-generic x86_64
XsessionErrors:
 (gnome-settings-daemon:1984): GLib-CRITICAL **: g_propagate_error: assertion 
`src != NULL' failed
 (polkit-gnome-authentication-agent-1:2557): GLib-CRITICAL **: 
g_once_init_leave: assertion `initialization_value != 0' failed
 (nautilus:2412): Eel-CRITICAL **: eel_preferences_get_boolean: assertion 
`preferences_is_initialized ()' failed
 (gnome-panel:2261): Gdk-WARNING **: 
/build/buildd/gtk+2.0-2.18.3/gdk/x11/gdkdrawable-x11.c:952 drawable is not a 
pixmap or window

** Affects: gcc-4.4 (Ubuntu)
     Importance: Undecided
         Status: New


** Tags: amd64 apport-bug

-- 
cerr crash in dlopen'ed c++ shared object, if linked to some libs
https://bugs.launchpad.net/bugs/490744
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.

-- 
ubuntu-bugs mailing list
ubuntu-bugs@lists.ubuntu.com
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to