On Thursday 12 of July 2012, Joel Rosdahl wrote:
> On 6 July 2012 19:09, Lubos Lunak wrote:
> > the attached patches modify ccache to also support Clang PCH in addition
> > to GCC PCH.
>
> Thanks!
>
> Regarding 0002-hash-clang-s-.pch-file-explicitly.patch: Why is the third
> assignment of pch_file done outside the "if (stat(pchpath, &st) == 0)"
> block? This means that pch_file and included_pch_file can be set even when
> there is no .pch file, so remember_include_file will fail to stat the file
> and then turn off the direct mode. The test suite also fails after the
> patch, but passes if the pch_file assignment is moved into the block.
Right. I guess that was an oversight when I moved the "Multiple precompiled
headers used" error to one place. Fixed version attached.
> The patches look good otherwise.
>
> > PS: Since I've noticed in the archives the recent mail about issues with
> > ccache and warnings about unused arguments: The proper way to use ccache
> > with Clang is to set CCACHE_CPP2, which not only avoids these warnings,
> > but in general Clang works suboptimally if passed preprocessed output
> > (warning/error messages quoting sources are affected, some warnings are
> > not supressed in headers).
>
> Do you have any idea about the performance impact of using CCACHE_CPP2 for
> clang?
Debug build of LibreOffice, warm disk caches, empty ccache, make -j4 in
xmloff module:
CCACHE_CPP2=1:
494.64user 34.99system 2:15.60elapsed 390%CPU (0avgtext+0avgdata
1309824maxresident)k
0inputs+3752560outputs (507major+13592550minor)pagefaults 0swaps
not set:
457.17user 28.94system 2:06.15elapsed 385%CPU (0avgtext+0avgdata
1309312maxresident)k
0inputs+3758600outputs (444major+12098612minor)pagefaults 0swaps
So in this case CCACHE_CPP2 adds about 8% overhead. It might make a
difference for somebody, but I myself would prefer to get better error
messages from Clang (and I actually use ccache only for a buildbot, so I
don't find this worth the effort).
If somebody would feel like playing with this, note that Clang 3.2 will
have -E -Wp,-rewrite-includes, which only processes #include directives and
nothing more (I wrote the feature to solve a similar problem when using Clang
with Icecream for distributed builds, and I assume this is the only thing
ccache in fact wants from -E too). So using this in ccache for Clang should
presumably reduce this overhead.
--
Lubos Lunak
l.lu...@suse.cz
From d897f0388b35ca0b8e333e7e8edbd57a0c4ba3e1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lubo=C5=A1=20Lu=C5=88=C3=A1k?=
Date: Fri, 6 Jul 2012 18:45:05 +0200
Subject: [PATCH 2/2] hash clang's .pch file explicitly
It does not appear anywhere in the preprocessed output, so
process_preprocessed_file() would miss it.
---
ccache.c | 31 +++
1 files changed, 31 insertions(+), 0 deletions(-)
diff --git a/ccache.c b/ccache.c
index 12b62a4..926d6b2 100644
--- a/ccache.c
+++ b/ccache.c
@@ -171,6 +171,11 @@ static bool profile_generate = false;
*/
static bool using_precompiled_header = false;
+/*
+ * The .gch/.pch file used for compilation.
+ */
+static char *included_pch_file = NULL;
+
/* How long (in microseconds) to wait before breaking a stale lock. */
unsigned lock_staleness_limit = 200;
@@ -532,6 +537,16 @@ process_preprocessed_file(struct mdfour *hash, const char *path)
hash_buffer(hash, p, (end - p));
free(data);
+
+ /* Explicitly check the .gch/.pch file, Clang does not include any mention of it
+ in the preprocessed output. */
+ if (included_pch_file) {
+ char *path = x_strdup(included_pch_file);
+ path = make_relative_path(path);
+ hash_string(hash, path);
+ remember_include_file(path, strlen(included_pch_file), hash);
+ }
+
return true;
}
@@ -1680,6 +1695,7 @@ cc_process_args(struct args *orig_args, struct args **preprocessor_args,
*/
if (compopt_takes_path(argv[i])) {
char *relpath;
+ char *pch_file = NULL;
if (i == argc-1) {
cc_log("Missing argument to %s", argv[i]);
stats_update(STATS_ARGS);
@@ -1696,23 +1712,37 @@ cc_process_args(struct args *orig_args, struct args **preprocessor_args,
if (stat(argv[i+1], &st) == 0) {
cc_log("Detected use of precompiled header: %s", argv[i+1]);
found_pch = true;
+ pch_file = x_strdup(argv[i+1]);
}
} else {
char* gchpath = format("%s.gch", argv[i+1]);
if (stat(gchpath, &st) == 0) {
cc_log("Detected use of precompiled header: %s", gchpath);
found_pch = true;
+ pch_file = x_strdup(gchpath);
} else {
char* pchpath = format("%s.pch", argv[i+1]);
if (stat(pchpath, &st) == 0) {
cc_log("Detected use of precompiled header: %s", pchpath);
found_pch = true;
+ pch_file = x_strdup(pchpath);
}
free(pchpath);
}
free(gchpath);
}
+ if (pch_file) {
+if (included_pch_file) {
+ cc_log("Multiple precompiled headers used: %s and %s\n",
+ included_pch_file, pch_file);
+