[PATCH] D39254: On FreeBSD, add -pthread to the flags for dynamic ASan tests

Dimitry Andric via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 24 13:43:33 PDT 2017


dim added a comment.

In https://reviews.llvm.org/D39254#905625, @eugenis wrote:

> Does asan runtime library have libthr.so in DT_NEEDED? Would adding that help?


Yes it has, but that doesn't help.  It looks like the AsanTSDInit() function is called before the pthread_key_create() stub which returns ENOSYS is replace by the 'real' function from libthr.so.

> If FreeBSD requires that everything built with ASan uses -pthread, then perhaps it is best done in the driver.

Well, not everything, I only encountered this problem when using the dynamic ASan library.  Though it seems that some of the static ASan test cases are linked with `-pthread` already, for example:

  /home/dim/obj/llvm-316264-trunk-freebsd12-i386-ninja-rel-1/./bin/clang --driver-mode=g++ -fsanitize=address -mno-omit-leaf-frame-pointer -fno-omit-frame-pointer -fno-optimize-sibling-calls -gline-tables-only -m32  -O0 /share/dim/src/llvm/trunk/runtimes/compiler-rt/test/asan/TestCases/Posix/stack-use-after-return.cc -pthread -o /home/dim/obj/llvm-316264-trunk-freebsd12-i386-ninja-rel-1/runtimes/runtimes-bins/compiler-rt/test/asan/I386FreeBSDConfig/TestCases/Posix/Output/stack-use-after-return.cc.tmp && env ASAN_OPTIONS=detect_stack_use_after_return=1 not  /home/dim/obj/llvm-316264-trunk-freebsd12-i386-ninja-rel-1/runtimes/runtimes-bins/compiler-rt/test/asan/I386FreeBSDConfig/TestCases/Posix/Output/stack-use-after-return.cc.tmp 2>&1 | FileCheck /share/dim/src/llvm/trunk/runtimes/compiler-rt/test/asan/TestCases/Posix/stack-use-after-return.cc

but this does not apply to all of them, for reasons that are unclear to me.

In https://reviews.llvm.org/D39254#905639, @krytarowski wrote:

> What exactly breaks?


All dynamic ASan tests fail with:

  ==7913==AddressSanitizer CHECK failed: /share/dim/src/llvm/trunk/runtimes/compiler-rt/lib/asan/asan_posix.cc:49 "((0)) == ((pthread_key_create(&tsd_key, destructor)))" (0x0, 0x4e)

This is because `AsanTSDInit()` calls `pthread_key_create()` while libthr.so is not loaded, and that causes `pthread_key_create()` to always return ENOSYS.

> What symbols are missing?

No symbols are missing, as far as I can see.

> Now are you testing it?

I run `ninja check-all`.

> `check-asan-dynamic` on NetBSD/amd64 works fine. Modulo around 3 tests that are unresearched.

I guess NetBSD doesn't use libthr.so?  Are all pthread functions folded into libc.so?


https://reviews.llvm.org/D39254





More information about the llvm-commits mailing list