Coverage report of the `check-clang-analysis` target

I tried to create a coverage report using llvm-cov of clang executing the Static Analyzer tests via the check-clang-analysis build target.
I found that the LLVM_BUILD_INSTRUMENTED_COVERAGE=ON CMake option does this according to the documentation:
https://clang.llvm.org/docs/SourceBasedCodeCoverage.html#collecting-coverage-reports-for-the-llvm-project

However, I’m getting this result for executing the llvm/utils/prepare-code-coverage-artifact.py script:

:: Merging raw profiles...Done!
:: Preparing html report for ['build/with-coverage/bin/clang']...warning: 10942 functions have mismatched data
warning: 10942 functions have mismatched data
Done!

Does anyone know how to set up such coverage reports?
Why do I get this 10942 functions have mismatched data warning?

Here is my reproducer:

git clone git@github.com:llvm/llvm-project.git
cd llvm-project

cmake -S llvm -B build/with-coverage -GNinja \
  -DBUILD_SHARED_LIBS=ON \
  -DCMAKE_BUILD_TYPE=Debug \
  -DCMAKE_ASM_COMPILER=clang \
  -DCMAKE_CXX_COMPILER=clang++ \
  -DCMAKE_C_COMPILER=clang \
  -DLLVM_ENABLE_ASSERTIONS=ON \
  -DLLVM_ENABLE_BINDINGS=OFF \
  -DLLVM_USE_LINKER=lld \
  -DLLVM_ENABLE_DUMP=ON \
  -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra" \
  -DLLVM_TARGETS_TO_BUILD=X86 \
  -DLLVM_BUILD_INSTRUMENTED_COVERAGE=ON \
  -DLLVM_COV=$(which llvm-cov) \
  -DLLVM_PROFDATA=$(which llvm-profdata)

ninja -C build/with-coverage check-clang-analysis

llvm/utils/prepare-code-coverage-artifact.py \
  --preserve-profiles \
  -C build/with-coverage \
  $(which llvm-profdata) \
  $(which llvm-cov) \
  build/with-coverage/profiles \
  my-coverage-output-dir \
  build/with-coverage/bin/clang

/CC Some folks, as per

@ashpande @pogo59 @kpdev42 @beanz @River707 @gulfemsavrun

Oh, it seems like passing BUILD_SHARED_LIBS=OFF the result is much more promising. That way I have a coverage HTML, just as expected.

Should we document that you cannot have shared libs for this? I was quite confused why this doesn’t work.

However, I still get the 34 functions have mismatched data warning.
Why do I still have this?

The coverage report tool doesn’t traverse dynamic linkage boundaries, so you need to include all the binaries you want coverage data for in your call to the prepare-code-coverage-artifact.py script.

Your output shows you only provided clang, so it won’t generate data for any function not included in the clang binary.

The coverage report tool doesn’t traverse dynamic linkage boundaries, so you need to include all the binaries you want coverage data for in your call to the prepare-code-coverage-artifact.py script.

Why does it not follow dynamic linkage boundaries?