Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 29 Apr 2015 16:31:45 -0700
From:      Garrett Cooper <yaneurabeya@gmail.com>
To:        FreeBSD Toolchain <freebsd-toolchain@freebsd.org>
Cc:        Anthony Cornehl <accornehl@gmail.com>, Benno Rice <benno@FreeBSD.org>
Subject:   A better way to get runtime coverage with libprofile_rt (from compiler_rt) / gcov?
Message-ID:  <1DCB7CE4-2AC1-4AC6-B630-8A55BAF546BB@gmail.com>

index | next in thread | raw e-mail

[-- Attachment #1 --]
Hi all,
	In order to adapt an existing process to clang, I went and tried to figure out how to get coverage generation to work on FreeBSD with shared binaries (not static binaries), which is the default for clang/gcc: https://github.com/yaneurabeya/scratch/blob/master/coverage-with-shared-libs-freebsd . In doing this I had to commit a few cardinal sins:
	1. I had to specify -lgcov, even though the gcc docs said --coverage implied this.
	2. I had to link in static libraries directly using LDADD: https://github.com/yaneurabeya/scratch/blob/master/coverage-with-shared-libs-freebsd/Makefile.inc#L9 . If I didn’t, things would blow when it tried to link lib/libfoo.so into bin/foo , so there might be a difference in behavior between clang and gcc in that regard (I tried using LDFLAGS + LDADD with just -lclang_rt.profile-x86_64, but that didn’t seem to work either):

/usr/bin/ld: foo: hidden symbol `llvm_gcda_emit_arcs' in /usr/bin/../lib/clang/3.6.0/lib/freebsd/libclang_rt.profile-x86_64.a(GCDAProfiling.o) is referenced by DSO
/usr/bin/ld: final link failed: Nonrepresentable section on output

	Does anyone know of a better way to solve this problem, i.e. avoid having to hardcode the full path to libclang_rt.profile-x86_64.a (or perhaps make clang do the right thing when trying to link in the library)?
Thanks!
-NGie

$ make -s obj depend all
===> lib (obj)
===> bin (obj)
===> lib (depend)
===> bin (depend)
===> lib (all)
===> bin (all)
$ make get-coverage
LD_LIBRARY_PATH=/usr/obj/usr/src.svn/tests/foo/lib /usr/obj/usr/src.svn/tests/foo/bin/foo
This is foo
lcov --capture --directory /usr/obj/usr/src.svn/tests/foo --output-file /usr/obj/usr/src.svn/tests/foo/coverage.info
Capturing coverage data from /usr/obj/usr/src.svn/tests/foo
Found gcov version: 4.2.1
Scanning /usr/obj/usr/src.svn/tests/foo for .gcda files ...
Found 2 data files in /usr/obj/usr/src.svn/tests/foo
Processing lib/foo.gcda
/usr/obj/usr/src.svn/tests/foo/lib/foo.gcno:version '402*', prefer '402p'
/usr/obj/usr/src.svn/tests/foo/lib/foo.gcda:version '402*', prefer version '402p'
/usr/obj/usr/src.svn/tests/foo/lib/foo.gcno:'foo' has arcs from exit block
Processing bin/foo.gcda
/usr/obj/usr/src.svn/tests/foo/bin/foo.gcno:version '402*', prefer '402p'
/usr/obj/usr/src.svn/tests/foo/bin/foo.gcda:version '402*', prefer version '402p'
Finished .info-file creation
genhtml /usr/obj/usr/src.svn/tests/foo/coverage.info --output-directory output
Reading data file /usr/obj/usr/src.svn/tests/foo/coverage.info
Found 2 entries.
Found common filename prefix "/usr/src.svn/tests/foo"
Writing .css and .png files.
Generating output.
Processing file bin/foo.c
Processing file lib/foo.c
Writing directory view page.
Overall coverage rate:
  lines......: 100.0% (4 of 4 lines)
  functions..: 100.0% (2 of 2 functions)


[-- Attachment #2 --]
-----BEGIN PGP SIGNATURE-----
Comment: GPGTools - https://gpgtools.org

iQEcBAEBCgAGBQJVQWnhAAoJEMZr5QU6S73eyooH/REUPj4X5HNiEO72U7GmJrr+
hkSEKUT9oLYhtSNIaChKESr+a0Yb48j2XGgDHPEMD6hKxsKz4HXVSXiWgBUVVsRK
J/71kvGwamyoUv+jCgMwVZ+5su0si/n+DCfA/RjowRf0yRLSiJGavPUFhnJG2ZAF
pqsoxr2MuMn7apxnHAVGkxGV3Hke94UD4OkFaaG9ijnaVsHffuVT+P1vGVb2lDGz
HpeMtLLwyQGl0T9MXKRQgRx+QLhrI/dGwuJIDRII9ZzOiNkn6vfJm4yEq0e7fJ/e
y/DApeaJOblJgLAijVWZ7KdrSeVyoiANuvTa9kMBTdpsPHeZsW3wQ6ebEJ885no=
=+lQL
-----END PGP SIGNATURE-----
home | help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1DCB7CE4-2AC1-4AC6-B630-8A55BAF546BB>