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

Copy LLVM's ThreadSanitizer (TSan) library to LDC's libraries like we do for ASan, and set the correct linker flags #3522

Merged
merged 4 commits into from
Aug 3, 2020

Conversation

JohanEngelen
Copy link
Member

TSan is not supported on Windows.

See #3519

Execution is still failing for me on macOS, let's see how our CI systems fare. With LLVM 8 I get:

❯ lldb /Users/johan/ldc/johan/build80/tests/sanitizers/Output/fsanitize_thread.d.tmp
(lldb) target create "/Users/johan/ldc/johan/build80/tests/sanitizers/Output/fsanitize_thread.d.tmp"
Current executable set to '/Users/johan/ldc/johan/build80/tests/sanitizers/Output/fsanitize_thread.d.tmp' (x86_64).
(lldb) r
Process 10307 launched: '/Users/johan/ldc/johan/build80/tests/sanitizers/Output/fsanitize_thread.d.tmp' (x86_64)
FATAL: ThreadSanitizer CHECK failed: /Users/johan/llvm/llvm/compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cc:311 "((tid)) < ((kMaxTid))" (0xffffffffffffffff, 0x1fc0)
    #0 __tsan::TsanCheckFailed(char const*, int, char const*, unsigned long long, unsigned long long) <null> (libldc_rt.tsan.dylib:x86_64h+0x62ac9)

Process 10307 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
    frame #0: 0x00007fff72962b66 libsystem_kernel.dylib`__pthread_kill + 10
libsystem_kernel.dylib`__pthread_kill:
->  0x7fff72962b66 <+10>: jae    0x7fff72962b70            ; <+20>
    0x7fff72962b68 <+12>: movq   %rax, %rdi
    0x7fff72962b6b <+15>: jmp    0x7fff72959ae5            ; cerror_nocancel
    0x7fff72962b70 <+20>: retq   
Target 0: (fsanitize_thread.d.tmp) stopped.
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
  * frame #0: 0x00007fff72962b66 libsystem_kernel.dylib`__pthread_kill + 10
    frame #1: 0x00007fff72b2d080 libsystem_pthread.dylib`pthread_kill + 333
    frame #2: 0x000000010060cd3e libldc_rt.tsan.dylib`wrap_pthread_kill + 94
    frame #3: 0x00007fff728be1ae libsystem_c.dylib`abort + 127
    frame #4: 0x00000001005f3526 libldc_rt.tsan.dylib`__sanitizer::Abort() + 70
    frame #5: 0x00000001005f2ec4 libldc_rt.tsan.dylib`__sanitizer::Die() + 196
    frame #6: 0x0000000100640b86 libldc_rt.tsan.dylib`__tsan::TsanCheckFailed(char const*, int, char const*, unsigned long long, unsigned long long) + 278
    frame #7: 0x00000001005f2f38 libldc_rt.tsan.dylib`__sanitizer::CheckFailed(char const*, int, char const*, unsigned long long, unsigned long long) + 88
    frame #8: 0x0000000100644c1b libldc_rt.tsan.dylib`__tsan::ThreadDetach(__tsan::ThreadState*, unsigned long, int) + 107
    frame #9: 0x0000000100609abe libldc_rt.tsan.dylib`wrap_pthread_detach + 254
    frame #10: 0x0000000100153ce0 fsanitize_thread.d.tmp`thread_term + 80
    frame #11: 0x000000010016fcbb fsanitize_thread.d.tmp`rt_term + 59
    frame #12: 0x00000001001701c8 fsanitize_thread.d.tmp`_D2rt6dmain212_d_run_main2UAAamPUQgZiZ6runAllMFZv + 120
    frame #13: 0x000000010016ffbb fsanitize_thread.d.tmp`_d_run_main2 + 395
    frame #14: 0x000000010016fe1d fsanitize_thread.d.tmp`_d_run_main + 141
    frame #15: 0x0000000100000dec fsanitize_thread.d.tmp`main + 60
    frame #16: 0x00007fff72812015 libdyld.dylib`start + 1

Somehow the threadID is invalid in the call path of the pthread_detach hook of TSan (called in druntime's thread_term as the main program/thread is being closed)

… do for ASan, and set the correct linker flags.

TSan is not supported on Windows.
@JohanEngelen
Copy link
Member Author

TSan now works with betterC, completely avoiding druntime: see the tests added.
Somehow druntime does not support TSan yet. I'm confused why druntime is detaching the main thread at all, maybe simply disabling that will make things work, but that's for another time.

@JohanEngelen
Copy link
Member Author

Apparently something is off with LLVM before version 8 (it could be just the way of testing), but let's not spend the time to figure out what that is.

@JohanEngelen
Copy link
Member Author

(this PR is ready btw, all other TSan stuff will be in different PRs)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant