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.
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.
Does this bug still exist? I thought ccache deliberately hashes the preprocessor options in direct mode in order to avoid this?
(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.
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
Renamed bug title. See also discussion on http://www.mail-archive.com/ccache@lists.samba.org/msg00920.html.
*** Bug 8728 has been marked as a duplicate of this bug. ***
Another related discussion here: http://www.mail-archive.com/ccache@lists.samba.org/msg01029.html
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.