Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 751463 - dev-util/ccache-4.0: mangles -fcolor-diagnostics and hides the compiler not supporting it in compile-but-not-link mode
Summary: dev-util/ccache-4.0: mangles -fcolor-diagnostics and hides the compiler not s...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All All
: Normal normal (vote)
Assignee: Gentoo Toolchain Maintainers
URL: https://github.com/ccache/ccache/issu...
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-10-27 15:14 UTC by Mihai Moldovan
Modified: 2020-11-22 20:57 UTC (History)
3 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
/tmp/ccache.log (ccache.log,15.02 KB, text/x-log)
2020-10-27 15:15 UTC, Mihai Moldovan
Details
webkit-gtk-2.28.4-ccache-nocolor.patch (webkit-gtk-2.28.4-ccache-nocolor.patch,778 bytes, patch)
2020-10-30 08:56 UTC, Sergei Trofimovich (RETIRED)
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Mihai Moldovan 2020-10-27 15:14:18 UTC
ccache 4.0 parses the command line and scans for options such as "-fcolor-diagnostics" (and a lot of other stuff, c.f., https://github.com/ccache/ccache/blob/v4.0/src/argprocessing.cpp#L217 and importantly https://github.com/ccache/ccache/blob/v4.0/src/argprocessing.cpp#L690 )

This makes sense in general, since ccache supports a multitude of compilers, and while -fcolor-diagnostics is a proper flag for clang, it isn't for GCC.

The downside of that is that the flags are mangled. For instance, ccache silently replaces the given -fcolor-diagnostics flags in its actual compilation step with the (supported by GCC) -fdiagnostics-color flag.

As a concrete example of breakage: compiler checks like in net-libs/webkit-gtk-2.28.4 that EXPLICITLY check if the compiler supports -fcolor-diagnostics are masked, the check succeeds wrongly, the flag is added to the global C(XX)FLAGS and everything breaks. You should be able the easily reproduce this issue with the MWE provided here, but another, even easier way is to try to configure net-libs/webkit-gtk with GCC as your system compiler and ccache 4.0 in use. This is just one example, though, the actual problem can occur otherwise as well (obviously).

It looks like this a regression in ccache 4.0 and hasn't been the case in the 3.x series.

When running the MWE, make sure that such an object is not cached (because that bypasses actual compiler invocation, naturally).

Also, do NOT use CCACHE_DISABLE=1, because this disables ccache's mangling and won't reproduce the problem.

Reproducible: Always

Steps to Reproduce:
MWE:

# cat src.c
int main(void) { return 0; }
# /usr/bin/x86_64-pc-linux-gnu-gcc -c -fcolor-diagnostics src.c -o /tmp/blargh
x86_64-pc-linux-gnu-gcc: error: unrecognized command line option ‘-fcolor-diagnostics’
# CCACHE_LOGFILE=/tmp/ccache.log /usr/lib/ccache/bin/x86_64-pc-linux-gnu-gcc -c -fcolor-diagnostics src.c -o /tmp/blargh
[no output, so the command succeeded]
# cat /tmp/ccache.log
[will be attached to this bug report]
Actual Results:  
Compile step succeeds when wrapped in ccache.

Expected Results:  
Compile step should fail.
Comment 1 Mihai Moldovan 2020-10-27 15:15:35 UTC
Created attachment 668813 [details]
/tmp/ccache.log
Comment 2 Mihai Moldovan 2020-10-27 15:16:42 UTC
Adding maintainer to CC.
Comment 3 Andrei Slavoiu 2020-10-27 15:24:49 UTC
Isn't the real issue here that net-libs/webkit-gtk-2.28.4 performs the check with one compiler (ccache + gcc in this case) then performs the actual build with a different compiler (gcc)?
Comment 4 Mihai Moldovan 2020-10-27 15:30:00 UTC
(In reply to Andrei Slavoiu from comment #3)
> Isn't the real issue here that net-libs/webkit-gtk-2.28.4 performs the check
> with one compiler (ccache + gcc in this case) then performs the actual build
> with a different compiler (gcc)?

You could think so, but no. webkit-gtk is actually using the ccache-wrapped compiler all the way.

I explicitly mentioned the compile-but-not-link mode, since *normal* compilation fails correctly, even with ccache 4.0:

# /usr/lib/ccache/bin/x86_64-pc-linux-gnu-gcc -fcolor-diagnostics /tmp/src.c -o /tmp/blargh
x86_64-pc-linux-gnu-gcc: error: unrecognized command line option ‘-fcolor-diagnostics’

Weirdly, it only wrongly succeeds when using the -c compiler flag.
Comment 5 Sergei Trofimovich (RETIRED) gentoo-dev 2020-10-27 18:54:53 UTC
> Steps to Reproduce:
> MWE:

> # cat src.c
> int main(void) { return 0; }

> # /usr/bin/x86_64-pc-linux-gnu-gcc -c -fcolor-diagnostics src.c -o
> /tmp/blargh
> x86_64-pc-linux-gnu-gcc: error: unrecognized command line option
> ‘-fcolor-diagnostics’

> /usr/lib/ccache/bin/x86_64-pc-linux-gnu-gcc
> -c -fcolor-diagnostics src.c -o /tmp/blargh
> [no output, so the command succeeded]

Yeah, that's an unfortunate breakage. Filed as https://github.com/ccache/ccache/issues/711
Comment 6 Sergei Trofimovich (RETIRED) gentoo-dev 2020-10-30 08:56:37 UTC
Created attachment 669296 [details, diff]
webkit-gtk-2.28.4-ccache-nocolor.patch

Meanwhile webkit-gtk-2.28.4-ccache-nocolor.patch is a workaround not to inject potentially unsupported diagnostics flags.
Comment 7 Larry the Git Cow gentoo-dev 2020-11-22 20:57:28 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=7158e6d5be786b4e656beea266330943fe2243d1

commit 7158e6d5be786b4e656beea266330943fe2243d1
Author:     Sergei Trofimovich <slyfox@gentoo.org>
AuthorDate: 2020-11-22 20:57:12 +0000
Commit:     Sergei Trofimovich <slyfox@gentoo.org>
CommitDate: 2020-11-22 20:57:23 +0000

    dev-util/ccache: bump up to 4.1
    
    Among other things it should fix inconsistent handling
    of `-fcolor-diagnostics` in compiler and linker drivers
    noticed by Mihai Moldovan.
    
    Closes: https://bugs.gentoo.org/751463
    Package-Manager: Portage-3.0.10, Repoman-3.0.2
    Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>

 dev-util/ccache/Manifest                           |   1 +
 dev-util/ccache/ccache-4.1.ebuild                  | 108 +++++++++++++++++++++
 dev-util/ccache/files/ccache-4.1-atomic.patch      |  23 +++++
 .../ccache/files/ccache-4.1-avoid-run-user.patch   |  18 ++++
 4 files changed, 150 insertions(+)