This is an archive of the discontinued LLVM Phabricator instance.

[GCOV] Flush counters before to avoid counting the execution before fork twice and for exec** functions we must flush before the call
ClosedPublic

Authored by calixte on Oct 23 2018, 11:20 AM.

Details

Summary

This is replacement for patch in https://reviews.llvm.org/D49460.
When we fork, the counters are duplicate as they're and so the values are finally wrong when writing gcda for parent and child.
So just before to fork, we flush the counters and so the parent and the child have new counters set to zero.
For exec** functions, we need to flush before the call to have some data.

Diff Detail

Event Timeline

calixte created this revision.Oct 23 2018, 11:20 AM
vsk added a comment.Oct 26 2018, 2:39 PM

Don't you just want to reset the counters in the child process?

lib/Transforms/Instrumentation/GCOVProfiling.cpp
535

See InstIterator.h. The instructions() range helper might be more convenient.

541

Take a look at TargetLibraryInfo.{h, def}. It might be cleaner to define fork() there, then check if you see a LibFunc_fork.

556

Why is this needed?

calixte added inline comments.Oct 30 2018, 10:16 AM
lib/Transforms/Instrumentation/GCOVProfiling.cpp
556

The line after the fork is executed 2 times: 1 time with the parent and 1 time with the child. So if we don't split the block the counter for this line (and the next ones in the same block as the fork) is only 1. So in putting a new block here and so a new counter in it we can reflect that the lines after the fork are executed two times.

calixte updated this revision to Diff 172800.Nov 6 2018, 11:16 AM

Fix comments from vsk and handle exec** functions too.

calixte retitled this revision from [GCOV] Flush counters before forking to avoid counting the execution before fork twice to [GCOV] Flush counters before to avoid counting the execution before fork twice and for exec** functions we must flush before the call.Nov 6 2018, 11:18 AM
calixte edited the summary of this revision. (Show Details)
marco-c added inline comments.Nov 7 2018, 1:37 AM
include/llvm/Analysis/TargetLibraryInfo.def
588

There's also execve.

lib/Transforms/Instrumentation/GCOVProfiling.cpp
473

We should do the flushing before fork/exec when we are cross-compiling from Windows to a target that supports fork/exec.
We have two options:

  1. Instead of using _WIN32, check that the target of the compilation isn't Windows;
  2. Just add the flush always, as it's effect is not important if we are on Windows and the function is defined by a user.
calixte updated this revision to Diff 172928.Nov 7 2018, 5:27 AM

Handle execve, fix issues with execvp and remove _WIN32.

marco-c accepted this revision.Nov 7 2018, 5:33 AM
This revision is now accepted and ready to land.Nov 7 2018, 5:33 AM
This revision was automatically updated to reflect the committed changes.