public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/65485] New: Use openmp in dynamic library but not in calling program causes segfault at the end of execution
@ 2015-03-20 8:58 thomas.izard at silkan dot com
2015-03-20 9:42 ` [Bug c++/65485] " thomas.izard at silkan dot com
0 siblings, 1 reply; 2+ messages in thread
From: thomas.izard at silkan dot com @ 2015-03-20 8:58 UTC (permalink / raw)
To: gcc-bugs
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug c++/65485] Use openmp in dynamic library but not in calling program causes segfault at the end of execution
2015-03-20 8:58 [Bug c++/65485] New: Use openmp in dynamic library but not in calling program causes segfault at the end of execution thomas.izard at silkan dot com
@ 2015-03-20 9:42 ` thomas.izard at silkan dot com
0 siblings, 0 replies; 2+ messages in thread
From: thomas.izard at silkan dot com @ 2015-03-20 9:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65485
--- Comment #2 from thomas.izard at silkan dot com ---
(In reply to Jakub Jelinek from comment #1)
> Can't reproduce, works just fine here (Fedora 21, x86_64).
Do you launch the program several times ? Some executions are correct (program
does not segfault everytime). I think it depends on the order the threads are
killed.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-03-20 9:23 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-20 8:58 [Bug c++/65485] New: Use openmp in dynamic library but not in calling program causes segfault at the end of execution thomas.izard at silkan dot com
2015-03-20 9:42 ` [Bug c++/65485] " thomas.izard at silkan dot com
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).