public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "thomas.izard at silkan dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/65485] New: Use openmp in dynamic library but not in calling program causes segfault at the end of execution Date: Fri, 20 Mar 2015 08:58:00 -0000 [thread overview] Message-ID: <bug-65485-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65485 Bug ID: 65485 Summary: Use openmp in dynamic library but not in calling program causes segfault at the end of execution Product: gcc Version: 4.9.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: thomas.izard at silkan dot com Consider: #include "omp.h" #include <iostream> extern "C" { int test() { int N = omp_get_max_threads(); #pragma omp parallel num_threads(N) { std::cout << omp_get_thread_num() << std::endl; } return 0; } }; Compiled with g++ -fopenmp -shared -fPIC -Wall -Wextra -o shared.so shared.cpp (no warnings/no errors). and : #include <iostream> #include <dlfcn.h> int main() { void* handle = dlopen("./shared.so", RTLD_NOW); if (!handle) { std::cerr << "can not open shared.so" << std::endl; return 1; } int(*f)() = (int(*)()) dlsym(handle,"test"); if (!f) { std::cerr << "can not find 'test' symbol in shared.so" << std::endl; return 1; } (*f)(); if (dlclose(handle)) { std::cerr << "can not close shared.so" << std::endl; return 1; } return 0; } compiled with: g++ -Wall -Wextra -o main main.cpp -ldl (no warnings/no errors). The main program loads the dynamic library and calls the "test" function. It does not directly use openmp. The problem is that a segmentation fault happen at the very end of the program. According to valgrind, at this point some threads are still active. Adding a -fopenmp flag while compiling the main program does not fix the problem. It seems that in this case the compiled code is not linked to GOMP (confirmed by ldd). The only workaround is to actually add an OpenMP directive (or a call to an OpenMP runtime function) in the main.cpp file. Same issue with (at least): g++-4.6.4, g++-4.7, g++-4.8.2 Systems used : Linux 3.2.0-77-generic #114-Ubuntu SMP (Ubuntu 64 12.04) Linux 3.13.0-43-generic #72-Ubuntu SMP (Ubuntu 64 server 14.04) Thomas
next reply other threads:[~2015-03-20 8:07 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2015-03-20 8:58 thomas.izard at silkan dot com [this message] 2015-03-20 9:42 ` [Bug c++/65485] " thomas.izard at silkan dot com
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-65485-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).