[ccache] Solve Android building problem when using ccache direct mode

Joel Rosdahl joel at rosdahl.net
Sat Apr 12 10:30:01 MDT 2014


Hi Dongsheng,

Basically, you have not set up ccache correctly. ccache relies on the
assumption that if the compiler check (by default the compiler's mtime) is
the same then the whole toolchain is the same. If you use different
(locations of the) toolchains but mtimes of the compilers are the same,
then you have to instruct ccache how to properly identify the compiler by
setting CCACHE_COMPILERCHECK to a suitable command. Or, disable the direct
mode like you mentioned.

One option is to use -MMD instead of -MD when compiling so that toolchain
headers don't end up in the .d files at all.

It might be possible to improve ccache to convert absolute paths to
relative paths in .d files in some clever way. Patches are welcome.


On 5 April 2014 17:24, Qu Dongsheng <qu.dongsheng at gmail.com> wrote:

>
> Hello
>
> When I was building Android source code on our building server, which many
> people share this machine and use ccache. I got an error that it tried to
> stat other people's system headers! After some debugging, I found that
> wrong dependency file was generated from the ccache.
>
> it was caused by
> - ccache is using direct mode
> - Every android source tree has prebuilt toolchain
> - Android compiles the C/C++ code with dependency file generated
> - We replaced Android prebuilt ccache with the ccache 3.1.7
>
> In such case, ccache just returns a wrong dependcency file, in which it
> contains the system headers with absolute path to other person's directory!
> I think that direct mode is not safe when dependency file will be
> generated. This issue happens even on the latest ccache. I made a patch to
> solve it, as follows. Of course, setting CCACHE_NODIRECT or CCACHE_UNIFY
> can solve the above building problem, but doing such will totally disable
> direct mode, we will not benefit from it.
>
> Is there better solution?
>
>
>
> commit 63da529963afa9e69b217d4dd0624f9828e294df
> Author: Qu Dongsheng <qu.dongsheng at gmail.com>
> Date:   Sat Apr 5 22:45:14 2014 +0800
>
>     Enabling direct mode is not safe when dependency file is generated.
>     As the dependency file contains the absolute paths to the system
> headers, wrong dependency file can be returned if toochain's location is
> changed.
>     This typically happens when multiple Android source trees are built on
> the same machine. (Every android source tree contains a copy of toolchain)
>
> diff --git a/ccache.c b/ccache.c
> index 02dbdfa..8efe921 100644
> --- a/ccache.c
> +++ b/ccache.c
> @@ -1995,6 +1995,7 @@ ccache(int argc, char *argv[])
>         cc_log("Source file: %s", input_file);
>         if (generating_dependencies) {
>                 cc_log("Dependency file: %s", output_dep);
> +               enable_direct = false;
>         }
>         cc_log("Object file: %s", output_obj);
>
>
>
>
>
> Dongsheng
> _______________________________________________
> ccache mailing list
> ccache at lists.samba.org
> https://lists.samba.org/mailman/listinfo/ccache
>


More information about the ccache mailing list