Stale gcov data makes tests crash at exit after a rebuild
Symptom#
In a coverage build, many tests fail after a large rebuild although every test case passes. The test prints its passing doctest summary, then dies at process exit:
[doctest] test cases: 21 | 21 passed | 0 failed | 0 skipped
... Bus error***Exception
profiling: .../trace_loader.cpp.gcda: cannot merge previous GCDA file: mismatched number of counters (2)
profiling: .../trace_loader.cpp.gcda: cannot merge previous GCDA file: corrupt arc tag (0x01d4f934)
Tests that do not touch the changed code crash too, and the same binary run alone may exit 0 once and 138 the next time.
Cause#
gcov writes counters at exit and merges them into the .gcda files the earlier runs left. When the objects were rebuilt with a different shape (new functions, changed code), the old .gcda files no longer match, and the merge reads them as corrupt; in this case the runtime then crashed. Parallel ctest runs writing the same .gcda files make it worse.
Fix#
Delete the coverage data before running the tests again; the next run writes fresh files:
For timing runs of a coverage build, send the data elsewhere with GCOV_PREFIX=<scratch dir> so it never lands next to the objects.
Evidence#
- dftracer-utils,
ctest --preset testsafter adding a variant alternative to a core type (2026-09-27): 13 of 17 duql tests reported Bus error or SegFault after passing. Afterfind build/build-tests -name '*.gcda' -delete,test_http_parserexited 0 and the same ctest run had no exit crashes.