public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug sanitizer/57507] New: gcc 4.8: thread sanitizer: std::thread false(?) positive
@ 2013-06-03  8:54 alxchk at alxchk dot me
  2013-06-03  9:07 ` [Bug sanitizer/57507] " kcc at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: alxchk at alxchk dot me @ 2013-06-03  8:54 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 57507
           Summary: gcc 4.8: thread sanitizer: std::thread false(?)
                    positive
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: sanitizer
          Assignee: unassigned at gcc dot gnu.org
          Reporter: alxchk at alxchk dot me
                CC: dodji at gcc dot gnu.org, dvyukov at gcc dot gnu.org,
                    jakub at gcc dot gnu.org, kcc at gcc dot gnu.org

$ cat test.cpp
#include <thread>

int main(int argc, char *argv[])
{
    std::thread t([](){});
    t.join();

    return 0;
}

$ LC_ALL=C g++ --version
g++ (Gentoo Hardened 4.8.0 p1.2, pie-0.5.5) 4.8.0
Copyright (C) 2013 Free Software Foundation, Inc.

$ g++ -o test test.cpp --std=gnu++11 -pthread -fsanitize=thread -ggdb3 -O0
$ ./test
==================
WARNING: ThreadSanitizer: data race (pid=14129)
  Write of size 8 at 0x7d080000bfc8 by thread T1:
    #0 <null> <null>:0 (libtsan.so.0+0x000000020dc0)
    #1 deallocate
/usr/lib/gcc/x86_64-pc-linux-gnu/4.8.0/include/g++-v4/ext/new_allocator.h:110
(exe+0x000000002b42)
    #2 deallocate
/usr/lib/gcc/x86_64-pc-linux-gnu/4.8.0/include/g++-v4/bits/alloc_traits.h:377
(exe+0x000000002972)
    #3 _M_destroy
/usr/lib/gcc/x86_64-pc-linux-gnu/4.8.0/include/g++-v4/bits/shared_ptr_base.h:417
(exe+0x000000003336)
    #4 <null> <null>:0 (libstdc++.so.6+0x0000000c8cea)

  Previous atomic write of size 4 at 0x7d080000bfc8 by main thread:
    #0 <null> <null>:0 (libtsan.so.0+0x00000000dfc5)
    #1 __exchange_and_add
/usr/lib/gcc/x86_64-pc-linux-gnu/4.8.0/include/g++-v4/ext/atomicity.h:47
(exe+0x000000001898)
    #2 __exchange_and_add_dispatch
/usr/lib/gcc/x86_64-pc-linux-gnu/4.8.0/include/g++-v4/ext/atomicity.h:80
(exe+0x000000001995)
    #3 std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release()
/usr/lib/gcc/x86_64-pc-linux-gnu/4.8.0/include/g++-v4/bits/shared_ptr_base.h:141
(exe+0x000000003c86)
    #4 std::__shared_count<(__gnu_cxx::_Lock_policy)2>::~__shared_count()
/usr/lib/gcc/x86_64-pc-linux-gnu/4.8.0/include/g++-v4/bits/shared_ptr_base.h:553
(exe+0x000000003c2d)
    #5 std::__shared_ptr<std::thread::_Impl_base,
(__gnu_cxx::_Lock_policy)2>::~__shared_ptr()
/usr/lib/gcc/x86_64-pc-linux-gnu/4.8.0/include/g++-v4/bits/shared_ptr_base.h:810
(exe+0x000000003aae)
    #6 std::shared_ptr<std::thread::_Impl_base>::~shared_ptr()
/usr/lib/gcc/x86_64-pc-linux-gnu/4.8.0/include/g++-v4/bits/shared_ptr.h:93
(exe+0x000000003afc)
    #7 thread<main(int, char**)::__lambda0>
/usr/lib/gcc/x86_64-pc-linux-gnu/4.8.0/include/g++-v4/thread:135
(exe+0x000000001c10)
    #8 main /tmp/test.cpp:5 (exe+0x000000001a3e)

  Location is heap block of size 56 at 0x7d080000bfc0 allocated by main thread:
    #0 <null> <null>:0 (libtsan.so.0+0x000000020ad2)
    #1 allocate
/usr/lib/gcc/x86_64-pc-linux-gnu/4.8.0/include/g++-v4/ext/new_allocator.h:104
(exe+0x000000002a5b)
    #2 allocate
/usr/lib/gcc/x86_64-pc-linux-gnu/4.8.0/include/g++-v4/bits/alloc_traits.h:351
(exe+0x000000002881)
    #3 __shared_count<std::thread::_Impl<std::_Bind_simple<main(int,
char**)::__lambda0()> >,
std::allocator<std::thread::_Impl<std::_Bind_simple<main(int,
char**)::__lambda0()> > >, std::_Bind_simple<main(int, char**)::__lambda0()> >
/usr/lib/gcc/x86_64-pc-linux-gnu/4.8.0/include/g++-v4/bits/shared_ptr_base.h:519
(exe+0x0000000026e5)
    #4
__shared_ptr<std::allocator<std::thread::_Impl<std::_Bind_simple<main(int,
char**)::__lambda0()> > >, std::_Bind_simple<main(int, char**)::__lambda0()> >
/usr/lib/gcc/x86_64-pc-linux-gnu/4.8.0/include/g++-v4/bits/shared_ptr_base.h:986
(exe+0x0000000025a1)
    #5 shared_ptr<std::allocator<std::thread::_Impl<std::_Bind_simple<main(int,
char**)::__lambda0()> > >, std::_Bind_simple<main(int, char**)::__lambda0()> >
/usr/lib/gcc/x86_64-pc-linux-gnu/4.8.0/include/g++-v4/bits/shared_ptr.h:316
(exe+0x000000002511)
    #6 allocate_shared<std::thread::_Impl<std::_Bind_simple<main(int,
char**)::__lambda0()> >,
std::allocator<std::thread::_Impl<std::_Bind_simple<main(int,
char**)::__lambda0()> > >, std::_Bind_simple<main(int, char**)::__lambda0()> >
/usr/lib/gcc/x86_64-pc-linux-gnu/4.8.0/include/g++-v4/bits/shared_ptr.h:598
(exe+0x000000002422)
    #7 make_shared<std::thread::_Impl<std::_Bind_simple<main(int,
char**)::__lambda0()> >, std::_Bind_simple<main(int, char**)::__lambda0()> >
/usr/lib/gcc/x86_64-pc-linux-gnu/4.8.0/include/g++-v4/bits/shared_ptr.h:614
(exe+0x00000000225a)
    #8 _M_make_routine<std::_Bind_simple<main(int, char**)::__lambda0()> >
/usr/lib/gcc/x86_64-pc-linux-gnu/4.8.0/include/g++-v4/thread:193
(exe+0x000000001fa2)
    #9 thread<main(int, char**)::__lambda0>
/usr/lib/gcc/x86_64-pc-linux-gnu/4.8.0/include/g++-v4/thread:135
(exe+0x000000001bde)
    #10 main /tmp/test.cpp:5 (exe+0x000000001a3e)

  Thread T1 (tid=14130, running) created by main thread at:
    #0 <null> <null>:0 (libtsan.so.0+0x000000022cdb)
    #1 <null> <null>:0 (libstdc++.so.6+0x0000000c8ef6)
    #2 main /tmp/test.cpp:5 (exe+0x000000001a3e)

SUMMARY: ThreadSanitizer: data race ??:0 ??
==================
ThreadSanitizer: reported 1 warnings


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

* [Bug sanitizer/57507] gcc 4.8: thread sanitizer: std::thread false(?) positive
  2013-06-03  8:54 [Bug sanitizer/57507] New: gcc 4.8: thread sanitizer: std::thread false(?) positive alxchk at alxchk dot me
@ 2013-06-03  9:07 ` kcc at gcc dot gnu.org
  2013-06-03  9:40 ` redi at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: kcc at gcc dot gnu.org @ 2013-06-03  9:07 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Kostya Serebryany <kcc at gcc dot gnu.org> ---
FTR: we don't yet officially support C++11 treads, so this is quite expected.
Patches and tests (to the upstream repo) are welcome


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

* [Bug sanitizer/57507] gcc 4.8: thread sanitizer: std::thread false(?) positive
  2013-06-03  8:54 [Bug sanitizer/57507] New: gcc 4.8: thread sanitizer: std::thread false(?) positive alxchk at alxchk dot me
  2013-06-03  9:07 ` [Bug sanitizer/57507] " kcc at gcc dot gnu.org
@ 2013-06-03  9:40 ` redi at gcc dot gnu.org
  2013-06-03 13:21 ` dvyukov at google dot com
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2013-06-03  9:40 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Would supporting std::shared_ptr solve the problem?  The problem seems to be
due to not understanding that the atomic ops used by shared_ptr are atomic.


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

* [Bug sanitizer/57507] gcc 4.8: thread sanitizer: std::thread false(?) positive
  2013-06-03  8:54 [Bug sanitizer/57507] New: gcc 4.8: thread sanitizer: std::thread false(?) positive alxchk at alxchk dot me
  2013-06-03  9:07 ` [Bug sanitizer/57507] " kcc at gcc dot gnu.org
  2013-06-03  9:40 ` redi at gcc dot gnu.org
@ 2013-06-03 13:21 ` dvyukov at google dot com
  2021-12-06  5:11 ` pinskia at gcc dot gnu.org
  2021-12-06  5:13 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: dvyukov at google dot com @ 2013-06-03 13:21 UTC (permalink / raw)
  To: gcc-bugs

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

Dmitry Vyukov <dvyukov at google dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dvyukov at google dot com

--- Comment #3 from Dmitry Vyukov <dvyukov at google dot com> ---
The problem is that libstdc++ is not instrumented. It makes atomic accesses to
the shared_ptr that tsan does not see.

Here are the only events related to address that tsan sees (the first number is
thread id):

#0: alloc(48) = 0x7d0c0000efd0
#0: MemoryAccess: @0x7f5094bb5021 0x7d0c0000efd0 size=8 is_write=0
shadow_mem=0x04300003bf40 {402418, 0, 0, 0}
#0: __tsan_atomic32_fetch_add(0x7d0c0000efd8, 4)
#0: MemoryAccess: @0x7f5094bcd8d4 0x7d0c0000efd8 size=4 is_write=1
shadow_mem=0x04300003bf60 {402418, 0, 0, 0}
#1: free(0x7d0c0000efd0)
#1: MemoryAccessRange: @0x7f5094bb6c27 0x7d0c0000efd0 size=48 is_write=1
  Write of size 8 at 0x7d0c0000efd8 by thread T1:
  Previous atomic write of size 4 at 0x7d0c0000efd8 by main thread:
  Location is heap block of size 48 at 0x7d0c0000efd0 allocated by main thread:

And here the stack where we detect the race:

#0  __tsan::ReportRace (thr=0x7f8a1c35e800) at tsan_rtl_report.cc:596
#1  0x00007f8a1c520565 in __tsan::__tsan_report_race () at tsan_rtl.cc:351
#2  0x00007f8a1c5205b8 in __tsan::HandleRace (thr=0x7f8a1c35e800,
shadow_mem=0x4300003bf60, cur=..., old=...) at tsan_rtl.cc:378
#3  0x00007f8a1c5381a3 in __tsan::MemoryAccessImpl (thr=0x7f8a1c35e800,
addr=137490493140952, kAccessSizeLog=3, kAccessIsWrite=true, kIsAtomic=false,
shadow_mem=0x4300003bf60, cur=...)
    at tsan_rtl.cc:462
#4  0x00007f8a1c5438ca in __tsan::MemoryAccessRange (thr=0x7f8a1c35e800,
pc=140231157189671, addr=137490493140952, size=40, is_write=true) at
tsan_rtl_thread.cc:363
#5  0x00007f8a1c522952 in __tsan::MemoryRangeFreed (thr=0x7f8a1c35e800,
pc=140231157189671, addr=137490493140944, size=48) at tsan_rtl.cc:607
#6  0x00007f8a1c5187e6 in __tsan::user_free (thr=0x7f8a1c35e800,
pc=140231157189671, p=0x7d0c0000efd0) at tsan_mman.cc:138
#7  0x00007f8a1c4f8c4b in operator delete (ptr=0x7d0c0000efd0) at
tsan_interceptors.cc:519
#8  0x00007f8a1c4f61ee in
__gnu_cxx::new_allocator<std::_Sp_counted_ptr_inplace<std::thread::_Impl<std::_Bind_simple<main(int,
char**)::<lambda()>()> >,
std::allocator<std::thread::_Impl<std::_Bind_simple<main(int,
char**)::<lambda()>()> > >, (__gnu_cxx::_Lock_policy)2u>
>::deallocate(__gnu_cxx::new_allocator<std::_Sp_counted_ptr_inplace<std::thread::_Impl<std::_Bind_simple<main(int,
char**)::<lambda()>()> >,
std::allocator<std::thread::_Impl<std::_Bind_simple<main(int,
char**)::<lambda()>()> > >, (__gnu_cxx::_Lock_policy)2u> >::pointer,
__gnu_cxx::new_allocator<std::_Sp_counted_ptr_inplace<std::thread::_Impl<std::_Bind_simple<main(int,
char**)::<lambda()>()> >,
std::allocator<std::thread::_Impl<std::_Bind_simple<main(int,
char**)::<lambda()>()> > >, (__gnu_cxx::_Lock_policy)2u> >::size_type)
(this=0x7f8a1c35de4f, __p=0x7d0c0000efd0) at
gccinstall/include/c++/4.9.0/ext/new_allocator.h:110
#9  0x00007f8a1c4f60dd in
std::allocator_traits<std::allocator<std::_Sp_counted_ptr_inplace<std::thread::_Impl<std::_Bind_simple<main(int,
char**)::<lambda()>()> >,
std::allocator<std::thread::_Impl<std::_Bind_simple<main(int,
char**)::<lambda()>()> > >, (__gnu_cxx::_Lock_policy)2u> >
>::deallocate(std::allocator<std::_Sp_counted_ptr_inplace<std::thread::_Impl<std::_Bind_simple<main(int,
char**)::<lambda()>()> >,
std::allocator<std::thread::_Impl<std::_Bind_simple<main(int,
char**)::<lambda()>()> > >, (__gnu_cxx::_Lock_policy)2u> > &,
std::allocator_traits<std::allocator<std::_Sp_counted_ptr_inplace<std::thread::_Impl<std::_Bind_simple<main(int,
char**)::<lambda()>()> >,
std::allocator<std::thread::_Impl<std::_Bind_simple<main(int,
char**)::<lambda()>()> > >, (__gnu_cxx::_Lock_policy)2u> > >::pointer,
std::allocator_traits<std::allocator<std::_Sp_counted_ptr_inplace<std::thread::_Impl<std::_Bind_simple<main(int,
char**)::<lambda()>()> >,
std::allocator<std::thread::_Impl<std::_Bind_simple<main(int,
char**)::<lambda()>()> > >, (__gnu_cxx::_Lock_policy)2u> > >::size_type)
(__a=..., __p=0x7d0c0000efd0, __n=1)
    at gccinstall/include/c++/4.9.0/bits/alloc_traits.h:377
#10 0x00007f8a1c4f6855 in
std::_Sp_counted_ptr_inplace<std::thread::_Impl<std::_Bind_simple<main(int,
char**)::<lambda()>()> >,
std::allocator<std::thread::_Impl<std::_Bind_simple<main(int,
char**)::<lambda()>()> > >, (__gnu_cxx::_Lock_policy)2u>::_M_destroy(void)
(this=0x7d0c0000efd0) at
gccinstall/include/c++/4.9.0/bits/shared_ptr_base.h:454
#11 0x00007f8a1bc56e7b in _M_release (this=0x7d0c0000efd0) at
gccbuild/x86_64-unknown-linux-gnu/libstdc++-v3/include/bits/shared_ptr_base.h:163
#12 ~__shared_count (this=<synthetic pointer>, __in_chrg=<optimized out>)
    at
gccbuild/x86_64-unknown-linux-gnu/libstdc++-v3/include/bits/shared_ptr_base.h:589
#13 ~__shared_ptr (this=<synthetic pointer>, __in_chrg=<optimized out>)
    at
gccbuild/x86_64-unknown-linux-gnu/libstdc++-v3/include/bits/shared_ptr_base.h:846
#14 ~shared_ptr (this=<synthetic pointer>, __in_chrg=<optimized out>) at
gccbuild/x86_64-unknown-linux-gnu/libstdc++-v3/include/bits/shared_ptr.h:93
#15 std::(anonymous namespace)::execute_native_thread_routine (__p=<optimized
out>) at ../../../../../gcc/libstdc++-v3/src/c++11/thread.cc:95
#16 0x00007f8a1c4fb1e6 in __tsan_thread_start_func (arg=0x7fff46a94080) at
tsan_interceptors.cc:802
#17 0x00007f8a1c0b4e9a in start_thread (arg=0x7f8a1c3cf840) at
pthread_create.c:308
#18 0x00007f8a1b3c8ccd in clone () at
../sysdeps/unix/sysv/linux/x86_64/clone.S:112

We had a similar problem with libgomp:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55561


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

* [Bug sanitizer/57507] gcc 4.8: thread sanitizer: std::thread false(?) positive
  2013-06-03  8:54 [Bug sanitizer/57507] New: gcc 4.8: thread sanitizer: std::thread false(?) positive alxchk at alxchk dot me
                   ` (2 preceding siblings ...)
  2013-06-03 13:21 ` dvyukov at google dot com
@ 2021-12-06  5:11 ` pinskia at gcc dot gnu.org
  2021-12-06  5:13 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-06  5:11 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=65393

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #4)
> This should no longer be a problem, because std::thread doesn't use
> std::shared_ptr these days.

Which is/was PR 65393.

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

* [Bug sanitizer/57507] gcc 4.8: thread sanitizer: std::thread false(?) positive
  2013-06-03  8:54 [Bug sanitizer/57507] New: gcc 4.8: thread sanitizer: std::thread false(?) positive alxchk at alxchk dot me
                   ` (3 preceding siblings ...)
  2021-12-06  5:11 ` pinskia at gcc dot gnu.org
@ 2021-12-06  5:13 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-06  5:13 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |p.bartosiewi at partner dot samsun
                   |                            |g.com

--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 64337 has been marked as a duplicate of this bug. ***

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

end of thread, other threads:[~2021-12-06  5:13 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-03  8:54 [Bug sanitizer/57507] New: gcc 4.8: thread sanitizer: std::thread false(?) positive alxchk at alxchk dot me
2013-06-03  9:07 ` [Bug sanitizer/57507] " kcc at gcc dot gnu.org
2013-06-03  9:40 ` redi at gcc dot gnu.org
2013-06-03 13:21 ` dvyukov at google dot com
2021-12-06  5:11 ` pinskia at gcc dot gnu.org
2021-12-06  5:13 ` pinskia 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).