staticanalysis / data-race-test

Automatically exported from code.google.com/p/data-race-test
0 stars 0 forks source link

tsanv2: instrumentation of int x = 0; #98

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
The following function should not contain any mops:

void writez(int fd) {
    2820:       push   %r14
    2822:       push   %rbx
    2823:       push   %rax
    2824:       mov    %edi,%ebx
    2826:       mov    0x18(%rsp),%rdi
    282b:       callq  a2b0 <__tsan_func_entry>
    2830:       lea    0x4(%rsp),%r14
  int x = 0;
    2835:       mov    %r14,%rdi
    2838:       callq  85d0 <__tsan_write4>
    283d:       movl   $0x0,0x4(%rsp)
  write(fd, &x, 4);
    2845:       mov    %ebx,%edi
    2847:       mov    %r14,%rsi
    284a:       mov    $0x4,%edx
    284f:       callq  11210 <write>
}
    2854:       callq  a3a0 <__tsan_func_exit>
    2859:       add    $0x8,%rsp
    285d:       pop    %rbx
    285e:       pop    %r14
    2860:       retq   

Original issue reported on code.google.com by dvyu...@google.com on 7 Apr 2012 at 12:52

GoogleCodeExporter commented 9 years ago
can we do it w/o a specific knowledge about the function "write"? 

Original comment by konstant...@gmail.com on 11 Apr 2012 at 1:00

GoogleCodeExporter commented 9 years ago
> can we do it w/o a specific knowledge about the function "write"? 

Yes, we can. I just meant initialization of addressable variables (the write is 
solely to make it addressable).
Even if a var is addressable, initialization can't race, because it's address 
it not yet taken.
Actually some other subsequent accesses may not be instrumented as well. For 
example:
int x = 0; // store, can't race
...
x++; // store, can't yet race
...
write(..., &x); // only here it actually becomes "addressable"
...
x++; // store, this one can race
However, it will require more complex flow analysis, and it's not clear what 
gain it will provide (if any). So that second part is 
optional/low-prio/abandoned. However, the first part (int x = 0) must be easy 
to do and can provide visible gain.

Original comment by dvyu...@google.com on 11 Apr 2012 at 7:17