Support code coverage profiling |
|||||||
Issue description
llvm-cov is a tool to provide code coverage.
It seems like our ToT version of clang doesn't support it.
I get to build and link a target with
cflags = [ "-fprofile-instr-generate", "-fcoverage-mapping" ]
ldflags = [ "-fprofile-instr-generate" ]
But when ran, it doesn't output any default.profraw file that I could find.
I tried to call __llvm_profile_write_file directly to explicitly write the file, but then I can't compile with clang from Chromium:
Undefined symbols for architecture x86_64:
"__llvm_profile_write_file()", referenced from:
This is defined in https://llvm.org/svn/llvm-project/compiler-rt/trunk/lib/profile/InstrProfiling.h.
So it seems that our clang is not built with the profile runtime library.
When using the regular clang, I get default.profraw just with the flags.
Reference:
http://clang.llvm.org/docs/SourceBasedCodeCoverage.html#using-the-profiling-runtime-without-static-initializers
,
Dec 20 2016
This sounds similar to bug 450379 – did this regress, or was that bug about something else? I'm not interested in working on this myself. (See one of the several threads on code coverage on chrome-team for some of the reasons.)
,
Dec 21 2016
Thank you for the pointers. I was trying initially to work with llvm-gov instead of gcov like in issue 450379 . I'll check if this is a regression. I checked that -fprofile-arcs/-ftest-coverage still work at compile time (compile outputs gcno), but haven't yet checked for the gcda at runtime. I need to call __gcov_flush, and hit the same "Undefined symbols for architecture xxxx: "_llvm_gcda_emit_arcs", referenced from:" as issue 450379 . So it's either a regression, or I need to pass an additional flag when compiling my target.
,
Dec 21 2016
,
Jan 23 2017
So I validate that the old approach with gcov worked: https://codereview.chromium.org/2654453002 While the new one doesn't: https://codereview.chromium.org/2648263002 What I don't get yet is that in the first, __gcov_flush is used, in the second, __llvm_profile_write_file is used. The first compiles and links, the second doesn’t: ninja -j1000 -C /Users/lpromero/Developer/bling/src/out/Debug-iphonesimulator ios_showcase_egtests ninja: Entering directory `/Users/lpromero/Developer/bling/src/out/Debug-iphonesimulator' [1/1] Regenerating ninja files [3/9] LINK obj/ios/showcase/x64/ios_showcase_egtests FAILED: obj/ios/showcase/x64/ios_showcase_egtests TOOL_VERSION=1478109034 ../../build/toolchain/mac/linker_driver.py ../../third_party/llvm-build/Release+Asserts/bin/clang++ -fprofile-instr-generate -Xlinker -rpath -Xlinker @executable_path/Frameworks -Xlinker -rpath -Xlinker @loader_path/Frameworks -Xlinker -rpath -Xlinker @executable_path/Frameworks -Xlinker -objc_abi_version -Xlinker 2 -Xlinker -sectcreate -Xlinker __TEXT -Xlinker __entitlements -Xlinker obj/ios/showcase/ios_showcase_egtests.xcent -arch x86_64 -Werror -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator10.2.sdk -stdlib=libc++ -mios-simulator-version-min=9.0 -Wl,-ObjC -F /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Library/Frameworks -F . -F . -L. -o "obj/ios/showcase/x64/ios_showcase_egtests" -Wl,-filelist,"obj/ios/showcase/x64/ios_showcase_egtests.rsp" -framework UIKit -framework CoreFoundation -framework CoreGraphics -framework CoreText -framework Foundation -framework XCTest -framework CFNetwork -framework Security -framework SystemConfiguration -framework EarlGrey -framework OCHamcrest -framework QuartzCore -framework Accelerate -framework MobileCoreServices -lresolv -framework ImageIO -lsqlite3 -framework WebKit -framework CoreBluetooth -framework CoreLocation -framework StoreKit -framework AssetsLibrary -framework MessageUI -framework PassKit -framework Photos -framework LocalAuthentication -framework AVFoundation Undefined symbols for architecture x86_64: "__llvm_profile_write_file()", referenced from: +[ShowcaseTestCase tearDown] in showcase_test_case.o "__llvm_profile_initialize_file()", referenced from: +[ShowcaseTestCase tearDown] in showcase_test_case.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) Traceback (most recent call last): File "../../build/toolchain/mac/linker_driver.py", line 229, in <module> Main(sys.argv) File "../../build/toolchain/mac/linker_driver.py", line 79, in Main subprocess.check_call(compiler_driver_args) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 540, in check_call raise CalledProcessError(retcode, cmd) subprocess.CalledProcessError: Command '['../../third_party/llvm-build/Release+Asserts/bin/clang++', '-fprofile-instr-generate', '-Xlinker', '-rpath', '-Xlinker', '@executable_path/Frameworks', '-Xlinker', '-rpath', '-Xlinker', '@loader_path/Frameworks', '-Xlinker', '-rpath', '-Xlinker', '@executable_path/Frameworks', '-Xlinker', '-objc_abi_version', '-Xlinker', '2', '-Xlinker', '-sectcreate', '-Xlinker', '__TEXT', '-Xlinker', '__entitlements', '-Xlinker', 'obj/ios/showcase/ios_showcase_egtests.xcent', '-arch', 'x86_64', '-Werror', '-isysroot', '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator10.2.sdk', '-stdlib=libc++', '-mios-simulator-version-min=9.0', '-Wl,-ObjC', '-F', '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Library/Frameworks', '-F', '.', '-F', '.', '-L.', '-o', 'obj/ios/showcase/x64/ios_showcase_egtests', '-Wl,-filelist,obj/ios/showcase/x64/ios_showcase_egtests.rsp', '-framework', 'UIKit', '-framework', 'CoreFoundation', '-framework', 'CoreGraphics', '-framework', 'CoreText', '-framework', 'Foundation', '-framework', 'XCTest', '-framework', 'CFNetwork', '-framework', 'Security', '-framework', 'SystemConfiguration', '-framework', 'EarlGrey', '-framework', 'OCHamcrest', '-framework', 'QuartzCore', '-framework', 'Accelerate', '-framework', 'MobileCoreServices', '-lresolv', '-framework', 'ImageIO', '-lsqlite3', '-framework', 'WebKit', '-framework', 'CoreBluetooth', '-framework', 'CoreLocation', '-framework', 'StoreKit', '-framework', 'AssetsLibrary', '-framework', 'MessageUI', '-framework', 'PassKit', '-framework', 'Photos', '-framework', 'LocalAuthentication', '-framework', 'AVFoundation']' returned non-zero exit status 1 ninja: build stopped: subcommand failed. But looking at compiler_rt source, both GCDAProfiling.c and InstrProfiling.c get built usually: https://github.com/llvm-mirror/compiler-rt/blob/master/lib/profile/CMakeLists.txt#L43 So I don't get why we have one but not the other.
,
Jan 23 2017
Actually, gcov only works locally. On the bots I get this error:
[15981/18775] LINK obj/ios/showcase/arm/Showcase
FAILED: obj/ios/showcase/arm/Showcase
export DEVELOPER_DIR=/b/build/slave/ios-device/build/src/build/ios_files/Xcode.app; TOOL_VERSION=1477667488 ../../build/toolchain/mac/linker_driver.py ../../third_party/llvm-build/Release+Asserts/bin/clang++ -fprofile-arcs -Xlinker -rpath -Xlinker @executable_path/Frameworks -Xlinker -objc_abi_version -Xlinker 2 -arch armv7 -Werror -isysroot /b/build/slave/ios-device/build/src/build/ios_files/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS10.0.sdk -stdlib=libc++ -miphoneos-version-min=9.0 -Wl,-ObjC -o "obj/ios/showcase/arm/Showcase" -Wl,-filelist,"obj/ios/showcase/arm/Showcase.rsp" -framework UIKit -framework CoreFoundation -framework CoreGraphics -framework CoreText -framework Foundation -framework CFNetwork -framework Security -framework SystemConfiguration -framework QuartzCore -framework Accelerate -framework MobileCoreServices -lresolv -framework ImageIO -lsqlite3 -framework WebKit -framework CoreBluetooth -framework CoreLocation -framework StoreKit -framework AssetsLibrary -framework MessageUI -framework PassKit -framework Photos -framework LocalAuthentication -framework AVFoundation
ld: file not found: /b/build/slave/ios-device/build/src/third_party/llvm-build/Release+Asserts/bin/../lib/clang/4.0.0/lib/darwin/libclang_rt.profile_ios.a
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Traceback (most recent call last):
File "../../build/toolchain/mac/linker_driver.py", line 229, in <module>
Main(sys.argv)
File "../../build/toolchain/mac/linker_driver.py", line 79, in Main
subprocess.check_call(compiler_driver_args)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 540, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['../../third_party/llvm-build/Release+Asserts/bin/clang++', '-fprofile-arcs', '-Xlinker', '-rpath', '-Xlinker', '@executable_path/Frameworks', '-Xlinker', '-objc_abi_version', '-Xlinker', '2', '-arch', 'armv7', '-Werror', '-isysroot', '/b/build/slave/ios-device/build/src/build/ios_files/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS10.0.sdk', '-stdlib=libc++', '-miphoneos-version-min=9.0', '-Wl,-ObjC', '-o', 'obj/ios/showcase/arm/Showcase', '-Wl,-filelist,obj/ios/showcase/arm/Showcase.rsp', '-framework', 'UIKit', '-framework', 'CoreFoundation', '-framework', 'CoreGraphics', '-framework', 'CoreText', '-framework', 'Foundation', '-framework', 'CFNetwork', '-framework', 'Security', '-framework', 'SystemConfiguration', '-framework', 'QuartzCore', '-framework', 'Accelerate', '-framework', 'MobileCoreServices', '-lresolv', '-framework', 'ImageIO', '-lsqlite3', '-framework', 'WebKit', '-framework', 'CoreBluetooth', '-framework', 'CoreLocation', '-framework', 'StoreKit', '-framework', 'AssetsLibrary', '-framework', 'MessageUI', '-framework', 'PassKit', '-framework', 'Photos', '-framework', 'LocalAuthentication', '-framework', 'AVFoundation']' returned non-zero exit status 1
https://build.chromium.org/p/tryserver.chromium.mac/builders/ios-device/builds/140273/steps/compile%20%28with%20patch%29/logs/stdio
,
Jan 23 2017
How come the error mentions libclang_rt.profile_ios.a while we only refer to libclang_rt.profile_iossim.a: tools/clang/scripts/package.py:219: 'lib/clang/*/lib/darwin/*profile_iossim*', Justin, any change there is an interaction with hermetic builds?
,
Jan 24 2017
https://codereview.chromium.org/2654453002/: gcov works for simulator but not device, which is probably expected.
,
Jan 24 2017
Where can I get the libclang_rt.profile_iossim.a that we use in our build of clang? Is it third_party/llvm-build/Release+Asserts/lib/clang/4.0.0/lib/darwin/libclang_rt.profile_iossim.a? Because that one has both symbols: 11:57 ~/Developer/bling/src % nm third_party/llvm-build/Release+Asserts/lib/clang/4.0.0/lib/darwin/libclang_rt.profile_iossim.a | grep __gcov_flush 0000000000001300 T ___gcov_flush 11:58 ~/Developer/bling/src % nm third_party/llvm-build/Release+Asserts/lib/clang/4.0.0/lib/darwin/libclang_rt.profile_iossim.a | grep __llvm_profile_write_file 00000000000008b0 T ___llvm_profile_write_file
,
Jan 24 2017
According to tools/clang/scripts/package.py, third_party/llvm-build/Release+Asserts/lib/clang/4.0.0/lib/darwin/libclang_rt.profile_iossim.a is the one we use.
,
Jan 24 2017
Seems close to my issue: http://stackoverflow.com/questions/24606402/llvm-fprofile-instr-generate-undefined-reference-to-llvm-profile-registe How do we build libclang_rt.profile_iossim.a?
,
Feb 16 2017
This CL compiles: https://codereview.chromium.org/2648263002/ It outputs a default.profraw file in the Documents directory of the app. For example: ~/Library/Developer/CoreSimulator/Devices/DB836A58-8465-4A7D-91CA-E5798980B2E4/data/Containers/Data/Application/B529E902-3ECD-4DA3-ADAE-EA06219D57D6/Documents Next step should be to generate a default.profdata file with the command: llvm-profdata merge -sparse default.profraw -o default.profdata Xcode comes with a version of that tool that we can invoke with xcrun: xcrun llvm-profdata merge -sparse default.profraw -o default.profdata The issue is that this outputs: error: default.profraw: Unsupported instrumentation profile format version I guess our version of clang is newer than Xcode's one, and indeed when building llvm-profdata from an llvm checkout, it works. The issue is then that llvm-cov fails to load the coverage: error: /Users/lpromero/Developer/bling/src/out/Debug-iphonesimulator/ios_showcase_egtests.app/ios_showcase_egtests: Failed to load coverage: Unknown architecture named: I opened issue 693061 to have llvm-profdata and llvm-cov tools matching our clang version be available to us. I think an alternative would be to build and test with Xcode's clang.
,
Mar 22 2017
,
Mar 31 2017
https://codereview.chromium.org/2789433004/ This works with Chromium clang and Xcode's llvm-cov/llvm-profdata, when passing a target architecture (see doc in CL).
,
May 4 2017
The following revision refers to this bug: https://chromium.googlesource.com/chromium/src.git/+/df93a8860b4379bb27d05bb0368189cf8e0f3a2b commit df93a8860b4379bb27d05bb0368189cf8e0f3a2b Author: lpromero <lpromero@chromium.org> Date: Thu May 04 09:42:20 2017 Add tools for code coverage support in iOS. In this CL, support is added to all unit tests targets and the Showcase Earl Grey tests. BUG= 676034 R=sdefresne@chromium.org,marq@chromium.org,lindsayw@chromium.org Review-Url: https://codereview.chromium.org/2789433004 Cr-Commit-Position: refs/heads/master@{#469301} [modify] https://crrev.com/df93a8860b4379bb27d05bb0368189cf8e0f3a2b/base/test/test_support_ios.mm [modify] https://crrev.com/df93a8860b4379bb27d05bb0368189cf8e0f3a2b/build/config/ios/BUILD.gn [modify] https://crrev.com/df93a8860b4379bb27d05bb0368189cf8e0f3a2b/build/config/ios/ios_sdk.gni [modify] https://crrev.com/df93a8860b4379bb27d05bb0368189cf8e0f3a2b/build/secondary/testing/gtest/BUILD.gn [add] https://crrev.com/df93a8860b4379bb27d05bb0368189cf8e0f3a2b/docs/ios/coverage.md [add] https://crrev.com/df93a8860b4379bb27d05bb0368189cf8e0f3a2b/docs/ios/images/coverage_xcode.png [add] https://crrev.com/df93a8860b4379bb27d05bb0368189cf8e0f3a2b/docs/ios/images/llvm-cov_report.png [add] https://crrev.com/df93a8860b4379bb27d05bb0368189cf8e0f3a2b/docs/ios/images/llvm-cov_report_folder.png [add] https://crrev.com/df93a8860b4379bb27d05bb0368189cf8e0f3a2b/docs/ios/images/llvm-cov_show.png [add] https://crrev.com/df93a8860b4379bb27d05bb0368189cf8e0f3a2b/docs/ios/images/llvm-cov_show_file.png [modify] https://crrev.com/df93a8860b4379bb27d05bb0368189cf8e0f3a2b/ios/build/tools/setup-gn.py [modify] https://crrev.com/df93a8860b4379bb27d05bb0368189cf8e0f3a2b/ios/showcase/test/BUILD.gn [modify] https://crrev.com/df93a8860b4379bb27d05bb0368189cf8e0f3a2b/ios/showcase/test/showcase_test_case.mm [delete] https://crrev.com/b6bec5fd85d27f68ba6ecdee9217ee0638e391ab/testing/coverage_util_ios.cc [modify] https://crrev.com/df93a8860b4379bb27d05bb0368189cf8e0f3a2b/testing/coverage_util_ios.h [add] https://crrev.com/df93a8860b4379bb27d05bb0368189cf8e0f3a2b/testing/coverage_util_ios.mm
,
May 4 2017
This is done. Either build out/Coverage-iphonesimulator, out/Coverage-iphoneos or just set ios_enable_coverage = true as gn argument. |
|||||||
►
Sign in to add a comment |
|||||||
Comment 1 by lpromero@chromium.org
, Dec 20 2016