[cfe-dev] Code coverage on clang

Nick Lewycky nlewycky at google.com
Tue Jul 9 00:23:25 PDT 2013


On 9 July 2013 00:10, Magnus Reftel <magnus.reftel at gmail.com> wrote:

> 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).
>

gcov doesn't have a single fixed format. If you're using the gcov from
gcc-4.7 then yes you use those flags mentioned. The default that clang
emits should be gcc-4.2 compatible, which is supposed to work with llvm-cov
or with a gcov binary from gcc 4.2

Nick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130709/e5851513/attachment.html>


More information about the cfe-dev mailing list