[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 22:34:39 +0000 (14:34 -0800)
commit5fbd1a333aa1a0b70903d036b98ea56c51ae5224
tree8b8f39c2f58c6e34a840f94d1411aad6deecf151
parent62d946e133f748d4500903c2b80fc456ff409505
[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