Bug 11251 - ccache with clang PCH
Summary: ccache with clang PCH
Alias: None
Product: ccache
Classification: Unclassified
Component: ccache (show other bugs)
Version: 3.2.1
Hardware: x64 Mac OS X
: P5 normal
Target Milestone: ---
Assignee: Joel Rosdahl
QA Contact: Joel Rosdahl
Depends on:
Reported: 2015-05-03 11:07 UTC by Thomas Röfer
Modified: 2016-06-09 19:43 UTC (History)
1 user (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Röfer 2015-05-03 11:07:50 UTC
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.
Comment 1 Thomas Röfer 2015-05-15 17:11:27 UTC
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.
Comment 2 Joel Rosdahl 2015-08-15 14:46:33 UTC
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?
Comment 3 Thomas Röfer 2015-08-27 11:13:09 UTC
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.
Comment 4 Joel Rosdahl 2016-06-09 19:43:50 UTC
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.