|
iOSGCov
Using gcov with iOS
Featured Introduction
Undefined symbols:
"_vproc_transaction_end", referenced from:
_gcov_exit in libgcov.a(_gcov.o)
_vproc_transaction_end$non_lazy_ptr in libgcov.a(_gcov.o)
(maybe you meant: _vproc_transaction_end$non_lazy_ptr)
"_vproc_transaction_begin", referenced from:
___gcov_init in libgcov.a(_gcov.o)
_vproc_transaction_begin$non_lazy_ptr in libgcov.a(_gcov.o)
(maybe you meant: _vproc_transaction_begin$non_lazy_ptr)
ld: symbol(s) not found
collect2: ld returned 1 exit status
GCC 4.2.1 iPhone/10.5SDK Development gcov IssueThe problem with building on the iPhone/10.5SDK is even more "interesting". Normally to set up code coverage on Xcode, you turn on the "Instrument Program Flow" (-fprofile-arcs) and "Generate Test Coverage Files" (-ftest-coverage) flags, and add libgcov (-lgcov). When you build on the iPhone/10.5SDK using gcc 4.2.1, the stock libgcov included with gcc 4.2.1 has references to vproc_transaction_begin and vproc_transaction_end. These routines are defined in the 10.6 runtime (crt1.10.6.o) but are not defined in the 10.5 runtime (the iPhone SDKs, at least up to iPhone SDK 3.2, depend on the 10.5 runtime) so you receive the link errors. To get around this we have built our own version of libgcov that doesn't need vproc_transaction_begin and vproc_transaction_end. You can get it here. Should you want to build you own, you can grab the sources for the version of gcc included with Xcode 3.2.2 here and change this file so that it doesn't link in the vproc functions. I did this like so: #if defined(__APPLE__) && !defined(__STATIC__) && !defined(__ppc__) && !defined(__ppc64__) && !defined(__arm__) #include <vproc.h> #undef VPROC_HAS_TRANSACTIONS /* <---- dmaclach hack to turn off link errors on iPhone */ #if defined(VPROC_HAS_TRANSACTIONS) vproc_transaction_t vproc_transaction_begin(vproc_t virtual_proc) __attribute__((weak)); void vproc_transaction_end(vproc_t virtual_proc, vproc_transaction_t handle) __attribute__((weak)); #endif and then build with the following command sudo gnumake install RC_OS=macos RC_ARCHS='x86_64 i386 ppc' TARGETS='x86_64 i386 ppc' SRCROOT=`pwd` OBJROOT=`pwd`/build/obj DSTROOT=`pwd`/build/dst SYMROOT=`pwd`/build/sym lipo -create -arch i386 build/dst/usr/lib/gcc/i686-apple-darwin10/libgcov.a -arch x86_64 build/dst/usr/lib/gcc/i686-apple-darwin10/x86_64/libgcov.a -arch ppc build/dst/usr/lib/gcc/powerpc-apple-darwin10/4.2.1/libgcov.a -output ~/Desktop/libgcov.a which should make a 3 way fat version on your desktop. If you choose to link in our special version of libgcov, make sure to remove the -lgcov flag from your project/target, or you will run into multiply defined link errors. Your other option is to build with gcc 4.0 as it has a version of libgcov that works with the 10.5 runtime. Note that in addition to linking in our special libgcov, you will also need to get rid of any inlines in your prefix headers as described here. 0% code coverage issueFirst make sure that you have read this: General Snow Leopard gcov Issue. The most common cause of the 0% code coverage issue is that gcda files are not being generated. gcda files are generated by libgcov at exit time, which means that your app must exit properly. There are a couple of ways to do this from the simulator:
<key>UIApplicationExitsOnSuspend</key> <true/> |