I have tried the below to enable code coverage for ART.
With a standalone program I was able to get the coverage information using android sources by following these steps:
Link refered: http://clang.llvm.org/docs/SourceBasedCodeCoverage.html#using-the-profiling-runtime-without-static-initializers
export LD_LIBRARY_PATH=.
/out/host/linux-x86/bin/llvm-cov report ./libprog.so -instr-profile=foo.profdata
In Android, libart.so gets generated in 2 steps. First all the .cc files gets converted in to. o and then in to .so.
Now the challenge here is .o files are compiled with llvm_coverage mapping but it is not linked. We tried linking using ldflags but it throws the below error:
FAILED: out/soong/.intermediates/vendor/intel/art-extension/tools/cpp-define-generator/cpp-define-generator-data/linux_x86_64/cpp-define-generator-data
prebuilts/clang/host/linux-x86/clang-4053586/bin/clang++ @out/soong/.intermediates/vendor/intel/art-extension/tools/cpp-define-generator/cpp-define-generator-data/linux_x86_64/cpp-define-generator-data.rsp -Wl,--start-group out/soong/.intermediates/external/compiler-rt/libcompiler_rt-extras/linux_x86_64_static/libcompiler_rt-extras.a -Wl,--end-group out/soong/.intermediates/system/core/base/libbase/linux_x86_64_shared/libbase.so out/soong/.intermediates/external/libcxx/libc++/linux_x86_64_shared/libc++.so -o out/soong/.intermediates/vendor/intel/art-extension/tools/cpp-define-generator/cpp-define-generator-data/linux_x86_64/cpp-define-generator-data -target x86_64-linux-gnu -Bprebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.15-4.8/x86_64-linux/bin -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wl,--no-undefined-version --gcc-toolchain=prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.15-4.8 --sysroot prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.15-4.8/sysroot -m64 -Bprebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.15-4.8/lib/gcc/x86_64-linux/4.8 -Lprebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.15-4.8/lib/gcc/x86_64-linux/4.8 -Lprebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.15-4.8/x86_64-linux/lib64 -ldl -lpthread -lrt -fprofile-instr-generate -fcoverage-mapping -Wl,-rpath,\$ORIGIN/../lib64 -Wl,-rpath,\$ORIGIN/lib64 -pie -nodefaultlibs -lpthread -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc
external/compiler-rt/lib/profile/InstrProfilingFile.c:599: error: undefined reference to 'atexit'
clang.real: error: linker command failed with exit code 1 (use -v to see invocation)
I added prebuilts/clang/host/linux-x86/clang-4053586/lib64/clang/5.0.300080/lib/linux/libclang_rt.profile-x86_64.a this library to the command line and it was successful. But i am not sure how to add it Android.bp file.
I would like to know if code coverage is already enabled on Android O. If So which flag should we turn it on.