[cfe-dev] Code coverage on clang

Magnus Reftel magnus.reftel at gmail.com
Tue Jul 9 00:10:12 PDT 2013


On 8 July 2013 22:44, Nick Lewycky <nlewycky at google.com> wrote:
> On 8 July 2013 00:24, mbm_kalpesh <mbm_kalpesh at yahoo.co.in> wrote:
>>
>> Hi,
>> I know how to use GCOV and LCOV to get code coverage on GCC.
>> But This time i need to use clang and get instrumented binaries and code
>> coverage.
>>
>> Please help (not able to find much info yet). Tried using -fprofile-arcs
>> and
>> -ftest-coverage. code is compiling fine but giving link errors.
>
>
> The profiling library in gcc is called "libgcov", but clang has its own
> named "libprofile_rt" and you need to link against that. The --coverage flag
> implies -lprofile_rt when linking, or you can pass -lprofile_rt yourself.
>
> The code for libprofile_rt is part of compiler-rt:
> http://llvm.org/svn/llvm-project/compiler-rt/trunk/lib/profile/ . If you
> don't have libprofile_rt, you'll need to build it.

Note that the default coverage information format is for llvm-cov. If
you want to use gcov for some reason, you'll need to specify the
options "-Xclang -coverage-cfg-checksum -Xclang
-coverage-no-function-names-in-data -Xclang -coverage-version='407*'"
(see http://llvm.org/bugs/show_bug.cgi?id=16568).

Best Regards
Magnus Reftel



More information about the cfe-dev mailing list