This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
RE: [PING] [PATCH] Fix parameters of __tsan_vptr_update
- From: Bernd Edlinger <bernd dot edlinger at hotmail dot de>
- To: Konstantin Serebryany <konstantin dot s dot serebryany at gmail dot com>
- Cc: Mike Stump <mikestump at comcast dot net>, Dmitry Vyukov <dvyukov at google dot com>, Kostya Serebryany <kcc at google dot com>, Jakub Jelinek <jakub at redhat dot com>, Richard Biener <richard dot guenther at gmail dot com>, "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>
- Date: Wed, 21 Jan 2015 09:23:46 +0100
- Subject: RE: [PING] [PATCH] Fix parameters of __tsan_vptr_update
- Authentication-results: sourceware.org; auth=none
- References: <DUB118-W36BD6269214D3EE6E26A4AE4510 at phx dot gbl> <20150102190102 dot GB1667 at tucnak dot redhat dot com>,<DUB118-W157955758BEE04CBCE299FE45D0 at phx dot gbl> <20150102212901 dot GG1667 at tucnak dot redhat dot com>,<DUB118-W23B6AF5E187BC7CE6646AEE45D0 at phx dot gbl> <DUB118-W23B4CFAA5A198B57689EBDE45B0 at phx dot gbl>,<DUB118-W16B4004988A5B0A3EE2CC2E4420 at phx dot gbl> <DUB118-W519443EF06A1C4DB96059EE44F0 at phx dot gbl>,<CACT4Y+YBJRzG9c4KSrykO5NbaGeAKfmJUTb7ryqk4dX_Hx5aNQ at mail dot gmail dot com>,<DUB118-W2875D28C15EDA755AEEC50E44F0 at phx dot gbl> <CACT4Y+a3j84+Pgp4zfuh2vRdDK3dy1WqA3oOMqhzWs+mQ5mqWg at mail dot gmail dot com>,<B45A3E4F-8313-45BE-946A-B0C159FF9120 at comcast dot net> <CAGQ9bdxAVfod2cQUz2YQLxH9F1ovVkaqXC1qSO5JPfA9jPvWGg at mail dot gmail dot com>,<DUB118-W32DE3E55FB0ADCB62D2790E44B0 at phx dot gbl>,<CAGQ9bdzUsV7zX7Xv2yLHQjxfVZk2bb9R64WaziOy0fNHuqt39Q at mail dot gmail dot com>
Hi,
On Tue, 20 Jan 2015 17:47:29, Konstantin Serebryany wrote:
>>
>> We discussed two alternatives to sleep:
>>
>> 1. step function, optionally with sched_yield to make it somewhat less busy waiting:
>> __attribute__((no_sanitize_thread))
>> void step (int i)
>> {
>> while (__atomic_load_n (&serial, __ATOMIC_ACQUIRE) != i - 1)
>> sched_yield();
>> __atomic_store_n (&serial, i, __ATOMIC_RELEASE);
>> }
>
> This will not work: tsan will still instrument atomics in a function
> with __attribute__((no_sanitize_thread))
> (This applies to both clang and gcc variants)
>
>> 2. tsan-invisible barriers:
>>
>> cat tsan_barrier.h
>> /* TSAN-invisible barriers. Link with -ldl. */
>> #include <pthread.h>
>> #include <dlfcn.h>
>>
>> static __typeof(pthread_barrier_wait) *barrier_wait;
>>
>> static
>> void barrier_init (pthread_barrier_t *barrier, unsigned count)
>> {
>> void *h = dlopen ("libpthread.so.0", RTLD_LAZY);
>> barrier_wait = (__typeof (pthread_barrier_wait) *)
>> dlsym (h, "pthread_barrier_wait");
>> pthread_barrier_init (barrier, NULL, count);
>> }
>
> So, we will have a single extra header file, but no extra .c files.
> This sounds tolerable.
> I am not sure how portable that is, but today's tsan works only on
> modern Linux anyway.
>
> If you want to contribute the code, please send a patch to upstream LLVM:
> we may not be able to take the code from gcc source tree to LLVM, the
> other direction is easy.
> Or please give us some time to fix the tests in upstream ourselves and
> than port them to the gcc test suite.
>
That's fine, LLVM is out of my reach so I can't do that myself, but I will
always help if I can.
> Dmitry, wdyt?
>
>
>>
>>
>> We preferred the second alternative, because it does not do busy waiting.
>> We include this header file in every positive test case and link with -ldl.
>
> -ldl is not required, since -fsanitize=thread already adds that.
>
Maybe that is a driver issue or just a linker oddity.
Clang will probably use a different linker.
In our case however, if I do not add -ldl to the application,
the linker complains about the missing DSO in the command line.
Also if I use -fsanititze=thread I do in most cases not need -pthread on the
command line, but if I happen to use a non-intercepted pthread function
for instance pthread_yield() I get an error:
cat test.c
#define _GNU_SOURCE
#include <pthread.h>
int main()
{
pthread_yield();
return 0;
}
gcc test.c -fsanitize=thread
/home/ed/gnu/install/lib/gcc/x86_64-unknown-linux-gnu/5.0.0/../../../../x86_64-unknown-linux-gnu/bin/ld: /tmp/ccGGRrgy.o: undefined reference to symbol 'pthread_yield@@GLIBC_2.2.5'
/lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
gcc test.c -fsanitize=thread -pthread
=> OK
Bernd.