This looks like xcodebuild bug, but I just wanted to bring it up here as well. I've been having issues with this in our project and seen other people mentioning similar issue https://github.com/realm/realm-cocoa/issues/6814, so I've put together an example project that suffers from this issue.
https://github.com/petrpavlik/CodeCoverageBugExample/tree/master
This is unmodified app template generated by Xcode, where I've 2 swift packages that contain ObjC code - CocoaAsyncSocket and SDWebImage. I was able to replicate this with Realm package for instance, so it's not about these 2 particular packages.
Running xcodebuild to run tests and collect code coverage
https://github.com/petrpavlik/CodeCoverageBugExample/tree/master
This is unmodified app template generated by Xcode, where I've 2 swift packages that contain ObjC code - CocoaAsyncSocket and SDWebImage. I was able to replicate this with Realm package for instance, so it's not about these 2 particular packages.
Running xcodebuild to run tests and collect code coverage
Code Block xcodebuild "-workspace" "CodeCoverageBugExample.xcworkspace" "-scheme" "CodeCoverageBugExample" "build" "COMPILER_INDEX_STORE_ENABLE=NO" "test" "-destination" "id=2E465F79-A48A-4C32-BBE0-F1104A27E4C7" "-resultBundlePath" "Test.xcresult" "GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=YES" "GCC_GENERATE_TEST_COVERAGE_FILES=YES"
fails with following error.Code Block duplicate symbol '___gcov_flush' in: /Users/petr/Library/Developer/Xcode/DerivedData/CodeCoverageBugExample-gictjvuwzgnjolaocdbqaotvidpx/Build/Products/Debug-iphonesimulator/SDWebImage.o /Users/petr/Library/Developer/Xcode/DerivedData/CodeCoverageBugExample-gictjvuwzgnjolaocdbqaotvidpx/Build/Products/Debug-iphonesimulator/CocoaAsyncSocket.o ld: 1 duplicate symbol for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)