[gcov] Fix .gcda decoding and support GCC 8, 9 and 10
authorFangrui Song <maskray@google.com>
Sat, 9 May 2020 17:36:34 +0000 (10:36 -0700)
committerFangrui Song <maskray@google.com>
Sun, 10 May 2020 16:55:23 +0000 (09:55 -0700)
commit2d00eb17cac40d96f357490d005c4601271bbba3
tree53595718027ada06df1c78eb279abbf3dc1cba82
parent8528186b9bfcb0e422a1046871f855edcf3389f6
[gcov] Fix .gcda decoding and support GCC 8, 9 and 10

GCDAProfiling.c unnecessarily writes function names to .gcda files.
GCC 4.2 gcc/libgcov.c (now renamed to libgcc/libgcov*) did not write function
names. gcov-7 (compatible) crashes on .gcda produced by libclang_rt.profile
rL176173 realized the problem and introduced a mode to remove function
names.

llvm-cov code apparently takes GCDAProfiling.c output format as truth
and tries to decode function names.  Additionally, llvm-cov tries to
decode tags in certain order which does not match libgcov emitted .gcda
files.

This patch fixes the .gcda decoder and makes it work with GCC 8 and 9
(10 is compatible with 9). Note, line statistics are broken and not
fixed by this patch.

Add test/tools/llvm-cov/gcov-{4.7,8,9}.c to test compatibility.
17 files changed:
llvm/include/llvm/ProfileData/GCOV.h
llvm/lib/ProfileData/GCOV.cpp
llvm/lib/ProfileData/SampleProfReader.cpp
llvm/test/tools/llvm-cov/Inputs/gcov-4.7.gcda [new file with mode: 0644]
llvm/test/tools/llvm-cov/Inputs/gcov-4.7.gcno [new file with mode: 0644]
llvm/test/tools/llvm-cov/Inputs/gcov-8.gcda [new file with mode: 0644]
llvm/test/tools/llvm-cov/Inputs/gcov-8.gcno [new file with mode: 0644]
llvm/test/tools/llvm-cov/Inputs/gcov-9.gcda [new file with mode: 0644]
llvm/test/tools/llvm-cov/Inputs/gcov-9.gcno [new file with mode: 0644]
llvm/test/tools/llvm-cov/Inputs/gcov47_compatibility.gcda [deleted file]
llvm/test/tools/llvm-cov/Inputs/gcov47_compatibility.gcno [deleted file]
llvm/test/tools/llvm-cov/gcov-4.7.c [new file with mode: 0644]
llvm/test/tools/llvm-cov/gcov-8.c [new file with mode: 0644]
llvm/test/tools/llvm-cov/gcov-9.c [new file with mode: 0644]
llvm/test/tools/llvm-cov/gcov47_compatibility.cpp [deleted file]
llvm/test/tools/llvm-cov/llvm-cov.test
llvm/tools/llvm-cov/gcov.cpp