[Coverage] Store compilation dir separately in coverage mapping
authorPetr Hosek <phosek@google.com>
Wed, 10 Feb 2021 08:25:34 +0000 (00:25 -0800)
committerPetr Hosek <phosek@google.com>
Thu, 18 Feb 2021 20:27:42 +0000 (12:27 -0800)
commit97ec8fa5bb07e3f5bf25ddcb216b545cd3d03b65
tree8e98f16e91b6e85c8006c9b5f2b38a5d7445d8a0
parent063236646849564094f5fcfc947ad36dba0efedb
[Coverage] Store compilation dir separately in coverage mapping

We currently always store absolute filenames in coverage mapping.  This
is problematic for several reasons. It poses a problem for distributed
compilation as source location might vary across machines.  We are also
duplicating the path prefix potentially wasting space.

This change modifies how we store filenames in coverage mapping. Rather
than absolute paths, it stores the compilation directory and file paths
as given to the compiler, either relative or absolute. Later when
reading the coverage mapping information, we recombine relative paths
with the working directory. This approach is similar to handling
ofDW_AT_comp_dir in DWARF.

Finally, we also provide a new option, -fprofile-compilation-dir akin
to -fdebug-compilation-dir which can be used to manually override the
compilation directory which is useful in distributed compilation cases.

Differential Revision: https://reviews.llvm.org/D95753
19 files changed:
clang/include/clang/Basic/CodeGenOptions.h
clang/include/clang/Driver/Options.td
clang/lib/CodeGen/CoverageMappingGen.cpp
clang/lib/CodeGen/CoverageMappingGen.h
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/CodeGen/profile-compilation-dir.c [new file with mode: 0644]
clang/test/CoverageMapping/abspath.cpp
clang/test/Profile/profile-prefix-map.c
compiler-rt/include/profile/InstrProfData.inc
llvm/docs/CoverageMappingFormat.rst
llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
llvm/include/llvm/ProfileData/Coverage/CoverageMappingReader.h
llvm/include/llvm/ProfileData/Coverage/CoverageMappingWriter.h
llvm/include/llvm/ProfileData/InstrProfData.inc
llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp
llvm/test/tools/llvm-cov/Inputs/binary-formats.v6.linux64l [new file with mode: 0755]
llvm/test/tools/llvm-cov/binary-formats.c
llvm/unittests/ProfileData/CoverageMappingTest.cpp