Skip to content

[FR] Missing TSAN runtime support? #1041

Open

Description

@equeim

Description

Add -fsanitize=thread to compile and link flags, and get error: undefined reference to '__tsan_func_entry' (and other tsan functions) link errors.

Environment Details

  • NDK Version: 20.0.5594570
  • Build system: CMake
  • Host OS: Ubuntu 18.04
  • ABI: arm64-v8a
  • NDK API level: 21
  • Device API level: 28

Activity

  1. enh commented on Jul 12, 2019

    @enh
    Contributor

    i know @yabinc had this working (for the platform) at one point, but it may have bitrotted. @eugenis might also know something useful...

  2. eugenis commented on Jul 12, 2019

    @eugenis

    That's basically all I know. Upstream tests are disabled (and AFAIK have never been enabled), so it is likely broken at this point.

  3. stephenhines commented on Jul 12, 2019

    @stephenhines

    TSan was never released in the NDK, so this is more of a feature request. @yabinc did have it working in the platform, but there are other components that would be needed in the NDK to actually let app developers enable it.

  4. yabinc commented on Jul 12, 2019

    @yabinc
    Collaborator

    TSAN uses a TLS slot to store thread specific state. Bionic added that support in Android N as slot 8, but changed to slot 6 in Android Q. The tsan library still uses slot 8.
    So currently the platform tsan is broken. I think we need to add dynamic detection of android version in tsan library.

    To use tsan on android, we need a tsan shared library linked and available on device, as https://android-review.googlesource.com/c/platform/prebuilts/clang/host/linux-x86/+/516421/1/Android.bp#253. static linking libtsan might also be possible, I didn't remember why we chose to use shared library.

    llvm-symbolizer is also needed on device to report data race locations.

  5. equeim commented on Jul 12, 2019

    @equeim
    Author

    asan and ubsan have shared libraries in ndk, which can be bundled with apps. tsan for some reason has only static library.

  6. haolongzhangm commented on Jul 18, 2019

    @haolongzhangm

    aarch64-linux-android-clang++ -fsanitize=thread -O0 -fno-omit-frame-pointer -g -pie -fPIE -L/home/zhl/mycode/tmp_aosp_for_tsan/aosp/prebuilts/clang/host/./linux-x86/clang-r349610b/lib64/clang/8.0.9/lib/linux/ -lclang_rt.tsan-aarch64-android main.cc -o android_test_tsan

    tsan_interceptors.cc:1747: undefined reference to `fileno_unlocked'

    extern "C" int fileno_unlocked(void *stream); at tsan_interceptors.cc

    but fileno_unlocked defined in libc:
    int fileno_unlocked(FILE* __fp)

  7. haolongzhangm commented on Jul 18, 2019

    @haolongzhangm

    issue same libclang_rt.tsan-aarch64-android.a link a different version of libc with NDK default libc.so?

    int fileno_unlocked(FILE* __fp)
    int fileno_unlocked(void *stream)

    different args ?

    any idea about this? rebuild NDK?

  8. DanAlbert commented on Jul 18, 2019

    @DanAlbert
    Contributor

    Rebuilding will just rebuild the bug. TSan needs to be fixed to work for Android. This isn't currently supported.

  9. added this to the external dependency milestone on Jul 18, 2019
  10. changed the title [-][BUG] Missing TSAN runtime support?[/-] [+][FR] Missing TSAN runtime support?[/+] on Jul 18, 2019
  11. 23 remaining items

  12. enh-google commented on Jul 18, 2022

    @enh-google
    Collaborator

    release notes didn't mention TSan support, so I guess it's not fixed yet and we have to wait more?

    yeah, not finished yet but still working on it. (and you're right: it'll be in the release notes when we think it's finished :-) )

  13. shixpGit commented on Jul 6, 2023

    @shixpGit

    I saw that r25 has TSan runtime libs, so jumped on it to test it. Unfortunately it crashed immediately:

    07-17    19:48:16.955    p:23002    t:23002    F    DEBUG                                         signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0
    07-17    19:48:16.955    p:23002    t:23002    F    DEBUG                                         Cause: null pointer dereference
    07-17    19:48:16.955    p:23002    t:23002    F    DEBUG                                             x0  000000763532354a  x1  00000076415791c8  x2  0000000000000003  x3  000000763535347c
    07-17    19:48:16.955    p:23002    t:23002    F    DEBUG                                             x4  ffffffffffffffff  x5  0000000000000000  x6  6f632f786570612f  x7  696f72646e612e6d
    07-17    19:48:16.955    p:23002    t:23002    F    DEBUG                                             x8  0000000000000000  x9  0000000000000000  x10 0000000000000000  x11 0000007641579128
    07-17    19:48:16.955    p:23002    t:23002    F    DEBUG                                             x12 000000006474e550  x13 0000000000000000  x14 0000000000000000  x15 0000000000000000
    07-17    19:48:16.955    p:23002    t:23002    F    DEBUG                                             x16 00000076353c7060  x17 000000762712e9f0  x18 00000076414c4000  x19 00000076415791c8
    07-17    19:48:16.955    p:23002    t:23002    F    DEBUG                                             x20 000000763532354a  x21 000000763535347c  x22 0000007641576000  x23 0000007635327bc7
    07-17    19:48:16.955    p:23002    t:23002    F    DEBUG                                             x24 0000000000000005  x25 0000007641579000  x26 00000076415791c8  x27 0000000000000000
    07-17    19:48:16.955    p:23002    t:23002    F    DEBUG                                             x28 0000007641579158  x29 0000007fc18ec460
    07-17    19:48:16.955    p:23002    t:23002    F    DEBUG                                             lr  000000762712ea6c  sp  0000007fc18ec3f0  pc  0000000000000000  pst 0000000080001000
    07-17    19:48:16.955    p:23002    t:23002    F    DEBUG                                         backtrace:
    07-17    19:48:16.955    p:23002    t:23002    F    DEBUG                                               #00 pc 0000000000000000  <unknown>
    07-17    19:48:16.955    p:23002    t:23002    F    DEBUG                                               #01 pc 0000000000072a68  /data/app/~~9wJuvaNwR8JAYPuNLH2VbA==/com.epicgames.TP_FirstPerson-5Fsz6ZLUofv8g-3Q2C6p5A==/lib/arm64/libclang_rt.tsan-aarch64-android.so (strcmp+120) (BuildId: a563b2c927a34c480d7b6ba00060d50f3272c83a)
    07-17    19:48:16.955    p:23002    t:23002    F    DEBUG                                               #02 pc 000000000004b478  /apex/com.android.runtime/lib64/bionic/libc.so (__libc_init_vdso(libc_globals*)+424) (BuildId: 53a228529316d67f22e241dd17ea9b9e)
    07-17    19:48:16.955    p:23002    t:23002    F    DEBUG                                               #03 pc 0000000000059330  /apex/com.android.runtime/lib64/bionic/libc.so (__libc_init_globals()+100) (BuildId: 53a228529316d67f22e241dd17ea9b9e)
    07-17    19:48:16.955    p:23002    t:23002    F    DEBUG                                               #04 pc 00000000000483d4  /apex/com.android.runtime/lib64/bionic/libc.so (__libc_preinit_impl()+40) (BuildId: 53a228529316d67f22e241dd17ea9b9e)
    07-17    19:48:16.955    p:23002    t:23002    F    DEBUG                                               #05 pc 00000000000b5cd8  /apex/com.android.runtime/bin/linker64 (__dl__ZL13call_functionPKcPFviPPcS2_ES0_+136) (BuildId: b542a635b31e7c4fe0ac851ba377d3e6)
    07-17    19:48:16.955    p:23002    t:23002    F    DEBUG                                               #06 pc 00000000000b5bf0  /apex/com.android.runtime/bin/linker64 (__dl__ZL10call_arrayIPFviPPcS1_EEvPKcPT_mbS5_+168) (BuildId: b542a635b31e7c4fe0ac851ba377d3e6)
    07-17    19:48:16.955    p:23002    t:23002    F    DEBUG                                               #07 pc 00000000000a108c  /apex/com.android.runtime/bin/linker64 (__dl__ZN6soinfo17call_constructorsEv+368) (BuildId: b542a635b31e7c4fe0ac851ba377d3e6)
    07-17    19:48:16.955    p:23002    t:23002    F    DEBUG                                               #08 pc 00000000000a0fac  /apex/com.android.runtime/bin/linker64 (__dl__ZN6soinfo17call_constructorsEv+144) (BuildId: b542a635b31e7c4fe0ac851ba377d3e6)
    07-17    19:48:16.955    p:23002    t:23002    F    DEBUG                                               #09 pc 00000000000a0fac  /apex/com.android.runtime/bin/linker64 (__dl__ZN6soinfo17call_constructorsEv+144) (BuildId: b542a635b31e7c4fe0ac851ba377d3e6)
    07-17    19:48:16.955    p:23002    t:23002    F    DEBUG                                               #10 pc 00000000000b8e7c  /apex/com.android.runtime/bin/linker64 (__dl__ZL29__linker_init_post_relocationR19KernelArgumentBlockR6soinfo+4176) (BuildId: b542a635b31e7c4fe0ac851ba377d3e6)
    07-17    19:48:16.955    p:23002    t:23002    F    DEBUG                                               #11 pc 00000000000b7ddc  /apex/com.android.runtime/bin/linker64 (__dl___linker_init+500) (BuildId: b542a635b31e7c4fe0ac851ba377d3e6)
    07-17    19:48:16.955    p:23002    t:23002    F    DEBUG                                               #12 pc 0000000000039074  /apex/com.android.runtime/bin/linker64 (__dl__start+4) (BuildId: b542a635b31e7c4fe0ac851ba377d3e6)
    

    release notes didn't mention TSan support, so I guess it's not fixed yet and we have to wait more?

    same result with testing on NDK25b, @enh-google Hi~ is there some latest news about this issue? :)

  14. enh-google commented on Jul 6, 2023

    @enh-google
    Collaborator

    no, no news. it's still on the to-do list, but relatively low priority because pretty much everyone actually wants this for their apps (a problem we don't know how to solve, because of the ART side of things) rather than for their stand-alone unit test binaries (a problem we probably could solve).

  15. DanAlbert commented on Jul 11, 2023

    @DanAlbert
    Contributor

    (it was higher priority when we thought we could at least enable unit tests relatively cheaply, but we've hit a phase that requires some pretty significant investigation and potentially a rework of how sanitizer internals work on android that that's no longer the case)

  16. bibop4 commented on Aug 29, 2024

    @bibop4

    @DanAlbert Thank you for all your hard work. I noticed the presence of libclang_rt.tsan-aarch64-android.so in NDK r26, and naturally assumed that TSan was supported. With this in mind, I proceeded with a multi-threaded project using the NDK, thinking that any data race issues in multi-threading could be easily resolved with TSan later on. Now that the time has come to address these issues, I find myself needing to use TSan. Is there any alternative method available? Also, could you provide any information on when TSan might be supported?

  17. DanAlbert commented on Aug 29, 2024

    @DanAlbert
    Contributor

    Nothing's changed since our last update.

  18. Space-desing commented on Oct 19, 2024

    @Space-desing
  19. airpfei commented on Jun 13, 2025

    @airpfei

    I’m going to support TSan on Android. Is there a guide on how I can contribute to the project?

  20. enh-google commented on Jun 13, 2025

    @enh-google
    Collaborator

    I’m going to support TSan on Android. Is there a guide on how I can contribute to the project?

    depends on where you need to make changes. changes to the tsan implementation itself would go in upstream llvm. changes to Android would go to AOSP.

  21. airpfei commented on Oct 13, 2025

    @airpfei
  22. DanAlbert commented on Oct 13, 2025

    @DanAlbert
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions