ccache has problems with clang's precompiled headers, at least with Apple's version. clang stores the timestamps and sizes of all headers included in the PCH in that file. There is also a .data file that contains them, but they also seem to be part of the .pch file itself. When some of these headers are also managed by ccache and such a header and the PCH are restored from the cache, the timestamps do not match anymore, resulting in a compiler error. I don't see much that ccache can do about this. So I excluded the PCH file from ccache. What I do not understand is that whenever the PCH is rebuilt, all files that use that PCH are also rebuild, i.e. they are all cache misses. I would expect that when the headers included in the PCH are the same again, the output of the preprocessor would be as well. I use the recommended settings for PCHs mentioned in the ccache manual.
Actually, for the precompiled headers generated by (at least Apple's) clang, two changes in ccache are required: - When "-x *-header" is found, skip any caching and simply call the compiler. Precompiled headers cannot be cached, because they contain the timestamps of all header files that were used to create them. When these are also restored from the cache, their timestamps are newer than the ones stored in the precompiled header and compiling will fail. - When using a precompiled header, do not add it to the dependencies of a file. -fpch-preprocess will extract all information required by ccache from the precompiled header. Its binary state is not important and integrating it into the hash of a file will only result in unnecessary cache misses. If gcc's precompiled headers aren't any different, ccache.c:674-679 can simply be deleted.
Thanks for the bug report and analysis! Sorry about the delayed answer. Would you be interested in working on a patch for the indicated problem? > If gcc's precompiled headers aren't any different, ccache.c:674-679 can simply be deleted. ccache.c:674-679 have nothing to do with precompiled headers in the reported ccache version (3.2.1). Could you clarify?
Sorry, I probably was on the current HEAD of the ccache repo at that time. It is these lines that should be deleted from ccache.c: if (included_pch_file) { char *path = x_strdup(included_pch_file); path = make_relative_path(path); hash_string(hash, path); remember_include_file(path, hash); } However, for not caching the PCH file itself, I have not implemented a solution. Instead I do not use ccache when the PCH file is generated. Thus I do not have a pull request that would solve the problem in general.
Closing this now since no progress has been made for a long time. Please create a new issue at https://github.com/ccache/ccache/issues if wanted.