This is an archive of the discontinued LLVM Phabricator instance.

[Coverage]: Fixing bug: -fcoverage-mapping does not work with gc-sections
ClosedPublic

Authored by davidxl on Jan 11 2016, 12:20 AM.

Details

Reviewers
bogner
vsk
Summary

(The patch is intended for discussion purpose only)

With linker gc turned on, the linker will happily discard all __llvm_covmap sections from input objects so resulting executable file won't be usable with llvm-cov tool -- missing coverage data.

To demonstrate the problem, build a program with -fprofile-instr-generate -fcoverage-mapping -Wl,--gc-sections. The resulting exec won't be usable for coverage data dumping.

This patch shows one way to to fix the problem (demonstrated for Linux/FreeBSD only here). The idea is to force referencing coverage data module headers in profile dumper routines.

There are a couple of downsides:

  1. it works for linux/freeBSD, and can be extended for Darwin. Supporting on other platforms can be more complicated -- need runtime registration of coverage data start/end
  2. increases runtime overhead (physical memory and dumping time)

Another much better possible solution (verified manually on Linux) is quite simple -- set __llvm_covmap section with the right attributes such that they are not allocatable. When a section does not have the 'a' bit in attribute, the linker won't garbage collect it (just like debug sections).

This method has another added benefit --- process virtual memory size is reduced and the covmap section is now strippable. I think we should go with this approach instead (at least for ELF based systems). Thoughts?

Diff Detail

Event Timeline

davidxl updated this revision to Diff 44434.Jan 11 2016, 12:20 AM
davidxl retitled this revision from to [Coverage]: Fixing bug: -fcoverage-mapping does not work with gc-sections.
davidxl updated this object.
davidxl added reviewers: bogner, vsk.
davidxl added a subscriber: llvm-commits.
vsk accepted this revision.Aug 1 2016, 6:08 PM
vsk edited edge metadata.

This discussion is stale, and I'm closing it to clear out my queue.

David implemented this for ELF. There isn't a simple way to mark sections as non-allocatable on MachO. We don't have the gc-sections issue on Darwin, but I am planning on improving the dead-stripping situation there at some point.

This revision is now accepted and ready to land.Aug 1 2016, 6:08 PM
vsk closed this revision.Aug 1 2016, 6:08 PM