<div dir="ltr">Hello, <div><br></div><div>I have few questions about coverage.</div><div><br></div><div>Is there any user-facing documentation for clang's "-coverage" flag?</div><div>The coverage instrumentation seems to happen before asan, and so if asan is also enabled <br>
</div><div>asan will instrument accesses to @__llvm_gcov_ctr.</div><div>This is undesirable and so we'd like to skip these accesses. </div><div>Looks like GEP around @__llvm_gcov_ctr have special metadata attached: </div>
<div><div> %2 = getelementptr inbounds [4 x i64]* @__llvm_gcov_ctr, i64 0, i64 %1<br></div><div> %3 = load i64* %2, align 8</div><div> %4 = add i64 %3, 1</div><div> store i64 %4, i64* %2, align 8</div></div><div> ...</div>
<div>!1 = metadata !{...; [ DW_TAG_compile_unit ] ... /home/kcc/tmp/cond.cc] [DW_LANG_C_plus_plus]<br></div><div><br></div><div><div>Can we rely on having this metadata attached to @__llvm_gcov_ctr? <br></div></div><div>Should we attach some metadata to the actual accesses as well, or simply find the corresponding GEP?</div>
<div><br></div><div>Finally, does anyone have performance numbers for coverage?</div><div>As of today it seems completely thread-hostile since __llvm_gcov_ctr is not thread-local.</div><div>A simple stress test shows that coverage slows down by 50x! </div>
<div><div>% cat ~/tmp/coverage_mt.cc </div><div>#include <pthread.h></div><div>__thread int x;</div><div>__attribute__((noinline))</div><div>void foo() {</div><div> x++;</div><div>}</div><div><br></div><div>void *Thread(void *) {</div>
<div> for (int i = 0; i < 100000000; i++)</div><div> foo();</div><div> return 0;</div><div>}</div><div><br></div><div>int main() {</div><div> static const int kNumThreads = 16;</div><div> pthread_t t[kNumThreads];</div>
<div> for (int i = 0; i < kNumThreads; i++)</div><div> pthread_create(&t[i], 0, Thread, 0);</div><div> for (int i = 0; i < kNumThreads; i++)</div><div> pthread_join(t[i], 0);</div><div> return 0;</div><div>
}</div></div><div><br></div><div><div>% clang -O2 ~/tmp/coverage_mt.cc -lpthread ; time ./a.out </div><div>TIME: real: 0.284; user: 3.560; system: 0.000</div><div>% clang -O2 ~/tmp/coverage_mt.cc -lpthread -coverage ; time ./a.out </div>
<div>TIME: real: 13.327; user: 174.510; system: 0.000</div></div><div><br></div><div>Any principal objections against making __llvm_gcov_ctr thread-local, perhaps under a flag?</div><div><br></div><div>If anyone is curious, my intent is to enable running coverage and asan in one process.</div>
<div><br></div><div>Thanks, <br></div><div>--kcc</div></div>