Coverage parameters of the clang code coverage function change the code logic?

54 views Asked by At

I have a section of the BUILD.gn file configured as follows:

config("test") {
  cflags = [
    "-std=c++17",
    "-fvisibility=hidden",
  ]

  cflags_cc = [ "-fvisibility-inlines-hidden" ]

  ldflags = []

  if (enable_coverage) {
    # clang coverage options:
      cflags += [
        "-fprofile-arcs",
        "-ftest-coverage",
      ]
      ldflags += [ "--coverage" ]
    cflags += [
      "-mllvm",
      "-limited-coverage-experimental=true",
      "-fno-use-cxa-atexit",
    ]
  }
}

I have some test code that uses protobuffer and the libprotobuf library. I also hid all of the symbols from libprotobuf and only exposed the functions I need to use. When enable_coverage is false, the code compiles fine, but when enable_coverage is true, there are linker errors like this:

ld.lld: error: undefined symbol: google::protobuf::RepeatedField::elements() const

It's true that I didn't expose the google::protobuf::RepeatedField<int>::elements() const function symbol, but my test code didn't change at all, meaning it's the same whether enable_coverage is false or true. So why does this linker error happen only when enable_coverage is true?

After I exposed the google::protobuf::RepeatedField<int>::elements() const symbol in libprotobuf, the problem was resolved. But what I really want to know is why parameters like -fprofile-arcs, -ftest-coverageand --coveragewould affect the test code and cause new linker requirements. Thank you.

0

There are 0 answers