Skip to content

Commit da43368

Browse files
cdeckerclaude
andcommitted
docs: Document LLVM version mismatch issue and solution in coverage README
Added comprehensive troubleshooting section explaining: - Root cause: LLVM version mismatch between clang compiler and llvm-profdata tools - Symptoms: All profraw files marked as corrupt/incomplete - Solution: Use consistent LLVM version (e.g., clang-18) across compilation and processing - Implementation details in GitHub Actions workflow - Updated build phase and local usage sections with warnings about version specificity This helps users understand why profraw files may appear corrupt and how to fix it. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Haiku 4.5 <[email protected]>
1 parent 2433d99 commit da43368

File tree

1 file changed

+67
-4
lines changed

1 file changed

+67
-4
lines changed

contrib/coverage/README.md

Lines changed: 67 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@ This approach provides accurate, detailed coverage information across the entire
2929
When building with `--enable-coverage`, CLN binaries are instrumented with LLVM coverage tracking:
3030

3131
```bash
32-
./configure --enable-coverage CC=clang
32+
./configure --enable-coverage CC=clang-18
3333
make
3434
```
3535

3636
This adds instrumentation that writes `.profraw` files when binaries execute.
3737

38+
**⚠️ IMPORTANT:** Always specify the LLVM version explicitly (e.g., `clang-18`) rather than using `CC=clang`. This ensures compatibility with the same-version `llvm-profdata` tools used for processing. See [LLVM Version Mismatch](#profile-data-is-malformed-or-no-valid-profraw-files-found) for details.
39+
3840
### Collection Phase
3941

4042
During test execution, the `LLVM_PROFILE_FILE` environment variable controls where `.profraw` files are written:
@@ -346,10 +348,12 @@ export CLN_TEST_NAME=test_connect # Creates subdir per test
346348

347349
1. **Build with coverage:**
348350
```bash
349-
./configure --enable-coverage CC=clang
351+
./configure --enable-coverage CC=clang-18
350352
make
351353
```
352354

355+
**Note:** Use `CC=clang-18` (or whatever LLVM version you have installed) to ensure compatibility with your `llvm-profdata` tools. See [LLVM Version Mismatch](#profile-data-is-malformed-or-no-valid-profraw-files-found) troubleshooting section.
356+
353357
2. **Set coverage environment:**
354358
```bash
355359
export CLN_COVERAGE_DIR=/tmp/cln-coverage
@@ -414,14 +418,73 @@ To see which tests cover which code:
414418

415419
**Solution:** `collect-coverage.sh` handles this automatically via batched merging
416420

417-
### "Profile data is malformed"
421+
### "Profile data is malformed" or "No valid .profraw files found"
418422

419-
**Cause:** Corrupt or incomplete `.profraw` files (often from crashed tests)
423+
**Cause 1:** Corrupt or incomplete `.profraw` files (often from crashed tests)
420424

421425
**Solutions:**
422426
- Run `cleanup-corrupt-profraw.sh` to identify and remove corrupt files
423427
- `collect-coverage.sh` automatically filters these out
424428

429+
**Cause 2 (CRITICAL):** LLVM version mismatch between compilation and processing
430+
431+
**Symptoms:**
432+
- All `.profraw` files marked as "corrupt/incomplete"
433+
- `llvm-profdata` validation fails on all files
434+
- Error: "No valid .profraw files found (all N files were corrupt/incomplete)"
435+
- Files are actually valid, but compiled with different LLVM version than processing tools
436+
437+
**Root Cause:**
438+
The code is compiled with one version of `clang` (e.g., clang-14 from system apt), but processed with a different version of `llvm-profdata` tools (e.g., llvm-profdata-18). The profraw file format is version-specific and incompatible across major LLVM versions.
439+
440+
**Example of the problem:**
441+
```bash
442+
# WRONG: Compilation with default clang
443+
CC=clang ./configure --enable-coverage # Uses clang-14
444+
make
445+
446+
# Then processing with different LLVM tools
447+
llvm-profdata-18 merge *.profraw # FAILS: version mismatch!
448+
```
449+
450+
**Solution:**
451+
Ensure the same LLVM version is used for both compilation AND processing throughout the entire workflow:
452+
453+
1. **Use consistent LLVM from apt:** Install LLVM 18 tools in your setup script
454+
```bash
455+
# In setup.sh or your environment setup
456+
wget -qO - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
457+
sudo add-apt-repository "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 main"
458+
sudo apt-get install clang-18 llvm-18-tools
459+
```
460+
461+
2. **Specify the compiler explicitly:** Use `CC=clang-18` not just `CC=clang`
462+
```bash
463+
./configure --enable-coverage CC=clang-18
464+
make
465+
```
466+
467+
3. **Record the version:** Keep track of LLVM version used during compilation
468+
```bash
469+
clang-18 --version > LLVM_VERSION.txt
470+
llvm-profdata-18 --version >> LLVM_VERSION.txt
471+
```
472+
473+
4. **Verify consistency:** Before processing, verify the test/report jobs use the same LLVM version
474+
```bash
475+
# In test job:
476+
clang-18 --version # Should match compilation version
477+
llvm-profdata-18 --version
478+
```
479+
480+
**Current Implementation:**
481+
The GitHub Actions workflow now:
482+
- Installs LLVM 18 from apt in `setup.sh` (runs for all jobs)
483+
- Uses `CC=clang-18` explicitly during compilation
484+
- Records LLVM version in `LLVM_VERSION.txt` during build
485+
- Verifies version consistency in test and report jobs
486+
- This ensures all `.profraw` files are created and processed with identical LLVM 18 tools
487+
425488
### High disk usage during CI
426489

427490
**Cause:** Raw `.profraw` files are large and accumulate quickly

0 commit comments

Comments
 (0)