Undefined symbols ___llvm_profile_runtime when building a package with code coverage turned on

Hi, I've already reported this bug as [SR-14788] Linker error when code coverage is turned on for Swift Package with Objective-C code · Issue #57137 · apple/swift · GitHub, but I also wanted to post here in the hopes that somebody's stumbled upon the same thing (and had found a workaround).

In a nutshell: I have a Swift package with Objective-C code that depends on another package with Swift code. When building it without code coverage enabled, everything builds fine. When code coverage is turned on, I get undefined symbols. Ideally I'd rewrite this code to Swift, but that's not feasible at the moment.

StackOverflow mentions adding -fprofile-instr-generate to linker flags, but I don't know if that is even possible in a package manifest (or at least without using unsafe flags).

2 Likes

I've run into this issue too. I don't know if it's solvable, and adding that flag for standard builds seem problematic.

What I've found is this issue seems to happen when SwiftPM and possibly Xcode decide to build as a dylib. When my libraries are built as static libraries I don't get this error.

I'll be opening a bug with Apple when I get a chance as I'm not sure if the bug is in SwiftPM or Xcode.

Unfortunately this has to be dynamic as the library is included in multiple other libraries, so I would get duplicate symbols otherwise.

We’re having this problem too. Were either of you able to solve this?

I was able to work around this by using a local binary Swift package. Thankfully the package that was causing me problems (PLCrashReporter) provides an xcframework in their Github releases, and Xcode prefers local packages to remote ones when resolving dependencies.