Skip to content

gcc: don't require .gcno for assembly compiled with coverage flags - #2845

Open
cstrahan wants to merge 1 commit into
mozilla:mainfrom
cstrahan:cstrahan/fix-coverage-assembly-gcno
Open

gcc: don't require .gcno for assembly compiled with coverage flags#2845
cstrahan wants to merge 1 commit into
mozilla:mainfrom
cstrahan:cstrahan/fix-coverage-assembly-gcno

Conversation

@cstrahan

Copy link
Copy Markdown

Problem

Caching an assembly compile that carries the gcov/coverage flags aborts the build:

$ sccache cc --coverage -c foo.S -o foo.o
sccache: encountered fatal error
sccache: error: failed to zip up compiler outputs
sccache: caused by: failed to open file `"foo.gcno"`
sccache: caused by: failed to open file `foo.gcno`: No such file or directory (os error 2)

--coverage / -ftest-coverage set outputs_gcno = true, and in gcc::parse_arguments
the .gcno note file is then added to the expected outputs as required
(optional: false). For C/C++/ObjC the compiler does emit a .gcno, but an assembly
input (.s / .S) accepts the coverage flags and produces no .gcno. When sccache
packages the compiler outputs for caching it can't find the file and fails the whole
compile.

This only surfaces because assembly is cacheable: the "Assembly language support" change
(d9d2eb6) added Language::Assembler / Language::AssemblerToPreprocess, so assembly
compiles now go through output packaging. Before that they were CannotCache and ran the
compiler directly, so the missing .gcno never mattered. It's the same class of bug as
the missing-.gcno case in #2275.

Real-world hit: any project that builds a .S under -Db_coverage/--coverage
(e.g. breakpad's breakpad_getcontext.S) can no longer be built through sccache with a
coverage build.

Fix

Mark the .gcno output optional for assembly languages. C/C++/ObjC are unchanged — the
.gcno stays required there, so a genuinely-missing note file for those languages is still
an error.

let optional = matches!(
    language,
    Language::Assembler | Language::AssemblerToPreprocess
);
outputs.insert("gcno", ArtifactDescriptor { path: gcno, optional });

Test

Added test_parse_arguments_coverage_assembly_gcno_optional, asserting that
--coverage -c foo.S yields a gcno output with optional: true (the existing
test_parse_arguments_coverage_outputs_gcno continues to assert optional: false for
foo.cpp).

Verified end to end with a from-source build:

  • sccache cc --coverage -c foo.S now succeeds and is cached;
  • sccache cc --coverage -c foo.c still emits and caches foo.gcno (restored on a cache
    hit), i.e. no regression for C/C++ coverage.

Fixes #2275.

Assembly inputs (.s/.S) accept --coverage / -ftest-coverage but never
emit a .gcno note file. Assembly became cacheable in the "Assembly
language support" change, after which sccache aborts caching such a
compile with "failed to zip up compiler outputs": the .gcno is added to
the expected outputs as required (optional: false), but the file does not
exist.

Mark the .gcno output optional for the assembly languages; C/C++/ObjC
keep requiring it, so a genuinely-missing note file there is still an
error. Adds a regression test.

Fixes mozilla#2275
@codecov-commenter

codecov-commenter commented Sep 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.42857% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 67.46%. Comparing base (4ffa89b) to head (c2e8197).

Files with missing lines Patch % Lines
src/compiler/gcc.rs 96.42% 1 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (4ffa89b) and HEAD (c2e8197). Click for more details.

HEAD has 9 uploads less than BASE
Flag BASE (4ffa89b) HEAD (c2e8197)
14 5
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2845      +/-   ##
==========================================
- Coverage   76.14%   67.46%   -8.69%     
==========================================
  Files          72       72              
  Lines       39807    38625    -1182     
==========================================
- Hits        30313    26060    -4253     
- Misses       9494    12565    +3071     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

clang coverage test compile error with precompile headers

2 participants