Bug 8424 - Direct mode may result in false cache hit when header file has been added to include directory
Summary: Direct mode may result in false cache hit when header file has been added to ...
Status: RESOLVED WONTFIX
Alias: None
Product: ccache
Classification: Unclassified
Component: ccache (show other bugs)
Version: 3.1.6
Hardware: All All
: P5 major
Target Milestone: ---
Assignee: Joel Rosdahl
QA Contact: Joel Rosdahl
URL:
Keywords:
: 8728 (view as bug list)
Depends on:
Blocks:
 
Reported: 2011-08-30 06:13 UTC by Rusty Russell
Modified: 2015-08-15 15:00 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Rusty Russell 2011-08-30 06:13:59 UTC
My ccanlint tool compiles up tests, then recompiles them with -Ireduced-features, where it has generated a different config.h.  I was getting failures because some object files were compiled with the old config.h, and some the new one.

I have an strace showing ccache reading the wrong config.h (it should get the one reduced-features/ not devel/cvs/ccan:

30865 execve("/usr/bin/ccache", ["/usr/bin/ccache", "/usr/local/bin/i686-linux-gnu-gc"..., "-g", "-Wall", "-Wstrict-prototypes", "-Wold-style-definition", "-Wmissing-prototypes", "-Wmissing-declarations", "-Wpointer-arith", "-Wwrite-strings", "-DCCAN_STR_DEBUG=1", "-Ireduced-features", "-I/home/rusty/devel/cvs/ccan", "-c", "-o", "/tmp/ccanlint-29351.1804289383/f"..., ...], [/* 42 vars */]) = 0
...
30865 stat64("/home/rusty/devel/cvs/ccan/config.h", {st_mode=S_IFREG|0644, st_size=1511, ...}) = 0
30865 open("/home/rusty/devel/cvs/ccan/config.h", O_RDONLY) = 6
30865 read(6, "/* Generated by CCAN configurato"..., 1511) = 1511
30865 read(6, "", 1511)                 = 0
30865 close(6)                          = 0

The workaround is to to disable direct mode, such as using CCACHE_UNIFY=1.
Comment 1 Joel Rosdahl 2011-09-04 08:16:17 UTC
Thanks for the bug report!

Unfortunately, this is a design bug in the direct mode, so it won't be easily fixable. I will have to think hard about this and possibly disable direct mode by default.
Comment 2 Andrew Stubbs 2012-09-24 09:11:58 UTC
Does this bug still exist? I thought ccache deliberately hashes the preprocessor options in direct mode in order to avoid this?
Comment 3 Joel Rosdahl 2012-11-04 13:40:26 UTC
(In reply to comment #2)
> Does this bug still exist?

Yes.

> I thought ccache deliberately hashes the preprocessor options in direct mode
> in order to avoid this?

Right, it does, but it doesn't help in this scenario. The problem is that in the direct mode, ccache records header files that were used by the compiler, but it doesn't record header files that were not used but could have been used if they existed. So, when ccache checks if a result could be taken from the cache, it can't check if the existence of a new header file should invalidate the result.
Comment 4 Ian Norton 2013-10-18 10:15:20 UTC
Simpler case to reproduce (using direct mode).

hello.c
inc2/hello.h

$ gcc -Iinc1 -Iinc2 -c hello.c 
# cache miss, result cached

add inc1/hello.h 

$ gcc -Iinc1 -Iinc2 -c hello.c 
# cache hit, inc1/hello.h ignored
Comment 5 Joel Rosdahl 2013-10-20 09:17:53 UTC
Renamed bug title.

See also discussion on http://www.mail-archive.com/ccache@lists.samba.org/msg00920.html.
Comment 6 Joel Rosdahl 2013-10-20 09:18:37 UTC
*** Bug 8728 has been marked as a duplicate of this bug. ***
Comment 7 Joel Rosdahl 2013-11-17 20:21:44 UTC
Another related discussion here: http://www.mail-archive.com/ccache@lists.samba.org/msg01029.html
Comment 8 Joel Rosdahl 2015-08-15 15:00:36 UTC
The only reasonable way I know to fix this problem is simply to remove the direct mode or disable it by default. My opinion (after thinking about it a couple of years ;-)) is that the problematic edge case is not important enough for disabling the direct mode by default.

I have documented the issue as a known problem in the ccache  manual and will leave it at that. Sorry.