public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/67791] New: Crash using std::thread and iostream with dynamic loading of a shared library
@ 2015-09-30 21:58 nexyon at gmail dot com
  2015-09-30 21:59 ` [Bug libstdc++/67791] " nexyon at gmail dot com
                   ` (15 more replies)
  0 siblings, 16 replies; 17+ messages in thread
From: nexyon at gmail dot com @ 2015-09-30 21:58 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67791

            Bug ID: 67791
           Summary: Crash using std::thread and iostream with dynamic
                    loading of a shared library
           Product: gcc
           Version: 5.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: nexyon at gmail dot com
  Target Milestone: ---

Created attachment 36430
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=36430&action=edit
the source of the shared library

If you think the summary of this bug is long/strange: yes, to me this seems
like the most weird bug, I have ever found.

What I am doing is the following:

* I have a main program (main.cpp) that loads a dynamic library thread.so and
calls a function in there.
* main.cpp also includes <iostream> without actually using this library.
(sounds weird, eh?)
* The function in thread.so creates a std::thread and runs it.
* The application crashes when the thread should be started.

Let me show you what happens (or: how to reproduce):

--------------

% g++ -g -fPIC -shared -o thread.so thread.cpp -std=c++11 -lpthread
% g++ -g -ldl -o main main.cpp
%  gdb main
        GNU gdb (GDB) 7.10
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-unknown-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from main...done.
(gdb) r
Starting program: /data/Work/Computer/Programming/Audaspace/bug/main 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".

Program received signal SIGSEGV, Segmentation fault.
0x0000000000000000 in ?? ()
(gdb) bt full
#0  0x0000000000000000 in ?? ()
No symbol table info available.
#1  0x00007ffff790e493 in __gthread_create (__args=<optimized out>,
__func=0x7ffff790e330 <std::(anonymous
namespace)::execute_native_thread_routine(void*)>, __threadid=0x7fffffffdd60)
    at
/build/gcc-multilib/src/gcc-build/x86_64-unknown-linux-gnu/libstdc++-v3/include/x86_64-unknown-linux-gnu/bits/gthr-default.h:662
No locals.
#2  std::thread::_M_start_thread (this=0x7fffffffdd60, __b=...) at
/build/gcc-multilib/src/gcc-5.2.0/libstdc++-v3/src/c++11/thread.cc:149
No locals.
#3  0x00007ffff6d99826 in std::thread::thread<void (&)(int, unsigned long
long*), int, unsigned long long*&>(void (&)(int, unsigned long long*), int&&,
unsigned long long*&) (this=0x7fffffffdd60, __f=
    @0x7ffff6d993e2: {void (int, unsigned long long *)} 0x7ffff6d993e2
<factorial(int, unsigned long long*)>) at /usr/include/c++/5.2.0/thread:137
No locals.
#4  0x00007ffff6d99463 in run () at thread.cpp:17
        a = 4196233
        c = 0x7fffffffdd70
        t1 = {_M_id = {_M_thread = 0}}
#5  0x0000000000400793 in main (argc=1, argv=0x7fffffffdea8) at main.cpp:9
        handle = 0x612c40
        run_func = 0x7ffff6d99430 <run()>
(gdb)

--------------

Now why is this weird/funny?

There are two ways you can get rid of the crash:

* the first is to add -lpthread to the second g++ line (the one that compiles
main.cpp and links the main program) OR
* you remove the line #include <iostream> in main.cpp

I found this bug in a way bigger code base as you can imagine and I already
spent a lot of time to get it down to this minimal example. I hope you can
find, what is the problem here! Thanks!


^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2023-08-07 20:02 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-30 21:58 [Bug libstdc++/67791] New: Crash using std::thread and iostream with dynamic loading of a shared library nexyon at gmail dot com
2015-09-30 21:59 ` [Bug libstdc++/67791] " nexyon at gmail dot com
2015-10-01  0:22 ` pinskia at gcc dot gnu.org
2015-10-01  9:36 ` redi at gcc dot gnu.org
2015-10-01 19:19 ` nexyon at gmail dot com
2020-11-23 14:15 ` redi at gcc dot gnu.org
2020-11-23 16:42 ` [Bug libstdc++/67791] [8/9/10/11 Regression] " redi at gcc dot gnu.org
2020-11-24 14:59 ` cvs-commit at gcc dot gnu.org
2021-04-19 10:40 ` [Bug libstdc++/67791] [8/9/10 " redi at gcc dot gnu.org
2021-05-14  9:47 ` [Bug libstdc++/67791] [9/10 " jakub at gcc dot gnu.org
2021-06-01  8:07 ` rguenth at gcc dot gnu.org
2022-05-27  9:35 ` [Bug libstdc++/67791] [10 " rguenth at gcc dot gnu.org
2022-06-28 10:31 ` jakub at gcc dot gnu.org
2023-04-28 12:31 ` cvs-commit at gcc dot gnu.org
2023-04-28 14:58 ` redi at gcc dot gnu.org
2023-08-07 16:45 ` colin.davidson at codeplay dot com
2023-08-07 20:02 ` redi at gcc dot gnu.org

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).