Skip to content

llvm-cov hangs indefinitely with instrumented clang build #131640

Open
@alyosharomanov

Description

@alyosharomanov

Description

llvm-cov export hangs indefinitely when attempting to export coverage data from an instrumented clang build. The process never completes and must be manually terminated.

Environment

  • OS: tried on Ubunut and MacOS
  • LLVM/Clang version: latest GitHub

Steps to Reproduce

1. Build release version of clang

mkdir clang-release
cd clang-release
cmake -G "Ninja" \
  -DCMAKE_C_COMPILER=clang \
  -DCMAKE_CXX_COMPILER=clang++ \
  -DCMAKE_BUILD_TYPE=Release \
  -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;lld" \
  -DLLVM_ENABLE_RUNTIMES="compiler-rt" \
  ../llvm-project/llvm
ninja

2. Build instrumented version of clang

mkdir clang-instrumented
cd clang-instrumented
cmake -G "Ninja" \
  -DCMAKE_C_COMPILER=../clang-release/bin/clang \
  -DCMAKE_CXX_COMPILER=../clang-release/bin/clang++ \
  -DCMAKE_C_FLAGS="-fprofile-instr-generate -fcoverage-mapping" \
  -DCMAKE_CXX_FLAGS="-fprofile-instr-generate -fcoverage-mapping" \
  -DCMAKE_BUILD_TYPE=Release \
  -DLLVM_ENABLE_ASSERTIONS=ON \
  -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;lld" \
  -DLLVM_ENABLE_RUNTIMES="compiler-rt" \
  ../llvm-project/llvm
ninja

3. Generate coverage data

# Compile a test program with the instrumented clang
./clang-instrumented/bin/clang program.cpp

# Process the raw profile data
./clang-release/bin/llvm-profdata merge -sparse default.profraw -o default.profdata

# Verify the profile data was generated correctly
./clang-release/bin/llvm-profdata show default.profdata
# This command completes successfully

# Export the coverage data - THIS HANGS INDEFINITELY
./clang-release/bin/llvm-cov export -object=clang-instrumented/bin/clang -instr-profile=default.profdata > default.json

Expected Behavior

The llvm-cov export command should complete in a reasonable amount of time and generate a JSON file with the coverage data.

Actual Behavior

The llvm-cov export command hangs indefinitely, sometimes for over an hour, without maxing out CPU or memory resources. In some cases, it eventually terminates on its own without producing any output or error messages.

Additional Information

  • The profile data seems to be generated correctly as verified by llvm-profdata show
  • Resource utilization during hang: CPU and memory do not max out during the hang
  • Timeout: I've waited over 1 hour with no results
  • The issue is selective based on binary complexity:
    • Works with: simpler binaries like llvm-mc and llvm-dwarfutil
    • Hangs with: more complex binaries like clang, lld, and opt

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions