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

David Li via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 11 00:20:25 PST 2016


davidxl created this revision.
davidxl added reviewers: bogner, vsk.
davidxl added a subscriber: llvm-commits.
Herald added a subscriber: emaste.

(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?

http://reviews.llvm.org/D16045

Files:
  lib/profile/InstrProfiling.h
  lib/profile/InstrProfilingFile.c
  lib/profile/InstrProfilingPlatformLinux.c

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D16045.44434.patch
Type: text/x-patch
Size: 3572 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160111/c25bca74/attachment.bin>


More information about the llvm-commits mailing list