Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minimal infrastructure support for ThreadSanitizer #27167

Merged
merged 1 commit into from
Aug 5, 2020
Merged

Minimal infrastructure support for ThreadSanitizer #27167

merged 1 commit into from
Aug 5, 2020

Conversation

vchuravy
Copy link
Member

Inspired by the current progress on partr, I started looking into what
it takes to have a race detector like Go. This PR is the minimal change
necessary for people to build with thread-sanitizer enabled.

The big open question is how to move forward with this and how to enable
something as simplisitics as go -race for multi-threaded Julia code.

Current build requirements:

  • Clang (preferably build with BUILD_LLVM_CLANG=1)
  • add -fsanitize=thread and -DJL_TSAN_ENABLED=1 to JCFLAGS and co.

I am open for ideas to enable better integration. I was thinking that our
options are:

  1. Have a julia-san similar to julia-debug that has TSAN enabled
  2. Pretend tsan is a cpu-feature and enable it in the sysimage behind
    a feature flag, e.g. julia -race would load the sanitized version
    of the sysimage. The main challenge here is that the executing binary
    needs to have setup code for TSAN, so we couldn't use that from a
    non-sanitized Julia
  3. Go has special treatment in TSAN, and similarily instead off using the
    C/C++ TSAN we could build our own and hook that up correctly

@vchuravy vchuravy requested a review from maleadt May 19, 2018 00:35
@ararslan ararslan added the multithreading Base.Threads and related functionality label May 19, 2018
@vchuravy
Copy link
Member Author

One interesting thing is that TSan currently ignores loads and stores to non-zero addressspaces [1]. So to make it useful to Julia code, we will have to fix that.
There is also inspiration to draw from the Go [2] and Java support that TSan has, Java [3,4] as an example has hooks to tell TSan about allocations.

@vchuravy
Copy link
Member Author

@maleadt We should probably add the function annotation for MSAn/ASAN as well c.f https://reviews.llvm.org/D9631, TSAN didn't sanitize Julia functions due the the abnnotation missing.

Current results for Julia usercode:

using Base.Threads
function f()
  x = Ref[]
  @threads for i in 1:10000
       x[] += 1
   end
   return x[]
end
SUMMARY: ThreadSanitizer: data race (<unknown module>) 
==================
==================
WARNING: ThreadSanitizer: data race (pid=17987)
  Read of size 8 at 0x7fbe415ad060 by thread T2:
    #0 <null> <null> (0x7fbe393235f8)
    #1 <null> <null> (0x7fbe3932379f)
    #2 jl_fptr_args /home/vchuravy/src/julia/src/gf.c:1833:12 (libjulia.so.0.7+0x474d4)
    #3 ti_run_fun /home/vchuravy/src/julia/src/threading.c:311:9 (libjulia.so.0.7+0xbe8bb)
    #4 ti_threadfun /home/vchuravy/src/julia/src/threading.c:422:17 (libjulia.so.0.7+0xbe3e8)

  Previous write of size 8 at 0x7fbe415ad060 by main thread:
    #0 <null> <null> (0x7fbe39323616)
    #1 <null> <null> (0x7fbe3932379f)
    #2 jl_fptr_args /home/vchuravy/src/julia/src/gf.c:1833:12 (libjulia.so.0.7+0x474d4)
    #3 ti_run_fun /home/vchuravy/src/julia/src/threading.c:311:9 (libjulia.so.0.7+0xbe8bb)
    #4 jl_threading_run /home/vchuravy/src/julia/src/threading.c:722:15 (libjulia.so.0.7+0xbf457)
    #5 <null> <null> (0x7fbe393233d2)
    #6 jl_fptr_args /home/vchuravy/src/julia/src/gf.c:1833:12 (libjulia.so.0.7+0x474d4)
    #7 jl_fptr_trampoline /home/vchuravy/src/julia/src/gf.c:1823:12 (libjulia.so.0.7+0x45f94)
    #8 jl_apply_generic /home/vchuravy/src/julia/src/gf.c:2140:23 (libjulia.so.0.7+0x526e7)
    #9 do_call /home/vchuravy/src/julia/src/interpreter.c:324:26 (libjulia.so.0.7+0x25f1e1)
    #10 eval_value /home/vchuravy/src/julia/src/interpreter.c:416:16 (libjulia.so.0.7+0x25dd22)
    #11 eval_body /home/vchuravy/src/julia/src/interpreter.c (libjulia.so.0.7+0x25c4e8)
    #12 jl_interpret_toplevel_thunk_callback /home/vchuravy/src/julia/src/interpreter.c:798:21 (libjulia.so.0.7+0x25d29d)
    #13 enter_interpreter_frame <null> (libjulia.so.0.7+0x7044b)
    #14 jl_toplevel_eval_flex /home/vchuravy/src/julia/src/toplevel.c:856:22 (libjulia.so.0.7+0x9d44e)
    #15 jl_parse_eval_all /home/vchuravy/src/julia/src/ast.c:852:26 (libjulia.so.0.7+0x5ed2b)
    #16 jl_load /home/vchuravy/src/julia/src/toplevel.c:894:12 (libjulia.so.0.7+0x9f561)
    #17 jl_load_ /home/vchuravy/src/julia/src/toplevel.c:901 (libjulia.so.0.7+0x9f561)
    #18 include boot.jl:314 (sys.so+0x3d31e4)
    #19 japi1_include_relative_13176 loading.jl:1068 (sys.so+0x3d31e4)
    #20 japi1_include_13175 sysimg.jl:29 (sys.so+0x3d35b7)
    #21 jl_fptr_args /home/vchuravy/src/julia/src/gf.c:1833:12 (libjulia.so.0.7+0x474d4)
    #22 jl_apply_generic /home/vchuravy/src/julia/src/gf.c:2140:23 (libjulia.so.0.7+0x526e7)
    #23 julia_exec_options_14615 client.jl:327 (sys.so+0x462d47)
    #24 japi1__start_14605 client.jl:457 (sys.so+0x46342c)
    #25 jl_fptr_args /home/vchuravy/src/julia/src/gf.c:1833:12 (libjulia.so.0.7+0x474d4)
    #26 jl_apply_generic /home/vchuravy/src/julia/src/gf.c:2140:23 (libjulia.so.0.7+0x526e7)
    #27 jl_apply /home/vchuravy/src/julia/ui/../src/julia.h:1540:12 (julia+0x499678)
    #28 true_main /home/vchuravy/src/julia/ui/repl.c:109 (julia+0x499678)
    #29 main /home/vchuravy/src/julia/ui/repl.c:240:15 (julia+0x4994f1)

We need to improve the traces so that they are actually useful, and currently I am hitting a weird issue after cleaning up this PR:
(It reminds me of other issues I had with things being hidden by the expmap, but adding *; does not help)

ThreadSanitizer: can't find longjmp buf
FATAL: ThreadSanitizer CHECK failed: /home/vchuravy/src/julia/deps/srccache/llvm-6.0.0/projects/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc:545 "((0)) != (0)" (0x0, 0x0)
LLVMSymbolizer: error reading file: No such file or directory
    #0 __tsan::TsanCheckFailed(char const*, int, char const*, unsigned long long, unsigned long long) /home/vchuravy/src/julia/deps/srccache/llvm-6.0.0/projects/compiler-rt/lib/tsan/rtl/tsan_rtl_report.cc:48:24 (julia+0x48a12d)
    #1 __sanitizer::CheckFailed(char const*, int, char const*, unsigned long long, unsigned long long) /home/vchuravy/src/julia/deps/srccache/llvm-6.0.0/projects/compiler-rt/lib/sanitizer_common/sanitizer_termination.cc:79:24 (julia+0x4a62c9)
    #2 LongJmp(__tsan::ThreadState*, unsigned long*) [clone .constprop.152] /home/vchuravy/src/julia/deps/srccache/llvm-6.0.0/projects/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc:545:3 (julia+0x4280aa)
    #3 siglongjmp /home/vchuravy/src/julia/deps/srccache/llvm-6.0.0/projects/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc:646:10 (julia+0x43a402)
    #4 restore_stack /home/vchuravy/src/julia/src/task.c:193:5 (libjulia.so.0.7+0x7c7ee)
    #5 restore_stack /home/vchuravy/src/julia/src/task.c:189:9 (libjulia.so.0.7+0x7c79b)
    #6 <null> <null> ([stack]+0x1e747)

@vchuravy vchuravy force-pushed the vc/tsan branch 2 times, most recently from a393cfe to 5dc13d9 Compare May 20, 2018 21:53
@vchuravy
Copy link
Member Author

a weird issue after cleaning up this PR:

Working hypothesis, this is happening after I started sanitizing Julia code (and precompiled a sysimg).
So the managled_sp is probably in Julia code and this is similar to what we are seeing in the trace:

    #0 <null> <null> (0x7fbe393235f8)
    #1 <null> <null> (0x7fbe3932379f)

welp, I will have to teach TSAN about Julia then.

@vtjnash
Copy link
Member

vtjnash commented May 21, 2018

The stack is intentionally corrupt there. Try turning off COPY_STACKS. We still might need to inform TSAN when we allocate a new stack, but at least it’ll never be invalid.

@vchuravy
Copy link
Member Author

Without COPY_STACKS I get:

ThreadSanitizer: can't find longjmp buf
FATAL: ThreadSanitizer CHECK failed: /home/vchuravy/src/julia/deps/srccache/llvm-6.0.0/projects/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc:545 "((0)) != (0)" (0x0, 0x0)
    #0 __tsan::TsanCheckFailed(char const*, int, char const*, unsigned long long, unsigned long long) /home/vchuravy/src/julia/deps/srccache/llvm-6.0.0/projects/compiler-rt/lib/tsan/rtl/tsan_rtl_report.cc:48:24 (julia+0x48a12d)
    #1 __sanitizer::CheckFailed(char const*, int, char const*, unsigned long long, unsigned long long) /home/vchuravy/src/julia/deps/srccache/llvm-6.0.0/projects/compiler-rt/lib/sanitizer_common/sanitizer_termination.cc:79:24 (julia+0x4a62c9)
    #2 LongJmp(__tsan::ThreadState*, unsigned long*) [clone .constprop.152] /home/vchuravy/src/julia/deps/srccache/llvm-6.0.0/projects/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc:545:3 (julia+0x4280aa)
    #3 siglongjmp /home/vchuravy/src/julia/deps/srccache/llvm-6.0.0/projects/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc:646:10 (julia+0x43a402)
    #4 ctx_switch /home/vchuravy/src/julia/src/task.c:400:9 (libjulia.so.0.7+0x5df3c)
    #5 jl_switchto /home/vchuravy/src/julia/src/task.c:429:5 (libjulia.so.0.7+0x5dde4)
    #6 jlplt_jl_switchto_8518 <null> (sys.so+0x32b931)
    #7 japi1_try_yieldto_8516 event.jl:199 (sys.so+0x32be13)
    #8 japi1_wait_8497 event.jl:267 (sys.so+0x32c23a)
    #9 julia_uv_write_15213 stream.jl:786 (sys.so+0x697c43)
    #10 julia_unsafe_write_15212 stream.jl:834 (sys.so+0x697f35)
    #11 jfptr_unsafe_write_15213 <null> (sys.so+0x698354)
    #12 jl_apply_generic /home/vchuravy/src/julia/src/gf.c:2140:23 (libjulia.so.0.7+0x46fb6)
    #13 julia_unsafe_write_15193 io.jl:225 (sys.so+0x69636e)
    #14 macro expansion gcutils.jl:87 (sys.so+0x70b096)
    #15 write strings/io.jl:150 (sys.so+0x70b096)
    #16 print strings/io.jl:152 (sys.so+0x70b096)
    #17 japi1_banner_16443 version.jl:292 (sys.so+0x70b096)
    #18 japi1_banner_16442 /home/vchuravy/src/julia/usr/share/julia/stdlib/v0.7/REPL/src/REPL.jl:1033 (sys.so+0x70b73f)
    #19 jl_apply_generic /home/vchuravy/src/julia/src/gf.c:2140:23 (libjulia.so.0.7+0x46fb6)
    #20 <null> <null> (0x7fd48ef40232)
    #21 <null> <null> (0x7fd48ef3fdd3)
    #22 jl_fptr_trampoline /home/vchuravy/src/julia/src/gf.c:1823:12 (libjulia.so.0.7+0x40022)
    #23 jl_apply_generic /home/vchuravy/src/julia/src/gf.c:2140:23 (libjulia.so.0.7+0x46fb6)
    #24 jl_apply /home/vchuravy/src/julia/src/./julia.h:1540:12 (libjulia.so.0.7+0x52212)
    #25 jl_f__apply /home/vchuravy/src/julia/src/builtins.c:561 (libjulia.so.0.7+0x52212)
    #26 jl_f__apply_latest /home/vchuravy/src/julia/src/builtins.c:599:23 (libjulia.so.0.7+0x528ee)
    #27 #invokelatest#1 essentials.jl:668 (sys.so+0x67470c)
    #28 invokelatest essentials.jl:667 (sys.so+0x67470c)
    #29 julia_run_main_repl_14858 client.jl:400 (sys.so+0x67470c)
    #30 julia_exec_options_14803 client.jl:338 (sys.so+0x679d24)
    #31 japi1__start_14793 client.jl:457 (sys.so+0x67a4e9)
    #32 jl_apply_generic /home/vchuravy/src/julia/src/gf.c:2140:23 (libjulia.so.0.7+0x46fb6)
    #33 jl_apply /home/vchuravy/src/julia/ui/../src/julia.h:1540:12 (julia+0x4b3078)
    #34 true_main /home/vchuravy/src/julia/ui/repl.c:109 (julia+0x4b3078)
    #35 main /home/vchuravy/src/julia/ui/repl.c:240:15 (julia+0x4b2ef1)
    #36 __libc_start_main <null> (libc.so.6+0x2306a)
    #37 _start <null> (julia+0x41f559)

@vchuravy
Copy link
Member Author

@tkf can you try this? This should fix the compilation failures you were seeing.

@tkf
Copy link
Member

tkf commented Apr 12, 2020

@vchuravy Thanks a lot for rebasing this! I tried

make -C deps install-llvm
echo 'CXXFLAGS += -DNDEBUG' > Make.user
PATH="$PWD/usr/tools:$PATH" make USECLANG=1 SANITIZE=1 SANITIZE_THREAD=1

With 798bd91 I get

    LINK usr/bin/julia
/julia-tsan/usr/lib/libjulia.so: undefined reference to `__sanitizer_finish_switch_fiber'
/julia-tsan/usr/lib/libjulia.so: undefined reference to `__sanitizer_start_switch_fiber'
clang-9: error: linker command failed with exit code 1 (use -v to see invocation)
Makefile:86: recipe for target '/julia-tsan/usr/bin/julia' failed
make[1]: *** [/julia-tsan/usr/bin/julia] Error 1
Makefile:78: recipe for target 'julia-ui-release' failed
make: *** [julia-ui-release] Error 2

With df54f3b I get

    JULIA usr/lib/julia/sys-o.a                               
Generating precompile statements...ThreadSanitizer: can't find longjmp buf
FATAL: ThreadSanitizer CHECK failed: /workspace/srcdir/llvm-project/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc:530 "((0))
 != (0)" (0x0, 0x0)                                                    
LLVMSymbolizer: error reading file: No such file or directory                
    #0 __tsan::TsanCheckFailed(char const*, int, char const*, unsigned long long, unsigned long long) /workspace/srcdir/llvm
-project/compiler-rt/lib/tsan/rtl/tsan_rtl_report.cc:47 (julia+0x4c88f8)
    #1 __sanitizer::CheckFailed(char const*, int, char const*, unsigned long long, unsigned long long) /workspace/srcdir/llv
m-project/compiler-rt/lib/sanitizer_common/sanitizer_termination.cc:78 (julia+0x4370e5)
    #2 LongJmp(__tsan::ThreadState*, unsigned long*) /workspace/srcdir/llvm-project/compiler-rt/lib/tsan/rtl/tsan_intercepto
rs.cc:530 (julia+0x455482)                                             
    #3 siglongjmp /workspace/srcdir/llvm-project/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc:630 (julia+0x482076)
    #4 jl_swap_fiber /julia-tsan/src/task.c:923:5 (libjulia.so.1+0x11d31a)              
    #5 ctx_switch /julia-tsan/src/task.c:346:13 (libjulia.so.1+0x11c52e)                                
    #6 jl_switchto /julia-tsan/src/task.c:404:5 (libjulia.so.1+0x11c52e)
    #7 <null> <null> (memfd:julia-codegen (deleted)+0x3222f9)
    #8 <null> <null> (memfd:julia-codegen (deleted)+0x48e4a8)                                           
    #9 <null> <null> (memfd:julia-codegen (deleted)+0x48e8f5)               
    #10 <null> <null> (memfd:julia-codegen (deleted)+0x490caa)
    #11 <null> <null> (memfd:julia-codegen (deleted)+0x4911ad)
    #12 <null> <null> (memfd:julia-codegen (deleted)+0x493466)
    #13 <null> <null> (memfd:julia-codegen (deleted)+0x498647)
    #14 <null> <null> (memfd:julia-codegen (deleted)+0x4a4306)
    #15 <null> <null> (memfd:julia-codegen (deleted)+0x4a8fc5)
    #16 <null> <null> (memfd:julia-codegen (deleted)+0x4a906c)
    #17 _jl_invoke /julia-tsan/src/gf.c:2235:23 (libjulia.so.1+0xf46c8)
    #18 jl_apply_generic /julia-tsan/src/gf.c:2402:12 (libjulia.so.1+0xf46c8)
    #19 jl_apply /julia-tsan/src/./julia.h:1691:12 (libjulia.so.1+0x11748b)
    #20 do_call /julia-tsan/src/interpreter.c:369:26 (libjulia.so.1+0x11748b)
    #21 eval_value /julia-tsan/src/interpreter.c:458:16 (libjulia.so.1+0x1148dd)
    #22 eval_body /julia-tsan/src/interpreter.c (libjulia.so.1+0x11352e)
    #23 jl_interpret_toplevel_thunk /julia-tsan/src/interpreter.c:921:21 (libjulia.so.1+0x114296)
    #24 jl_toplevel_eval_flex /julia-tsan/src/toplevel.c:818:18 (libjulia.so.1+0x13ad0a)
    #25 jl_toplevel_eval /julia-tsan/src/toplevel.c:827:12 (libjulia.so.1+0x13c26d)
    #26 jl_toplevel_eval_in /julia-tsan/src/toplevel.c:850:13 (libjulia.so.1+0x13c26d)
    #27 <null> <null> (memfd:julia-codegen (deleted)+0x314767)
    #28 <null> <null> (memfd:julia-codegen (deleted)+0x40b6b1)
    #29 jl_fptr_args /julia-tsan/src/gf.c:1997:12 (libjulia.so.1+0xea3e4)
    #30 _jl_invoke /julia-tsan/src/gf.c:2235:23 (libjulia.so.1+0xf46c8)
    #31 jl_apply_generic /julia-tsan/src/gf.c:2402:12 (libjulia.so.1+0xf46c8)
    #32 jl_apply /julia-tsan/src/./julia.h:1691:12 (libjulia.so.1+0x11748b)
    #33 do_call /julia-tsan/src/interpreter.c:369:26 (libjulia.so.1+0x11748b)
    #34 eval_value /julia-tsan/src/interpreter.c:458:16 (libjulia.so.1+0x1148dd)
    #35 eval_body /julia-tsan/src/interpreter.c (libjulia.so.1+0x11352e)
    #36 jl_interpret_toplevel_thunk /julia-tsan/src/interpreter.c:921:21 (libjulia.so.1+0x114296)
    #37 jl_toplevel_eval_flex /julia-tsan/src/toplevel.c:818:18 (libjulia.so.1+0x13ad0a)
    #38 jl_parse_eval_all /julia-tsan/src/ast.c:912:26 (libjulia.so.1+0xfe795)
    #39 jl_load_rewrite /julia-tsan/src/toplevel.c:881:12 (libjulia.so.1+0x13c515)
    #40 jl_load /julia-tsan/src/toplevel.c:886:12 (libjulia.so.1+0x13c515)
    #41 <null> <null> (memfd:julia-codegen (deleted)+0x3163e7)
    #42 <null> <null> (memfd:julia-codegen (deleted)+0x3ea9d9)
    #43 <null> <null> (memfd:julia-codegen (deleted)+0x40a1c3)
    #44 jl_fptr_args /julia-tsan/src/gf.c:1997:12 (libjulia.so.1+0xea3e4)
    #45 _jl_invoke /julia-tsan/src/gf.c:2235:23 (libjulia.so.1+0xf46c8)
    #46 jl_apply_generic /julia-tsan/src/gf.c:2402:12 (libjulia.so.1+0xf46c8)
    #47 <null> <null> (memfd:julia-codegen (deleted)+0x408256)
    #48 <null> <null> (memfd:julia-codegen (deleted)+0x409c62)
    #49 <null> <null> (memfd:julia-codegen (deleted)+0x409d6c)
    #50 _jl_invoke /julia-tsan/src/gf.c:2235:23 (libjulia.so.1+0xf46c8)
    #51 jl_apply_generic /julia-tsan/src/gf.c:2402:12 (libjulia.so.1+0xf46c8)
    #52 jl_apply /julia-tsan/ui/../src/julia.h:1691:12 (julia+0x4d400f)
    #53 true_main /julia-tsan/ui/repl.c:96:13 (julia+0x4d400f)
    #54 main /julia-tsan/ui/repl.c:217:15 (julia+0x4d3e81)
    #55 __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310 (libc.so.6+0x21b96)
    #56 _start <null> (julia+0x41e2c9)
    
*** This error is usually fixed by running `make clean`. If the error persists, try `make cleanall`. ***
sysimage.mk:86: recipe for target '/julia-tsan/usr/lib/julia/sys-o.a' failed
make[1]: *** [/julia-tsan/usr/lib/julia/sys-o.a] Error 1
Makefile:87: recipe for target 'julia-sysimg-release' failed
make: *** [julia-sysimg-release] Error 2

@vchuravy
Copy link
Member Author

Yeah.... I was hoping that the ASAN hooks would work for TSAN as well, but apparently no such joy.

@vchuravy
Copy link
Member Author

Yes it looks like we need to use:

void *__tsan_create_fiber(unsigned flags)
void __tsan_destroy_fiber(void *fiber)
void __tsan_switch_to_fiber(void *fiber, unsigned flags) 
// optional
void __tsan_set_fiber_name(void *fiber, const char *name)

@vchuravy
Copy link
Member Author

Ok this now allows me to compile with tsan. There are a bunch of data races reported (which I don't recall from way back when), so we
need to figure out if those are spurious or real. As an example:

WARNING: ThreadSanitizer: data race (pid=14316)                                                                                                    
  Read of size 8 at 0x7fe6a72b0078 by thread T4:                                                                                                   
    #0 jl_typemap_entry_assoc_exact /data/vchuravy/src/julia/src/typemap.c:627 (libjulia-debug.so.1+0x233d37)                                      
    #1 jl_typemap_assoc_exact /data/vchuravy/src/julia/src/julia_internal.h:1063 (libjulia-debug.so.1+0x2237ba)                                    
    #2 jl_lookup_generic_ /data/vchuravy/src/julia/src/gf.c:2346 (libjulia-debug.so.1+0x22adbc)                                                    
    #3 jl_apply_generic /data/vchuravy/src/julia/src/gf.c:2398 (libjulia-debug.so.1+0x22b307)                                                      
    #4 jl_apply /data/vchuravy/src/julia/src/julia.h:1708 (libjulia-debug.so.1+0x277be4)                                                           
    #5 jl_finish_task /data/vchuravy/src/julia/src/task.c:216 (libjulia-debug.so.1+0x277a15)                                                       
    #6 jl_threadfun /data/vchuravy/src/julia/src/partr.c:265 (libjulia-debug.so.1+0x2f6011)                                                        
                                                                                                                                                   
  Previous write of size 8 at 0x7fe6a72b0078 by thread T5:                                                                                         
    #0 jl_typemap_insert /data/vchuravy/src/julia/src/typemap.c:894 (libjulia-debug.so.1+0x236113)                                                 
    #1 cache_method /data/vchuravy/src/julia/src/gf.c:1102 (libjulia-debug.so.1+0x22734e)                                                          
    #2 jl_mt_assoc_by_type /data/vchuravy/src/julia/src/gf.c:1205 (libjulia-debug.so.1+0x223e37)                                                   
    #3 jl_lookup_generic_ /data/vchuravy/src/julia/src/gf.c:2367 (libjulia-debug.so.1+0x22b12f)                                                    
    #4 jl_apply_generic /data/vchuravy/src/julia/src/gf.c:2398 (libjulia-debug.so.1+0x22b307)                                                      
    #5 jl_apply /data/vchuravy/src/julia/src/julia.h:1708 (libjulia-debug.so.1+0x277be4)                                                           
    #6 jl_finish_task /data/vchuravy/src/julia/src/task.c:216 (libjulia-debug.so.1+0x277a15)                                                       
    #7 jl_threadfun /data/vchuravy/src/julia/src/partr.c:265 (libjulia-debug.so.1+0x2f6011)                                                        
                                                                                                                                                   
  Thread T4 (tid=14320, running) created by main thread at:                                                                                        
    #0 pthread_create /workspace/srcdir/llvm-project/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc:967 (julia-debug+0x457615)                      
    #1 uv_thread_create_ex /workspace/srcdir/libuv/src/unix/thread.c:229 (libjulia-debug.so.1+0x5d77c3)                                            
    #2 _julia_init /data/vchuravy/src/julia/src/init.c:764 (libjulia-debug.so.1+0x27508e)                                                          
    #3 julia_init__threading /data/vchuravy/src/julia/src/task.c:266 (libjulia-debug.so.1+0x277f91)                                                
    #4 main /data/vchuravy/src/julia/ui/repl.c:211 (julia-debug+0x4d4032)                                                                          
                                                                                                                                                   
  Thread T5 (tid=14321, running) created by main thread at:
    #0 pthread_create /workspace/srcdir/llvm-project/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc:967 (julia-debug+0x457615)
    #1 uv_thread_create_ex /workspace/srcdir/libuv/src/unix/thread.c:229 (libjulia-debug.so.1+0x5d77c3)
    #2 _julia_init /data/vchuravy/src/julia/src/init.c:764 (libjulia-debug.so.1+0x27508e)
    #3 julia_init__threading /data/vchuravy/src/julia/src/task.c:266 (libjulia-debug.so.1+0x277f91)
    #4 main /data/vchuravy/src/julia/ui/repl.c:211 (julia-debug+0x4d4032)

@tkf
Copy link
Member

tkf commented Apr 15, 2020

I still get ThreadSanitizer: can't find longjmp buf with 1779f7a. Do I need to set COPY_STACKS to some value?

@Keno
Copy link
Member

Keno commented Aug 3, 2020

The task handling isn't quite right in this PR, but the PR itself is basically fine. Fixing the task handling requires some changes to the task interface that I'd like to do separately, since there's so many different configurations for that, so I'm gonna go ahead and rebase this and get it merged and then put up a separate PR to fix up the task switch annotations.

@@ -65,6 +65,23 @@
# define JL_THREAD_LOCAL
#endif

// Duplicated from options.h
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems oddly terrible. Can we delete it from there?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe put it in dtypes.h? We've seem to have accumulated a bunch of these kinds of things there.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, for the moment, there's probably no reason not to just put this here. Does raise the question of why jl_task_t is defined in the public header in the first place. We're never passing it by value, so it should probably move to the internals header, but we can do that separately.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, let me just do that first.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, we need the layout information in the public header because locks depend on it for ABI reasons. We should disentangle all of that at some point, but for now, I'll just leave this here and delete it elsewhere.

Copy link
Member

@vtjnash vtjnash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks valid. Should we add a note or new issue about adding tsan_destroy_fiber eventually?

@Keno
Copy link
Member

Keno commented Aug 3, 2020

Looks valid. Should we add a note or new issue about adding tsan_destroy_fiber eventually?

The fiber handling isn't quite right, there are ordering constraints on the tsan switch vs the setjmp that are not correct in this PR. I have it hacked up locally to work, but that requires some refactoring to do cleanly, which I'd like to do in a separate PR. I'll be adding the fiber destroy at the same time.

@vtjnash
Copy link
Member

vtjnash commented Aug 3, 2020

Yeah, there's some somewhat similar stuff I wanted to do in #32283

- enables building with TSAN for the runtime library as well as Julia code
- updates the handling of `SANITIZE=1` in Make.inc
- moves sanitizer to late in the pipeline, copies what Clang does
- cleans up `options.h`, and `julia_internal.h` w.r.t sanitizers
- update devdocs for sanitizer
- adds a patch for TSAN to deal with Julia's usage of address spaces
- don't use COPY_STACKS with TSAN
- don't use DEEPBIND by default if a sanitizer is enabled
@Keno Keno merged commit d862442 into master Aug 5, 2020
@Keno Keno deleted the vc/tsan branch August 5, 2020 00:03
simeonschaub pushed a commit to simeonschaub/julia that referenced this pull request Aug 11, 2020
- enables building with TSAN for the runtime library as well as Julia code
- updates the handling of `SANITIZE=1` in Make.inc
- moves sanitizer to late in the pipeline, copies what Clang does
- cleans up `options.h`, and `julia_internal.h` w.r.t sanitizers
- update devdocs for sanitizer
- adds a patch for TSAN to deal with Julia's usage of address spaces
- don't use COPY_STACKS with TSAN
- don't use DEEPBIND by default if a sanitizer is enabled
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
multithreading Base.Threads and related functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants