Any advice on building a code coverage build with gcov?

297 views
Skip to first unread message

Clint Talbert

unread,
Jun 25, 2008, 11:28:24 PM6/25/08
to
I'm trying to build a code coverage instrumented build with gcov;
however, I'm not having much luck.

I'm using the mozilla central repo, on Ubuntu 8.04. My gcc version is:
4.2.3. My gcov version is also 4.2.3.

I've tried the following different settings in my mozconfig file, and I
note the output of each below them.

# Take 1
export CFLAGS="-fprofile-arcs -ftest-coverage"
export CXXFLAGS="-fprofile-arcs -ftest-coverage"
export LDFLAGS="-lgcov"
--> DSO errors on compiled tests (see the error below)


# Take 2
export CFLAGS="-fprofile-arcs -ftest-coverage -shared"
export CXXFLAGS="-fprofile-arcs -ftest-coverage -shared"
export OS_CFLAGS="-fprofile-arcs -ftest-coverage"
export LDFLAGS="-lgcov"
export XLDOPTS="-lgcov"
--> segfaults in binaries (see the error below)
--> note that this one did not hit any DSO errors. Also rebuilding the
specific DSO failures with the -shared option present caused those
builds to succeed, but I then hit the segfault issue once I tried to run
binaries generated that way.

# Take 3
export CFLAGS="-fprofile-arcs -ftest-coverage"
export CXXFLAGS="-fprofile-arcs -ftest-coverage"
export OS_CFLAGS="-fprofile-arcs -ftest-coverage"
export LDFLAGS="-lgcov"
export XLDOPTS="-lgcov"
# --> DSO errors on compiled tests (see the error below)

# Take 4 - bc's approach
export CFLAGS="--coverage"
export CXXFLAGS="--coverage"
export OS_CFLAGS="--coverage"
export LDFLAGS="--coverage"
export XLDOPTS="--coverage"
# --> DSO errors on compiled tests (see the error below)

== The Errors ==

Attempts 1, 3, and 4 all create the same error, it happens for every
compiled code test and it looks like this:

ar cr libxremote_client_s.a XRemoteClient.o
ranlib libxremote_client_s.a
/usr/bin/ld: mozilla-xremote-client: hidden symbol `__gcov_merge_add' in
/usr/lib/gcc/i486-linux-gnu/4.2.3/libgcov.a(_gcov_merge_add.o) is
referenced by DSO
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: ld returned 1 exit status
make[4]: *** [mozilla-xremote-client] Error 1
make[4]: Leaving directory
`/home/mozilla/mozcentral/dbg/widget/src/xremoteclient'
make[3]: *** [libs_tier_toolkit] Error 2
make[3]: Leaving directory `/home/mozilla/mozcentral/dbg'
make[2]: *** [tier_toolkit] Error 2
make[2]: Leaving directory `/home/mozilla/mozcentral/dbg'
make[1]: *** [default] Error 2
make[1]: Leaving directory `/home/mozilla/mozcentral/dbg'
make: *** [build] Error 2

Attempt 2 causes a segfault immediately when any built binary is executed:

gcc -DOSTYPE=\"Linux2.6\" -DOSARCH=Linux
-I/home/mozilla/mozcentral/config -I. -I../dist/include
-I../dist/include -I../dist/include/nspr -I../dist/sdk/include
-fPIC -Wall -W -Wno-unused -Wpointer-arith -Wcast-align -W
-Wno-long-long -pedantic -fprofile-arcs -ftest-coverage -shared
-fno-strict-aliasing -pthread -pipe -DDEBUG -D_DEBUG -DDEBUG_mozilla
-DTRACING -g -fno-inline -include ../mozilla-config.h -DMOZILLA_CLIENT
-I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -o elf-dynstr-gc
/home/mozilla/mozcentral/config/elf-dynstr-gc.c -lpthread -lgcov
-Wl,-rpath-link,../dist/bin -lgobject-2.0 -lglib-2.0
gcc -o nsinstall -fprofile-arcs -ftest-coverage -shared -DXP_UNIX
host_nsinstall.o host_pathsub.o
/home/mozilla/mozcentral/dbg/config/nsinstall -R -m 644
../mozilla-config.h /home/mozilla/mozcentral/config/nsStaticComponents.h
../dist/include
make[4]: *** [export] Segmentation fault
make[4]: Leaving directory `/home/mozilla/mozcentral/dbg/config'
make[3]: *** [export_tier_base] Error 2
make[3]: Leaving directory `/home/mozilla/mozcentral/dbg'
make[2]: *** [tier_base] Error 2
make[2]: Leaving directory `/home/mozilla/mozcentral/dbg'
make[1]: *** [default] Error 2
make[1]: Leaving directory `/home/mozilla/mozcentral/dbg'
make: *** [build] Error 2

I really appreciate any advice or direction you can give me on this.
I've also attempted this on Mac OS X 10.4 (gcc 4.0.1) and I got
something that looked a lot like the "DSO" error, though it had a
different wording it was still referring to the problem of being unable
to link with the shared libraries.

I've read that building with gcov in shared library is usually a
problem. Is there a way to build the core OS libaries in as statics?
Perhaps that would solve this.

Thanks for the help.

Clint

Peter Weilbacher

unread,
Jun 27, 2008, 2:40:11 AM6/27/08
to
On 26.06.2008 05:28, Clint Talbert wrote:
> I'm trying to build a code coverage instrumented build with gcov;
> however, I'm not having much luck.
>
> I'm using the mozilla central repo, on Ubuntu 8.04. My gcc version is:
> 4.2.3. My gcov version is also 4.2.3.
[...]

> I've read that building with gcov in shared library is usually a
> problem. Is there a way to build the core OS libaries in as statics?
> Perhaps that would solve this.

I have done the exact same exercise yesterday, although with GCC 3.3.5
on OS/2. There I had to use -static-libgcc in the LDFLAGS to be able to
link without errors.

Peter.

Clint Talbert

unread,
Jun 30, 2008, 5:08:33 PM6/30/08
to
Peter Weilbacher wrote:

> I have done the exact same exercise yesterday, although with GCC 3.3.5
> on OS/2. There I had to use -static-libgcc in the LDFLAGS to be able to
> link without errors.

Thanks Peter, let me give that a whirl on my Ubuntu box.

Clint

Clint Talbert

unread,
Jul 2, 2008, 7:31:02 PM7/2/08
to

I've tried this now with a couple of different attempts. The best
looking attempt (that got the furthest) has the mozconfig below. It
failed with this error:

c++ -o mozilla-xremote-client -fno-rtti -fno-exceptions -Wall
-Wconversion -Wpointer-arith -Woverloaded-virtual -Wsynth
-Wno-ctor-dtor-privacy -Wno-non-virtual-dtor -Wcast-align -Wno-long-long
-pedantic -fprofile-arcs -ftest-coverage -fno-strict-aliasing
-fshort-wchar -pthread -pipe -DDEBUG -D_DEBUG -DDEBUG_mozilla -DTRACING
-g -fno-inline mozilla-xremote-client.o XRemoteClient_standalone.o
-lpthread -lgcov -static-libgcc
-Wl,-rpath-link,../../../dist/bin -L../../../dist/bin
-L../../../dist/lib -L../../../dist/lib -lplds4 -lplc4 -lnspr4 -lpthread
-ldl -lX11 -ldl -lm


ranlib libxremote_client_s.a
/usr/bin/ld: mozilla-xremote-client: hidden symbol `__gcov_merge_add' in
/usr/lib/gcc/i486-linux-gnu/4.2.3/libgcov.a(_gcov_merge_add.o) is
referenced by DSO
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: ld returned 1 exit status
make[4]: *** [mozilla-xremote-client] Error 1
make[4]: Leaving directory

`/home/mozilla/mozcentral/mozcentral-dbg/widget/src/xremoteclient'


make[3]: *** [libs_tier_toolkit] Error 2

make[3]: Leaving directory `/home/mozilla/mozcentral/mozcentral-dbg'


make[2]: *** [tier_toolkit] Error 2

make[2]: Leaving directory `/home/mozilla/mozcentral/mozcentral-dbg'


make[1]: *** [default] Error 2

make[1]: Leaving directory `/home/mozilla/mozcentral/mozcentral-dbg'


make: *** [build] Error 2


Here is the mozconfig:

. $topsrcdir/browser/config/mozconfig

export CFLAGS="-fprofile-arcs -ftest-coverage"
export CXXFLAGS="-fprofile-arcs -ftest-coverage"

export LDFLAGS="-lgcov -static-libgcc"

mk_add_options MOZ_CO_PROJECT=browser
ac_add_options --enable-places
ac_add_options --enable-application=browser
ac_add_options --enable-airbag
mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/../mozcentral-dbg
mk_add_options
MOZ_CO_MODULE=mozilla/js/tests,mozilla/tools/tinderbox-configs

ac_add_options --disable-tests
ac_add_options --enable-mochitest

ac_add_options --enable-extensions=default,inspector,layout-debug
# ac_add_options --disable-javaxpcom

ac_add_options --enable-debug
ac_add_options --disable-static
ac_add_options --enable-shared
ac_add_options --disable-optimize
ac_add_options --disable-composer
ac_add_options --disable-mailnews
ac_add_options --disable-crashreporter
ac_add_options --disable-install
ac_add_options --enable-libxul

#ac_add_options --with-macos-sdk="/Developer/SDKs/MacOSX10.4u.sdk"

mk_add_options MOZ_MAKE_FLAGS="-j3"

mk_add_options AUTOCONF=autoconf2.13

Thanks for any help or other ideas folks have. I'm getting a VM set up
with Ubuntu 7.10 to try it there.

Clint

Benjamin Smedberg

unread,
Jul 4, 2008, 12:49:53 AM7/4/08
to
Clint Talbert wrote:

> c++ -o mozilla-xremote-client -fno-rtti -fno-exceptions -Wall
> -Wconversion -Wpointer-arith -Woverloaded-virtual -Wsynth
> -Wno-ctor-dtor-privacy -Wno-non-virtual-dtor -Wcast-align -Wno-long-long
> -pedantic -fprofile-arcs -ftest-coverage -fno-strict-aliasing
> -fshort-wchar -pthread -pipe -DDEBUG -D_DEBUG -DDEBUG_mozilla -DTRACING
> -g -fno-inline mozilla-xremote-client.o XRemoteClient_standalone.o
> -lpthread -lgcov -static-libgcc -Wl,-rpath-link,../../../dist/bin
> -L../../../dist/bin -L../../../dist/lib -L../../../dist/lib -lplds4
> -lplc4 -lnspr4 -lpthread -ldl -lX11 -ldl -lm
> ranlib libxremote_client_s.a
> /usr/bin/ld: mozilla-xremote-client: hidden symbol `__gcov_merge_add' in
> /usr/lib/gcc/i486-linux-gnu/4.2.3/libgcov.a(_gcov_merge_add.o) is
> referenced by DSO

This isn't very helpful, because it doesn't say *which* DSO is referencing
that symbol. Can you run `nm` on the various sharedlib (libnspr4.so?) to
find which one is referencing that symbol (and for kicks, figure out why
that sharedlib isn't being linked against -lgcov).

--BDS

Clint Talbert

unread,
Jul 10, 2008, 2:19:43 PM7/10/08
to
Benjamin Smedberg wrote:

> Clint Talbert wrote:
>
> This isn't very helpful, because it doesn't say *which* DSO is
> referencing that symbol. Can you run `nm` on the various sharedlib
> (libnspr4.so?) to find which one is referencing that symbol (and for
> kicks, figure out why that sharedlib isn't being linked against -lgcov).
>
Thanks for the comment Benjamin. Running nm on the libnspr4.so I can
see that these symbols are indeed undefined:
0007b110 r __PRETTY_FUNCTION__.2718
U __assert_fail@@GLIBC_2.0
00082054 A __bss_start
U __ctype_b_loc@@GLIBC_2.3
w __cxa_finalize@@GLIBC_2.1.3
00076130 t __divdi3
00076870 t __do_global_ctors_aux
0000a480 t __do_global_dtors_aux
00080b40 d __dso_handle
U __environ@@GLIBC_2.0
U __errno_location@@GLIBC_2.0
00076790 t __fstat
U __fxstat64@@GLIBC_2.2
U __fxstat@@GLIBC_2.0
U __gcov_execv
U __gcov_execve
U __gcov_fork
U __gcov_init
U __gcov_merge_add
w __gmon_start__
U __h_errno_location@@GLIBC_2.0
0000a517 t __i686.get_pc_thunk.bx
000762b0 t __moddi3
U __stack_chk_fail@@GLIBC_2.4
00076850 t __stack_chk_fail_local

One other thing that catches my eye here is that it appears that several
versions of GLIBC_2.x are being referenced. Is that normal?

I'm going to try to figure out why libnspr4.so isn't being linked
against -lgcov next, I'm going to respin the build and I'll update here
once I have something useful to report.

Reply all
Reply to author
Forward
0 new messages