----- Original Message -----
On Thu, Aug 31, 2017 at 05:45:38AM -0400, Yongkui Guo wrote:
Hi,
I tried to do code coverage testing for libguestfs with gcov.
The steps are shown as follows: 1. Download and install the source package(libguestfs-1.36.5-1.el7.src.rpm)
Probably best to try building this from git instead of using RPMs, so we can get the changes working upstream first. Make sure to read this page first:
I will read it later. And I need to think about how to do code coverage in this way. Thanks.
+CFLAGS="-fprofile-arcs -ftest-coverage -g -O0"; export CFLAGS +LDFLAGS="-fprofile-arcs -ftest-coverage -lgcov"; export LDFLAGS
+sed -i 's/^CFLAGS = -fprofile-arcs -ftest-coverage -g -O0/CFLAGS = /g' /home/mockbuild/rpmbuild/BUILD/libguestfs-1.36.5/ocaml/Makefile
../libmlguestfs.a(libguestfsocaml_a-utils.o): In function `guestfs_int_string_is_valid': utils.c:(.text+0xb99): undefined reference to `c_isalpha' utils.c:(.text+0xbbf): undefined reference to `c_isdigit'
I suppose that we need to link the OCaml bindings to -lgnu, which your patch attempts:
+libguestfsocaml_a_LIBADD = \ + $(top_builddir)/gnulib/lib/libgnu.la +
... but the problem is that libguestfsocaml.a isn't really used for anything. See the comment in the same Makefile.am:
# Build the C part into a library, so that automake handles the C # compilation step for us. Note that we don't directly use this # library; we link with the object files that it generates. noinst_LIBRARIES = libguestfsocaml.a
You'll need to change all the places where $(libguestfsocaml_a_OBJECTS) is used instead, eg something like this untested change:
stamp-mlguestfs: libguestfsocaml.a $(guestfs_cmm) $(OCAMLMKLIB) -o mlguestfs \ $(libguestfsocaml_a_OBJECTS) guestfs.cmo \ $(LDFLAGS) \ $(LTLIBINTL) \ - -L../lib/.libs -lguestfs + -L../lib/.libs -lguestfs \ + -L../gnulib/lib/.libs -lgnu if HAVE_OCAMLOPT $(OCAMLMKLIB) -o mlguestfs \ $(libguestfsocaml_a_OBJECTS) guestfs.cmx \ $(LDFLAGS) \ $(LTLIBINTL) \ - -L../lib/.libs -lguestfs + -L../lib/.libs -lguestfs \ + -L../gnulib/lib/.libs -lgnu endif touch $@
I added the above changes as a patch. But it failed with the following error: --------------------------------------------------------- ... ocamlmklib -o mlguestfs \ libguestfsocaml_a-guestfs-c.o libguestfsocaml_a-guestfs-c-actions.o libguestfsocaml_a-guestfs-c-errnos.o ../common/utils/libguestfsocaml_a-utils.o guestfs.cmo \ -Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld \ \ -L../lib/.libs -lguestfs \ -L../gnulib/lib/.libs -lgnu Unknown option -Wl,-z,relro Unknown option -specs=/usr/lib/rpm/redhat/redhat-hardened-ld ocamlmklib -o mlguestfs \ libguestfsocaml_a-guestfs-c.o libguestfsocaml_a-guestfs-c-actions.o libguestfsocaml_a-guestfs-c-errnos.o ../common/utils/libguestfsocaml_a-utils.o guestfs.cmx \ -Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld \ \ -L../lib/.libs -lguestfs \ -L../gnulib/lib/.libs -lgnu Unknown option -Wl,-z,relro Unknown option -specs=/usr/lib/rpm/redhat/redhat-hardened-ld touch stamp-mlguestfs make[2]: Leaving directory `/home/mockbuild/rpmbuild/BUILD/libguestfs-1.36.5/ocaml' Making all in ocaml/examples make[2]: Entering directory `/home/mockbuild/rpmbuild/BUILD/libguestfs-1.36.5/ocaml/examples' ocamlfind ocamlopt -cclib -L../../lib/.libs -package unix -linkpkg \ -warn-error A -I .. mlguestfs.cmxa create_disk.ml -o create_disk ocamlfind ocamlopt -cclib -L../../lib/.libs -package unix -linkpkg \ -warn-error A -I .. mlguestfs.cmxa debug_logging.ml -o debug_logging /usr/bin/ld: cannot find -lgnu collect2: error: ld returned 1 exit status --------------------------------------------------------- Then I removed the '-lgnu' option. The error was still the same as before: --------------------------------------------------------- ... ocamlmklib -o mlguestfs \ libguestfsocaml_a-guestfs-c.o libguestfsocaml_a-guestfs-c-actions.o libguestfsocaml_a-guestfs-c-errnos.o ../common/utils/libguestfsocaml_a-utils.o guestfs.cmo \ -fprofile-arcs -ftest-coverage -lgcov \ \ -L../lib/.libs -lguestfs \ -L../gnulib/lib/.libs Unknown option -fprofile-arcs Unknown option -ftest-coverage ocamlmklib -o mlguestfs \ libguestfsocaml_a-guestfs-c.o libguestfsocaml_a-guestfs-c-actions.o libguestfsocaml_a-guestfs-c-errnos.o ../common/utils/libguestfsocaml_a-utils.o guestfs.cmx \ -fprofile-arcs -ftest-coverage -lgcov \ \ -L../lib/.libs -lguestfs \ -L../gnulib/lib/.libs Unknown option -fprofile-arcs Unknown option -ftest-coverage touch stamp-mlguestfs Warning: Element Unix.error not found make[2]: Leaving directory `/home/mockbuild/rpmbuild/BUILD/libguestfs-1.36.5/ocaml' Making all in ocaml/examples make[2]: Entering directory `/home/mockbuild/rpmbuild/BUILD/libguestfs-1.36.5/ocaml/examples' ocamlfind ocamlopt -cclib -L../../lib/.libs -package unix -linkpkg \ -warn-error A -I .. mlguestfs.cmxa create_disk.ml -o create_disk ocamlfind ocamlopt -cclib -L../../lib/.libs -package unix -linkpkg \ -warn-error A -I .. mlguestfs.cmxa debug_logging.ml -o debug_logging ../libmlguestfs.a(libguestfsocaml_a-utils.o): In function `guestfs_int_string_is_valid': utils.c:(.text+0xb99): undefined reference to `c_isalpha' utils.c:(.text+0xbbf): undefined reference to `c_isdigit' collect2: error: ld returned 1 exit status File "caml_startup", line 1: Error: Error during linking make[2]: *** [debug_logging] Error 2 make[2]: *** Waiting for unfinished jobs.... ../libmlguestfs.a(libguestfsocaml_a-utils.o): In function `guestfs_int_string_is_valid': utils.c:(.text+0xb99): undefined reference to `c_isalpha' utils.c:(.text+0xbbf): undefined reference to `c_isdigit' collect2: error: ld returned 1 exit status File "caml_startup", line 1: Error: Error during linking make[2]: *** [create_disk] Error 2 make[2]: Leaving directory `/home/mockbuild/rpmbuild/BUILD/libguestfs-1.36.5/ocaml/examples' make[1]: *** [all-recursive] Error 1 make[1]: Leaving directory `/home/mockbuild/rpmbuild/BUILD/libguestfs-1.36.5' make: *** [all] Error 2 error: Bad exit status from /var/tmp/rpm-tmp.FM2viv (%build) --------------------------------------------------------- Best wishes Yongkui Guo IRC: yoguo Tel: 15010777318