1CCACHE(1) ccache Manual CCACHE(1)
2
3
4
6 ccache - a fast C/C++ compiler cache
7
9 ccache [options]
10 ccache compiler [compiler options]
11 compiler [compiler options] (via symbolic link)
12
14 Ccache is a compiler cache. It speeds up recompilation by caching the
15 result of previous compilations and detecting when the same compilation
16 is being done again.
17
18 Ccache has been carefully written to always produce exactly the same
19 compiler output that you would get without the cache. The only way you
20 should be able to tell that you are using ccache is the speed.
21 Currently known exceptions to this goal are listed under CAVEATS. If
22 you discover an undocumented case where ccache changes the output of
23 your compiler, please let us know.
24
26 There are two ways to use ccache. You can either prefix your
27 compilation commands with ccache or you can let ccache masquerade as
28 the compiler by creating a symbolic link (named as the compiler) to
29 ccache. The first method is most convenient if you just want to try out
30 ccache or wish to use it for some specific projects. The second method
31 is most useful for when you wish to use ccache for all your
32 compilations.
33
34 To use the first method, just make sure that ccache is in your PATH.
35
36 To use the symlinks method, do something like this:
37
38 cp ccache /usr/local/bin/
39 ln -s ccache /usr/local/bin/gcc
40 ln -s ccache /usr/local/bin/g++
41 ln -s ccache /usr/local/bin/cc
42 ln -s ccache /usr/local/bin/c++
43
44 And so forth. This will work as long as the directory with symlinks
45 comes before the path to the compiler (which is usually in /usr/bin).
46 After installing you may wish to run “which gcc” to make sure that the
47 correct link is being used.
48
49 Warning
50 The technique of letting ccache masquerade as the compiler works
51 well, but currently doesn’t interact well with other tools that do
52 the same thing. See Using ccache with other compiler wrappers.
53
54 Warning
55 Use a symbolic links for masquerading, not hard links.
56
58 These command line options only apply when you invoke ccache as
59 “ccache”. When invoked as a compiler (via a symlink as described in the
60 previous section), the normal compiler options apply and you should
61 refer to the compiler’s documentation.
62
63 Common options
64 -c, --cleanup
65 Clean up the cache by removing old cached files until the specified
66 file number and cache size limits are not exceeded. This also
67 recalculates the cache file count and size totals. Normally, there
68 is no need to initiate cleanup manually as ccache keeps the cache
69 below the specified limits at runtime and keeps statistics up to
70 date on each compilation. Forcing a cleanup is mostly useful if you
71 manually modify the cache contents or believe that the cache size
72 statistics may be inaccurate.
73
74 -C, --clear
75 Clear the entire cache, removing all cached files, but keeping the
76 configuration file.
77
78 --config-path PATH
79 Let the subsequent command line options operate on configuration
80 file PATH instead of the default. Using this option has the same
81 effect as setting the environment variable CCACHE_CONFIGPATH
82 temporarily.
83
84 -d, --directory PATH
85 Let the subsequent command line options operate on cache directory
86 PATH instead of the default. For example, to show statistics for a
87 cache directory at /shared/ccache you can run ccache -d
88 /shared/ccache -s. Using this option has the same effect as setting
89 the environment variable CCACHE_DIR temporarily.
90
91 --evict-older-than AGE
92 Remove files older than AGE from the cache. AGE should be an
93 unsigned integer with a d (days) or s (seconds) suffix.
94
95 -h, --help
96 Print a summary of command line options.
97
98 -F NUM, --max-files NUM
99 Set the maximum number of files allowed in the cache to NUM. Use 0
100 for no limit. The value is stored in a configuration file in the
101 cache directory and applies to all future compilations.
102
103 -M SIZE, --max-size SIZE
104 Set the maximum size of the files stored in the cache. SIZE should
105 be a number followed by an optional suffix: k, M, G, T (decimal),
106 Ki, Mi, Gi or Ti (binary). The default suffix is G. Use 0 for no
107 limit. The value is stored in a configuration file in the cache
108 directory and applies to all future compilations.
109
110 -X LEVEL, --recompress LEVEL
111 Recompress the cache to level LEVEL using the Zstandard algorithm.
112 The level can be an integer, with the same semantics as the
113 compression_level configuration option), or the special value
114 uncompressed for no compression. See Cache compression for more
115 information. This can potentionally take a long time since all
116 files in the cache need to be visited. Only files that are
117 currently compressed with a different level than LEVEL will be
118 recompressed.
119
120 -o KEY=VALUE, --set-config KEY=VALUE
121 Set configuration option KEY to VALUE. See Configuration for more
122 information.
123
124 -x, --show-compression
125 Print cache compression statistics. See Cache compression for more
126 information. This can potentionally take a long time since all
127 files in the cache need to be visited.
128
129 -p, --show-config
130 Print current configuration options and from where they originate
131 (environment variable, configuration file or compile-time default)
132 in human-readable format.
133
134 -s, --show-stats
135 Print a summary of configuration and statistics counters in
136 human-readable format.
137
138 -V, --version
139 Print version and copyright information.
140
141 -z, --zero-stats
142 Zero the cache statistics (but not the configuration options).
143
144 Options for scripting or debugging
145 --checksum-file PATH
146 Print the checksum (64 bit XXH3) of the file at PATH.
147
148 --dump-manifest PATH
149 Dump manifest file at PATH in text format to standard output. This
150 is only useful when debugging ccache and its behavior.
151
152 --dump-result PATH
153 Dump result file at PATH in text format to standard output. This is
154 only useful when debugging ccache and its behavior.
155
156 --extract-result PATH
157 Extract data stored in the result file at PATH. The data will be
158 written to ccache-result.* files in to the current working
159 directory. This is only useful when debugging ccache and its
160 behavior.
161
162 -k KEY, --get-config KEY
163 Print the value of configuration option KEY. See Configuration for
164 more information.
165
166 --hash-file PATH
167 Print the hash (160 bit BLAKE3) of the file at PATH. This is only
168 useful when debugging ccache and its behavior.
169
170 --print-stats
171 Print statistics counter IDs and corresponding values in
172 machine-parsable (tab-separated) format.
173
174 Extra options
175 When run as a compiler, ccache usually just takes the same command line
176 options as the compiler you are using. The only exception to this is
177 the option --ccache-skip. That option can be used to tell ccache to
178 avoid interpreting the next option in any way and to pass it along to
179 the compiler as-is.
180
181 Note
182 --ccache-skip currently only tells ccache not to interpret the next
183 option as a special compiler option — the option will still be
184 included in the direct mode hash.
185
186 The reason this can be important is that ccache does need to parse the
187 command line and determine what is an input filename and what is a
188 compiler option, as it needs the input filename to determine the name
189 of the resulting object file (among other things). The heuristic ccache
190 uses when parsing the command line is that any argument that exists as
191 a file is treated as an input file name. By using --ccache-skip you can
192 force an option to not be treated as an input file name and instead be
193 passed along to the compiler as a command line option.
194
195 Another case where --ccache-skip can be useful is if ccache interprets
196 an option specially but shouldn’t, since the option has another meaning
197 for your compiler than what ccache thinks.
198
200 ccache’s default behavior can be overridden by options in configuration
201 files, which in turn can be overridden by environment variables with
202 names starting with CCACHE_. Ccache normally reads configuration from
203 two files: first a system-level configuration file and secondly a
204 cache-specific configuration file. The priorities of configuration
205 options are as follows (where 1 is highest):
206
207 1. Environment variables.
208
209 2. The primary (cache-specific) configuration file (see below).
210
211 3. The secondary (system-wide read-only) configuration file
212 <sysconfdir>/ccache.conf (typically /etc/ccache.conf or
213 /usr/local/etc/ccache.conf).
214
215 4. Compile-time defaults.
216
217 As a special case, if the the environment variable CCACHE_CONFIGPATH is
218 set it specifies the primary configuration file and the secondary
219 (system-wide) configuration file won’t be read.
220
221 Location of the primary configuration file
222 The location of the primary (cache-specific) configuration is
223 determined like this:
224
225 1. If CCACHE_CONFIGPATH is set, use that path.
226
227 2. Otherwise, if the environment variable CCACHE_DIR is set then use
228 $CCACHE_DIR/ccache.conf.
229
230 3. Otherwise, if cache_dir is set in the secondary (system-wide)
231 configuration file then use <cache_dir>/ccache.conf.
232
233 4. Otherwise, if there is a legacy $HOME/.ccache directory then use
234 $HOME/.ccache/ccache.conf.
235
236 5. Otherwise, if XDG_CONFIG_HOME is set then use
237 $XDG_CONFIG_HOME/ccache/ccache.conf.
238
239 6. Otherwise, use %APPDATA%/ccache/ccache.conf (Windows),
240 $HOME/Library/Preferences/ccache/ccache.conf (macOS) or
241 $HOME/.config/ccache/ccache.conf (other systems).
242
243 Configuration file syntax
244 Configuration files are in a simple “key = value” format, one option
245 per line. Lines starting with a hash sign are comments. Blank lines are
246 ignored, as is whitespace surrounding keys and values. Example:
247
248 # Set maximum cache size to 10 GB:
249 max_size = 10G
250
251 Boolean values
252 Some configuration options are boolean values (i.e. truth values). In a
253 configuration file, such values must be set to the string true or
254 false. For the corresponding environment variables, the semantics are a
255 bit different:
256
257 · A set environment variable means “true” (even if set to the empty
258 string).
259
260 · The following case-insensitive negative values are considered an
261 error (instead of surprising the user): 0, false, disable and no.
262
263 · An unset environment variable means “false”.
264
265 Each boolean environment variable also has a negated form starting with
266 CCACHE_NO. For example, CCACHE_COMPRESS can be set to force compression
267 and CCACHE_NOCOMPRESS can be set to force no compression.
268
269 Configuration options
270 Below is a list of available configuration options. The corresponding
271 environment variable name is indicated in parentheses after each
272 configuration option key.
273
274 absolute_paths_in_stderr (CCACHE_ABSSTDERR)
275 This option specifies whether ccache should rewrite relative paths
276 in the compiler’s standard error output to absolute paths. This can
277 be useful if you use base_dir with a build system (e.g. CMake with
278 the "Unix Makefiles" generator) that executes the compiler in a
279 different working directory, which makes relative paths in compiler
280 errors or warnings incorrect. The default is false.
281
282 base_dir (CCACHE_BASEDIR)
283 This option should be an absolute path to a directory. If set,
284 ccache will rewrite absolute paths into paths relative to the
285 current working directory, but only absolute paths that begin with
286 base_dir. Cache results can then be shared for compilations in
287 different directories even if the project uses absolute paths in
288 the compiler command line. See also the discussion under Compiling
289 in different directories. If set to the empty string (which is the
290 default), no rewriting is done.
291
292 A typical path to use as base_dir is your home directory or another
293 directory that is a parent of your project directories. Don’t use /
294 as the base directory since that will make ccache also rewrite
295 paths to system header files, which typically is contraproductive.
296
297 For example, say that Alice’s current working directory is
298 /home/alice/project1/build and that she compiles like this:
299
300 ccache gcc -I/usr/include/example -I/home/alice/project2/include -c /home/alice/project1/src/example.c
301
302 Here is what ccache will actually execute for different base_dir
303 values:
304
305 # Current working directory: /home/alice/project1/build
306
307 # With base_dir = /:
308 gcc -I../../../../usr/include/example -I../../project2/include -c ../src/example.c
309
310 # With base_dir = /home or /home/alice:
311 gcc -I/usr/include/example -I../../project2/include -c ../src/example.c
312
313 # With base_dir = /home/alice/project1 or /home/alice/project1/src:
314 gcc -I/usr/include/example -I/home/alice/project2/include -c ../src/example.c
315
316 If Bob has put project1 and project2 in /home/bob/stuff and both
317 users have set base_dir to /home or /home/$USER, then Bob will get
318 a cache hit (if they share ccache directory) since the actual
319 command line will be identical to that of Alice:
320
321 # Current working directory: /home/bob/stuff/project1/build
322
323 # With base_dir = /home or /home/bob:
324 gcc -I/usr/include/example -I../../project2/include -c ../src/example.c
325
326 Without base_dir there will be a cache miss since the absolute
327 paths will differ. With base_dir set to / there will be a cache
328 miss since the relative path to /usr/include/example will be
329 different. With base_dir set to /home/bob/stuff/project1 there will
330 a cache miss since the path to project2 will be a different
331 absolute path.
332
333 cache_dir (CCACHE_DIR)
334 This option specifies where ccache will keep its cached compiler
335 outputs. The default is $XDG_CACHE_HOME/ccache if XDG_CACHE_HOME is
336 set, otherwise $HOME/.cache/ccache. Exception: If the legacy
337 directory $HOME/.ccache exists then that directory is the default.
338
339 See also Location of the primary configuration file.
340
341 If you want to use another CCACHE_DIR value temporarily for one
342 ccache invocation you can use the -d/--directory command line
343 option instead.
344
345 compiler (CCACHE_COMPILER or (deprecated) CCACHE_CC)
346 This option can be used to force the name of the compiler to use.
347 If set to the empty string (which is the default), ccache works it
348 out from the command line.
349
350 compiler_check (CCACHE_COMPILERCHECK)
351 By default, ccache includes the modification time (“mtime”) and
352 size of the compiler in the hash to ensure that results retrieved
353 from the cache are accurate. This option can be used to select
354 another strategy. Possible values are:
355
356 content
357 Hash the content of the compiler binary. This makes ccache very
358 slightly slower compared to mtime, but makes it cope better
359 with compiler upgrades during a build bootstrapping process.
360
361 mtime
362 Hash the compiler’s mtime and size, which is fast. This is the
363 default.
364
365 none
366 Don’t hash anything. This may be good for situations where you
367 can safely use the cached results even though the compiler’s
368 mtime or size has changed (e.g. if the compiler is built as
369 part of your build system and the compiler’s source has not
370 changed, or if the compiler only has changes that don’t affect
371 code generation). You should only use none if you know what you
372 are doing.
373
374 string:value
375 Hash value. This can for instance be a compiler revision number
376 or another string that the build system generates to identify
377 the compiler.
378
379 a command string
380 Hash the standard output and standard error output of the
381 specified command. The string will be split on whitespace to
382 find out the command and arguments to run. No other
383 interpretation of the command string will be done, except that
384 the special word %compiler% will be replaced with the path to
385 the compiler. Several commands can be specified with semicolon
386 as separator. Examples:
387
388 %compiler% -v
389
390 %compiler% -dumpmachine; %compiler% -dumpversion
391
392 You should make sure that the specified command is as fast as
393 possible since it will be run once for each ccache invocation.
394
395 Identifying the compiler using a command is useful if you want
396 to avoid cache misses when the compiler has been rebuilt but
397 not changed.
398
399 Another case is when the compiler (as seen by ccache) actually
400 isn’t the real compiler but another compiler wrapper — in that
401 case, the default mtime method will hash the mtime and size of
402 the other compiler wrapper, which means that ccache won’t be
403 able to detect a compiler upgrade. Using a suitable command to
404 identify the compiler is thus safer, but it’s also slower, so
405 you should consider continue using the mtime method in
406 combination with the prefix_command option if possible. See
407 Using ccache with other compiler wrappers.
408
409 compiler_type (CCACHE_COMPILERTYPE)
410 Ccache normally guesses the compiler type based on the compiler
411 name. The compiler_type option lets you force a compiler type. This
412 can be useful if the compiler has a non-standard name but is
413 actually one of the known compiler types. Possible values are:
414
415 auto
416 Guess one of the types below based on the compiler name
417 (following symlinks). This is the default.
418
419 clang
420 Clang-based compiler.
421
422 gcc
423 GCC-based compiler.
424
425 nvcc
426 NVCC (CUDA) compiler.
427
428 *other
429 Any compiler other than the known types.
430
431 pump
432 distcc’s "pump" script.
433
434 compression (CCACHE_COMPRESS or CCACHE_NOCOMPRESS, see Boolean values
435 above)
436 If true, ccache will compress data it puts in the cache. However,
437 this option has no effect on how files are retrieved from the
438 cache; compressed and uncompressed results will still be usable
439 regardless of this option. The default is true.
440
441 Compression is done using the Zstandard algorithm. The algorithm is
442 fast enough that there should be little reason to turn off
443 compression to gain performance. One exception is if the cache is
444 located on a compressed file system, in which case the compression
445 performed by ccache of course is redundant.
446
447 Compression will be disabled if file cloning (the file_clone
448 option) or hard linking (the hard_link option) is enabled.
449
450 compression_level (CCACHE_COMPRESSLEVEL)
451 This option determines the level at which ccache will compress
452 object files using the real-time compression algorithm Zstandard.
453 It only has effect if compression is enabled (which it is by
454 default). Zstandard is extremely fast for decompression and very
455 fast for compression for lower compression levels. The default is
456 0.
457
458 Semantics of compression_level:
459
460 > 0
461 A positive value corresponds to normal Zstandard compression
462 levels. Lower levels (e.g. 1) mean faster compression but
463 worse compression ratio. Higher levels (e.g. 19) mean slower
464 compression but better compression ratio. The maximum possible
465 value depends on the libzstd version, but at least up to 19 is
466 available for all versions. Decompression speed is essentially
467 the same for all levels. As a rule of thumb, use level 5 or
468 lower since higher levels may slow down compilations
469 noticeably. Higher levels are however useful when recompressing
470 the cache with command line option -X/--recompress.
471
472 < 0
473 A negative value corresponds to Zstandard’s “ultra-fast”
474 compression levels, which are even faster than level 1 but with
475 less good compression ratios. For instance, level -3
476 corresponds to “--fast=3” for the zstd command line tool. In
477 practice, there is little use for levels lower than -5 or so.
478
479 0 (default)
480 The value 0 means that ccache will choose a suitable level,
481 currently 1.
482
483 See the Zstandard documentation for more information.
484
485 cpp_extension (CCACHE_EXTENSION)
486 This option can be used to force a certain extension for the
487 intermediate preprocessed file. The default is to automatically
488 determine the extension to use for intermediate preprocessor files
489 based on the type of file being compiled, but that sometimes
490 doesn’t work. For example, when using the “aCC” compiler on HP-UX,
491 set the cpp extension to i.
492
493 debug (CCACHE_DEBUG or CCACHE_NODEBUG, see Boolean values above)
494 If true, enable the debug mode. The debug mode creates per-object
495 debug files that are helpful when debugging unexpected cache
496 misses. Note however that ccache performance will be reduced
497 slightly. See Cache debugging for more information. The default is
498 false.
499
500 debug_dir (CCACHE_DEBUGDIR)
501 Specifies where to write per-object debug files if the debug mode
502 is enabled. If set to the empty string, the files will be written
503 next to the object file. If set to a directory, the debug files
504 will be written with full absolute paths in that directory,
505 creating it if needed. The default is the empty string.
506
507 For example, if *debug_dir* is set to `/example`, the current working
508 directory is `/home/user` and the object file is `build/output.o` then the
509 debug log will be written to `/example/home/user/build/output.o.ccache-log`.
510 See also _<<_cache_debugging,Cache debugging>>_.
511
512 depend_mode (CCACHE_DEPEND or CCACHE_NODEPEND, see Boolean values
513 above)
514 If true, the depend mode will be used. The default is false. See
515 The depend mode.
516
517 direct_mode (CCACHE_DIRECT or CCACHE_NODIRECT, see Boolean values
518 above)
519 If true, the direct mode will be used. The default is true. See The
520 direct mode.
521
522 disable (CCACHE_DISABLE or CCACHE_NODISABLE, see Boolean values above)
523 When true, ccache will just call the real compiler, bypassing the
524 cache completely. The default is false.
525
526 extra_files_to_hash (CCACHE_EXTRAFILES)
527 This option is a list of paths to files that ccache will include in
528 the the hash sum that identifies the build. The list separator is
529 semicolon on Windows systems and colon on other systems.
530
531 file_clone (CCACHE_FILECLONE or CCACHE_NOFILECLONE, see Boolean values
532 above)
533 If true, ccache will attempt to use file cloning (also known as
534 “copy on write”, “CoW” or “reflinks”) to store and fetch cached
535 compiler results. file_clone has priority over hard_link. The
536 default is false.
537
538 Files stored by cloning cannot be compressed, so the cache size
539 will likely be significantly larger if this option is enabled.
540 However, performance may be improved depending on the use case.
541
542 Unlike the hard_link option, file_clone is completely safe to use,
543 but not all file systems support the feature. For such file
544 systems, ccache will fall back to use plain copying (or hard links
545 if hard_link is enabled).
546
547 hard_link (CCACHE_HARDLINK or CCACHE_NOHARDLINK, see Boolean values
548 above)
549 If true, ccache will attempt to use hard links to store and fetch
550 cached object files. The default is false.
551
552 Files stored via hard links cannot be compressed, so the cache size
553 will likely be significantly larger if this option is enabled.
554 However, performance may be improved depending on the use case.
555
556 Warning
557 Do not enable this option unless you are aware of these
558 caveats:
559
560 · If the resulting file is modified, the file in the cache will
561 also be modified since they share content, which corrupts the
562 cache entry. As of version 4.0, ccache makes stored and fetched
563 object files read-only as a safety measure guard. Furthermore,
564 a simple integrity check is made for cached object files by
565 verifying that their sizes are correct. This means that
566 mistakes like strip file.o or echo >file.o will be detected
567 even if the object file is made writeable, but a modification
568 that doesn’t change the file size will not.
569
570 · Programs that don’t expect that files from two different
571 identical compilations are hard links to each other can fail.
572
573 · Programs that rely on modification times (like “make”) can be
574 confused if several users (or one user with several build
575 trees) use the same cache directory. The reason for this is
576 that the object files share i-nodes and therefore modification
577 times. If file.o is in build tree A (hard-linked from the
578 cache) and file.o then is produced by ccache in build tree B by
579 hard-linking from the cache, the modification timestamp will be
580 updated for file.o in build tree A as well. This can retrigger
581 relinking in build tree A even though nothing really has
582 changed.
583
584 hash_dir (CCACHE_HASHDIR or CCACHE_NOHASHDIR, see Boolean values above)
585 If true (which is the default), ccache will include the current
586 working directory (CWD) in the hash that is used to distinguish two
587 compilations when generating debug info (compiler option -g with
588 variations). Exception: The CWD will not be included in the hash if
589 base_dir is set (and matches the CWD) and the compiler option
590 -fdebug-prefix-map is used. See also the discussion under Compiling
591 in different directories.
592
593 The reason for including the CWD in the hash by default is to
594 prevent a problem with the storage of the current working directory
595 in the debug info of an object file, which can lead ccache to
596 return a cached object file that has the working directory in the
597 debug info set incorrectly.
598
599 You can disable this option to get cache hits when compiling the
600 same source code in different directories if you don’t mind that
601 CWD in the debug info might be incorrect.
602
603 ignore_headers_in_manifest (CCACHE_IGNOREHEADERS)
604 This option is a list of paths to files (or directories with
605 headers) that ccache will not include in the manifest list that
606 makes up the direct mode. Note that this can cause stale cache hits
607 if those headers do indeed change. The list separator is semicolon
608 on Windows systems and colon on other systems.
609
610 ignore_options (CCACHE_IGNOREOPTIONS)
611 This option is a space-delimited list of compiler options that
612 ccache will exclude from the hash. Excluding a compiler option from
613 the hash can be useful when you know it doesn’t affect the result
614 (but ccache doesn’t know that), or when it does and you don’t care.
615 If a compiler option in the list is suffixed with an asterisk (*)
616 it will be matched as a prefix. For example, -fmessage-length=*
617 will match both -fmessage-length=20 and -fmessage-length=70.
618
619 inode_cache (CCACHE_INODECACHE or CCACHE_NOINODECACHE, see Boolean
620 values above)
621 If true, enables caching of source file hashes based on device,
622 inode and timestamps. This will reduce the time spent on hashing
623 included files as the result can be resused between compilations.
624
625 The feature is still experimental and thus off by default. It is
626 currently not available on Windows.
627
628 The feature requires temporary_dir to be located on a local
629 filesystem.
630
631 keep_comments_cpp (CCACHE_COMMENTS or CCACHE_NOCOMMENTS, see Boolean
632 values above)
633 If true, ccache will not discard the comments before hashing
634 preprocessor output. This can be used to check documentation with
635 -Wdocumentation.
636
637 limit_multiple (CCACHE_LIMIT_MULTIPLE)
638 Sets the limit when cleaning up. Files are deleted (in LRU order)
639 until the levels are below the limit. The default is 0.8 (= 80%).
640 See Automatic cleanup for more information.
641
642 log_file (CCACHE_LOGFILE)
643 If set to a file path, ccache will write information on what it is
644 doing to the specified file. This is useful for tracking down
645 problems.
646
647 If set to syslog, ccache will log using syslog() instead of to a
648 file. If you use rsyslogd, you can add something like this to
649 /etc/rsyslog.conf or a file in /etc/rsyslog.d:
650
651 # log ccache to file
652 :programname, isequal, "ccache" /var/log/ccache
653 # remove from syslog
654 & ~
655
656 max_files (CCACHE_MAXFILES)
657 This option specifies the maximum number of files to keep in the
658 cache. Use 0 for no limit (which is the default). See also Cache
659 size management.
660
661 max_size (CCACHE_MAXSIZE)
662 This option specifies the maximum size of the cache. Use 0 for no
663 limit. The default value is 5G. Available suffixes: k, M, G, T
664 (decimal) and Ki, Mi, Gi, Ti (binary). The default suffix is G. See
665 also Cache size management.
666
667 path (CCACHE_PATH)
668 If set, ccache will search directories in this list when looking
669 for the real compiler. The list separator is semicolon on Windows
670 systems and colon on other systems. If not set, ccache will look
671 for the first executable matching the compiler name in the normal
672 PATH that isn’t a symbolic link to ccache itself.
673
674 pch_external_checksum (CCACHE_PCH_EXTSUM or CCACHE_NOPCH_EXTSUM, see
675 Boolean values above)
676 When this option is set, and ccache finds a precompiled header
677 file, ccache will look for a file with the extension “.sum” added
678 (e.g. “pre.h.gch.sum”), and if found, it will hash this file
679 instead of the precompiled header itself to work around the
680 performance penalty of hashing very large files.
681
682 prefix_command (CCACHE_PREFIX)
683 This option adds a list of prefixes (separated by space) to the
684 command line that ccache uses when invoking the compiler. See also
685 Using ccache with other compiler wrappers.
686
687 prefix_command_cpp (CCACHE_PREFIX_CPP)
688 This option adds a list of prefixes (separated by space) to the
689 command line that ccache uses when invoking the preprocessor.
690
691 read_only (CCACHE_READONLY or CCACHE_NOREADONLY, see Boolean values
692 above)
693 If true, ccache will attempt to use existing cached results, but it
694 will not add new results to the cache. Statistics counters will
695 still be updated, though, unless the stats option is set to false.
696
697 If you are using this because your ccache directory is read-only,
698 you need to set temporary_dir since ccache will fail to create
699 temporary files otherwise. You may also want to set stats to false
700 make ccache not even try to update stats files.
701
702 read_only_direct (CCACHE_READONLY_DIRECT or CCACHE_NOREADONLY_DIRECT,
703 see Boolean values above)
704 Just like read_only except that ccache will only try to retrieve
705 results from the cache using the direct mode, not the preprocessor
706 mode. See documentation for read_only regarding using a read-only
707 ccache directory.
708
709 recache (CCACHE_RECACHE or CCACHE_NORECACHE, see Boolean values above)
710 If true, ccache will not use any previously stored result. New
711 results will still be cached, possibly overwriting any pre-existing
712 results.
713
714 run_second_cpp (CCACHE_CPP2 or CCACHE_NOCPP2, see Boolean values above)
715 If true, ccache will first run the preprocessor to preprocess the
716 source code (see The preprocessor mode) and then on a cache miss
717 run the compiler on the source code to get hold of the object file.
718 This is the default.
719
720 If false, ccache will first run preprocessor to preprocess the
721 source code and then on a cache miss run the compiler on the
722 preprocessed source code instead of the original source code. This
723 makes cache misses slightly faster since the source code only has
724 to be preprocessed once. The downside is that some compilers won’t
725 produce the same result (for instance diagnostics warnings) when
726 compiling preprocessed source code.
727
728 A solution to the above mentioned downside is to set run_second_cpp
729 to false and pass -fdirectives-only (for GCC) or -frewrite-includes
730 (for Clang) to the compiler. This will cause the compiler to leave
731 the macros and other preprocessor information, and only process the
732 #include directives. When run in this way, the preprocessor
733 arguments will be passed to the compiler since it still has to do
734 some preprocessing (like macros).
735
736 sloppiness (CCACHE_SLOPPINESS)
737 By default, ccache tries to give as few false cache hits as
738 possible. However, in certain situations it’s possible that you
739 know things that ccache can’t take for granted. This option makes
740 it possible to tell ccache to relax some checks in order to
741 increase the hit rate. The value should be a comma-separated string
742 with one or several of the following values:
743
744 clang_index_store
745 Ignore the Clang compiler option -index-store-path and its
746 argument when computing the manifest hash. This is useful if
747 you use Xcode, which uses an index store path derived from the
748 local project path. Note that the index store won’t be updated
749 correctly on cache hits if you enable this sloppiness.
750
751 file_stat_matches
752 Ccache normally examines a file’s contents to determine whether
753 it matches the cached version. With this sloppiness set, ccache
754 will consider a file as matching its cached version if the
755 mtimes and ctimes match.
756
757 file_stat_matches_ctime
758 Ignore ctimes when file_stat_matches is enabled. This can be
759 useful when backdating files' mtimes in a controlled way.
760
761 include_file_ctime
762 By default, ccache will not cache a file if it includes a
763 header whose ctime is too new. This sloppiness disables that
764 check. See also Handling of newly created header files.
765
766 include_file_mtime
767 By default, ccache will not cache a file if it includes a
768 header whose mtime is too new. This sloppiness disables that
769 check. See also Handling of newly created header files.
770
771 locale
772 Ccache includes the environment variables LANG, LC_ALL,
773 LC_CTYPE and LC_MESSAGES in the hash by default since they may
774 affect localization of compiler warning messages. Set this
775 sloppiness to tell ccache not to do that.
776
777 pch_defines
778 Be sloppy about #defines when precompiling a header file. See
779 Precompiled headers for more information.
780
781 modules
782 By default, ccache will not cache compilations if -fmodules is
783 used since it cannot hash the state of compiler’s internal
784 representation of relevant modules. This sloppiness allows
785 caching in such a case. See C++ modules for more information.
786
787 system_headers
788 By default, ccache will also include all system headers in the
789 manifest. With this sloppiness set, ccache will only include
790 system headers in the hash but not add the system header files
791 to the list of include files.
792
793 time_macros
794 Ignore __DATE__, __TIME__ and __TIMESTAMP__ being present in
795 the source code.
796
797 See the discussion under Troubleshooting for more information.
798
799 stats (CCACHE_STATS or CCACHE_NOSTATS, see Boolean values above)
800 If true, ccache will update the statistics counters on each
801 compilation. The default is true.
802
803 temporary_dir (CCACHE_TEMPDIR)
804 This option specifies where ccache will put temporary files. The
805 default is /run/user/<UID>/ccache-tmp if /run/user/<UID> exists,
806 otherwise <cache_dir>/tmp.
807
808 Note
809 In previous versions of ccache, CCACHE_TEMPDIR had to be on the
810 same filesystem as the CCACHE_DIR path, but this requirement
811 has been relaxed.)
812
813 umask (CCACHE_UMASK)
814 This option specifies the umask for files and directories in the
815 cache directory. This is mostly useful when you wish to share your
816 cache with other users.
817
819 By default, ccache has a 5 GB limit on the total size of files in the
820 cache and no limit on the number of files. You can set different limits
821 using the command line options -M/--max-size and -F/--max-files. Use
822 ccache -s/--show-stats to see the cache size and the currently
823 configured limits (in addition to other various statistics).
824
825 Cleanup can be triggered in two different ways: automatic and manual.
826
827 Automatic cleanup
828 Ccache maintains counters for various statistics about the cache,
829 including the size and number of all cached files. In order to improve
830 performance and reduce issues with concurrent ccache invocations, there
831 is one statistics file for each of the sixteen subdirectories in the
832 cache.
833
834 After a new compilation result has been written to the cache, ccache
835 will update the size and file number statistics for the subdirectory
836 (one of sixteen) to which the result was written. Then, if the size
837 counter for said subdirectory is greater than max_size / 16 or the file
838 number counter is greater than max_files / 16, automatic cleanup is
839 triggered.
840
841 When automatic cleanup is triggered for a subdirectory in the cache,
842 ccache will:
843
844 1. Count all files in the subdirectory and compute their aggregated
845 size.
846
847 2. Remove files in LRU (least recently used) order until the size is
848 at most limit_multiple * max_size / 16 and the number of files is
849 at most limit_multiple * max_files / 16, where limit_multiple,
850 max_size and max_files are configuration options.
851
852 3. Set the size and file number counters to match the files that were
853 kept.
854
855 The reason for removing more files than just those needed to not exceed
856 the max limits is that a cleanup is a fairly slow operation, so it
857 would not be a good idea to trigger it often, like after each cache
858 miss.
859
860 Manual cleanup
861 You can run ccache -c/--cleanup to force cleanup of the whole cache,
862 i.e. all of the sixteen subdirectories. This will recalculate the
863 statistics counters and make sure that the configuration options
864 max_size and max_files are not exceeded. Note that limit_multiple is
865 not taken into account for manual cleanup.
866
868 Ccache will by default compress all data it puts into the cache using
869 the compression algorithm Zstandard (zstd) using compression level 1.
870 The algorithm is fast enough that there should be little reason to turn
871 off compression to gain performance. One exception is if the cache is
872 located on a compressed file system, in which case the compression
873 performed by ccache of course is redundant. See the documentation for
874 the configuration options compression and compression_level for more
875 information.
876
877 You can use the command line option -x/--show-compression to print
878 information related to compression. Example:
879
880 Total data: 14.8 GB (16.0 GB disk blocks)
881 Compressed data: 11.3 GB (30.6% of original size)
882 - Original data: 36.9 GB
883 - Compression ratio: 3.267 x (69.4% space savings)
884 Incompressible data: 3.5 GB
885
886 Notes:
887
888 · The “disk blocks” size is the cache size when taking disk block
889 size into account. This value should match the “cache size” value
890 from “ccache --show-stats”. The other size numbers refer to actual
891 content sizes.
892
893 · “Compressed data” refers to result and manifest files stored in the
894 cache.
895
896 · “Incompressible data” refers to files that are always stored
897 uncompressed (triggered by enabling file_clone or hard_link) or
898 unknown files (for instance files created by older ccache
899 versions).
900
901 · The compression ratio is affected by compression_level.
902
903 The cache data can also be recompressed to another compression level
904 (or made uncompressed) with the command line option -X/--recompress. If
905 you choose to disable compression by default or to use a low
906 compression level, you can (re)compress newly cached data with a higher
907 compression level after the build or at another time when there are
908 more CPU cycles available, for instance every night. Full recompression
909 potentially takes a lot of time, but only files that are currently
910 compressed with a different level than the target level will be
911 recompressed.
912
914 ccache -s/--show-stats can show the following statistics:
915
916 ┌───────────────────────────┬────────────────────────────┐
917 │Name │ Description │
918 ├───────────────────────────┼────────────────────────────┤
919 │ │ │
920 │autoconf compile/link │ Uncachable compilation or │
921 │ │ linking by an autoconf │
922 │ │ test. │
923 ├───────────────────────────┼────────────────────────────┤
924 │ │ │
925 │bad compiler arguments │ Malformed compiler │
926 │ │ argument, e.g. missing a │
927 │ │ value for a compiler │
928 │ │ option that requires an │
929 │ │ argument or failure to │
930 │ │ read a file specified by a │
931 │ │ compiler option argument. │
932 ├───────────────────────────┼────────────────────────────┤
933 │ │ │
934 │cache file missing │ A file was unexpectedly │
935 │ │ missing from the cache. │
936 │ │ This only happens in rare │
937 │ │ situations, e.g. if one │
938 │ │ ccache instance is about │
939 │ │ to get a file from the │
940 │ │ cache while another │
941 │ │ instance removed the file │
942 │ │ as part of cache cleanup. │
943 ├───────────────────────────┼────────────────────────────┤
944 │ │ │
945 │cache hit (direct) │ A result was successfully │
946 │ │ found using the direct │
947 │ │ mode. │
948 ├───────────────────────────┼────────────────────────────┤
949 │ │ │
950 │cache hit (preprocessed) │ A result was successfully │
951 │ │ found using the │
952 │ │ preprocessor mode. │
953 ├───────────────────────────┼────────────────────────────┤
954 │ │ │
955 │cache miss │ No result was found. │
956 ├───────────────────────────┼────────────────────────────┤
957 │ │ │
958 │cache size │ Current size of the cache. │
959 ├───────────────────────────┼────────────────────────────┤
960 │ │ │
961 │called for link │ The compiler was called │
962 │ │ for linking, not │
963 │ │ compiling. Ccache only │
964 │ │ supports compilation of a │
965 │ │ single file, i.e. calling │
966 │ │ the compiler with the -c │
967 │ │ option to produce a single │
968 │ │ object file from a single │
969 │ │ source file. │
970 ├───────────────────────────┼────────────────────────────┤
971 │ │ │
972 │called for preprocessing │ The compiler was called │
973 │ │ for preprocessing, not │
974 │ │ compiling. │
975 ├───────────────────────────┼────────────────────────────┤
976 │ │ │
977 │can’t use precompiled │ Preconditions for using │
978 │header │ precompiled headers were │
979 │ │ not fulfilled. │
980 ├───────────────────────────┼────────────────────────────┤
981 │ │ │
982 │can’t use modules │ Preconditions for using │
983 │ │ C++ modules were not │
984 │ │ fulfilled. │
985 ├───────────────────────────┼────────────────────────────┤
986 │ │ │
987 │ccache internal error │ Unexpected failure, e.g. │
988 │ │ due to problems │
989 │ │ reading/writing the cache. │
990 ├───────────────────────────┼────────────────────────────┤
991 │ │ │
992 │cleanups performed │ Number of cleanups │
993 │ │ performed, either │
994 │ │ implicitly due to the │
995 │ │ cache size limit being │
996 │ │ reached or due to explicit │
997 │ │ ccache -c/--cleanup calls. │
998 ├───────────────────────────┼────────────────────────────┤
999 │ │ │
1000 │compile failed │ The compilation failed. No │
1001 │ │ result stored in the │
1002 │ │ cache. │
1003 ├───────────────────────────┼────────────────────────────┤
1004 │ │ │
1005 │compiler check failed │ A compiler check program │
1006 │ │ specified by │
1007 │ │ compiler_check │
1008 │ │ (CCACHE_COMPILERCHECK) │
1009 │ │ failed. │
1010 ├───────────────────────────┼────────────────────────────┤
1011 │ │ │
1012 │compiler produced empty │ The compiler’s output file │
1013 │output │ (typically an object file) │
1014 │ │ was empty after │
1015 │ │ compilation. │
1016 ├───────────────────────────┼────────────────────────────┤
1017 │ │ │
1018 │compiler produced no │ The compiler’s output file │
1019 │output │ (typically an object file) │
1020 │ │ was missing after │
1021 │ │ compilation. │
1022 ├───────────────────────────┼────────────────────────────┤
1023 │ │ │
1024 │compiler produced stdout │ The compiler wrote data to │
1025 │ │ standard output. This is │
1026 │ │ something that compilers │
1027 │ │ normally never do, so │
1028 │ │ ccache is not designed to │
1029 │ │ store such output in the │
1030 │ │ cache. │
1031 ├───────────────────────────┼────────────────────────────┤
1032 │ │ │
1033 │couldn’t find the compiler │ The compiler to execute │
1034 │ │ could not be found. │
1035 ├───────────────────────────┼────────────────────────────┤
1036 │ │ │
1037 │error hashing extra file │ Failure reading a file │
1038 │ │ specified by │
1039 │ │ extra_files_to_hash │
1040 │ │ (CCACHE_EXTRAFILES). │
1041 ├───────────────────────────┼────────────────────────────┤
1042 │ │ │
1043 │files in cache │ Current number of files in │
1044 │ │ the cache. │
1045 ├───────────────────────────┼────────────────────────────┤
1046 │ │ │
1047 │multiple source files │ The compiler was called to │
1048 │ │ compile multiple source │
1049 │ │ files in one go. This is │
1050 │ │ not supported by ccache. │
1051 ├───────────────────────────┼────────────────────────────┤
1052 │ │ │
1053 │no input file │ No input file was │
1054 │ │ specified to the compiler. │
1055 ├───────────────────────────┼────────────────────────────┤
1056 │ │ │
1057 │output to a non-regular │ The output path specified │
1058 │file │ with -o is not a file │
1059 │ │ (e.g. a directory or a │
1060 │ │ device node). │
1061 ├───────────────────────────┼────────────────────────────┤
1062 │ │ │
1063 │output to stdout │ The compiler was │
1064 │ │ instructed to write its │
1065 │ │ output to standard output │
1066 │ │ using -o -. This is not │
1067 │ │ supported by ccache. │
1068 ├───────────────────────────┼────────────────────────────┤
1069 │ │ │
1070 │preprocessor error │ Preprocessing the source │
1071 │ │ code using the compiler’s │
1072 │ │ -E option failed. │
1073 ├───────────────────────────┼────────────────────────────┤
1074 │ │ │
1075 │stats updated │ When statistics were │
1076 │ │ updated the last time. │
1077 ├───────────────────────────┼────────────────────────────┤
1078 │ │ │
1079 │stats zeroed │ When ccache -z was called │
1080 │ │ the last time. │
1081 ├───────────────────────────┼────────────────────────────┤
1082 │ │ │
1083 │unsupported code directive │ Code like the assembler │
1084 │ │ .incbin directive was │
1085 │ │ found. This is not │
1086 │ │ supported by ccache. │
1087 ├───────────────────────────┼────────────────────────────┤
1088 │ │ │
1089 │unsupported compiler │ A compiler option not │
1090 │option │ supported by ccache was │
1091 │ │ found. │
1092 ├───────────────────────────┼────────────────────────────┤
1093 │ │ │
1094 │unsupported source │ A source language e.g. │
1095 │language │ specified with -x was │
1096 │ │ unsupported by ccache. │
1097 └───────────────────────────┴────────────────────────────┘
1098
1100 The basic idea is to detect when you are compiling exactly the same
1101 code a second time and reuse the previously produced output. The
1102 detection is done by hashing different kinds of information that should
1103 be unique for the compilation and then using the hash sum to identify
1104 the cached output. Ccache uses BLAKE3, a very fast cryptographic hash
1105 algorithm, for the hashing. On a cache hit, ccache is able to supply
1106 all of the correct compiler outputs (including all warnings, dependency
1107 file, etc) from the cache. Data stored in the cache is checksummed with
1108 XXH3, an extremely fast non-cryptographic algorithm, to detect
1109 corruption.
1110
1111 Ccache has two ways of gathering information used to look up results in
1112 the cache:
1113
1114 · the preprocessor mode, where ccache runs the preprocessor on the
1115 source code and hashes the result
1116
1117 · the direct mode, where ccache hashes the source code and include
1118 files directly
1119
1120 The direct mode is generally faster since running the preprocessor has
1121 some overhead.
1122
1123 If no previous result is detected (i.e., there is a cache miss) using
1124 the direct mode, ccache will fall back to the preprocessor mode unless
1125 the depend mode is enabled. In the depend mode, ccache never runs the
1126 preprocessor, not even on cache misses. Read more in The depend mode
1127 below.
1128
1129 Common hashed information
1130 The following information is always included in the hash:
1131
1132 · the extension used by the compiler for a file with preprocessor
1133 output (normally .i for C code and .ii for C++ code)
1134
1135 · the compiler’s size and modification time (or other
1136 compiler-specific information specified by compiler_check)
1137
1138 · the name of the compiler
1139
1140 · the current directory (if hash_dir is enabled)
1141
1142 · contents of files specified by extra_files_to_hash (if any)
1143
1144 The preprocessor mode
1145 In the preprocessor mode, the hash is formed of the common information
1146 and:
1147
1148 · the preprocessor output from running the compiler with -E
1149
1150 · the command line options except those that affect include files
1151 (-I, -include, -D, etc; the theory is that these command line
1152 options will change the preprocessor output if they have any effect
1153 at all)
1154
1155 · any standard error output generated by the preprocessor
1156
1157 Based on the hash, the cached compilation result can be looked up
1158 directly in the cache.
1159
1160 The direct mode
1161 In the direct mode, the hash is formed of the common information and:
1162
1163 · the input source file
1164
1165 · the compiler options
1166
1167 Based on the hash, a data structure called “manifest” is looked up in
1168 the cache. The manifest contains:
1169
1170 · references to cached compilation results (object file, dependency
1171 file, etc) that were produced by previous compilations that matched
1172 the hash
1173
1174 · paths to the include files that were read at the time the
1175 compilation results were stored in the cache
1176
1177 · hash sums of the include files at the time the compilation results
1178 were stored in the cache
1179
1180 The current contents of the include files are then hashed and compared
1181 to the information in the manifest. If there is a match, ccache knows
1182 the result of the compilation. If there is no match, ccache falls back
1183 to running the preprocessor. The output from the preprocessor is parsed
1184 to find the include files that were read. The paths and hash sums of
1185 those include files are then stored in the manifest along with
1186 information about the produced compilation result.
1187
1188 There is a catch with the direct mode: header files that were used by
1189 the compiler are recorded, but header files that were not used, but
1190 would have been used if they existed, are not. So, when ccache checks
1191 if a result can be taken from the cache, it currently can’t check if
1192 the existence of a new header file should invalidate the result. In
1193 practice, the direct mode is safe to use in the absolute majority of
1194 cases.
1195
1196 The direct mode will be disabled if any of the following holds:
1197
1198 · direct_mode is false
1199
1200 · a modification time of one of the include files is too new (needed
1201 to avoid a race condition)
1202
1203 · a compiler option not supported by the direct mode is used:
1204
1205 · a -Wp,X compiler option other than -Wp,-MD,path, -Wp,-MMD,path
1206 and -Wp,-D_define_
1207
1208 · -Xpreprocessor
1209
1210 · the string __TIME__ is present in the source code
1211
1212 The depend mode
1213 If the depend mode is enabled, ccache will not use the preprocessor at
1214 all. The hash used to identify results in the cache will be based on
1215 the direct mode hash described above plus information about include
1216 files read from the dependency file generated by the compiler with -MD
1217 or -MMD.
1218
1219 Advantages:
1220
1221 · The ccache overhead of a cache miss will be much smaller.
1222
1223 · Not running the preprocessor at all can be good if compilation is
1224 performed remotely, for instance when using distcc or similar;
1225 ccache then won’t make potentially costly preprocessor calls on the
1226 local machine.
1227
1228 Disadvantages:
1229
1230 · The cache hit rate will likely be lower since any change to
1231 compiler options or source code will make the hash different.
1232 Compare this with the default setup where ccache will fall back to
1233 the preprocessor mode, which is tolerant to some types of changes
1234 of compiler options and source code changes.
1235
1236 · If -MD is used, the manifest entries will include system header
1237 files as well, thus slowing down cache hits slightly, just as using
1238 -MD slows down make.
1239
1240 · If -MMD is used, the manifest entries will not include system
1241 header files, which means ccache will ignore changes in them.
1242
1243 The depend mode will be disabled if any of the following holds:
1244
1245 · depend_mode is false.
1246
1247 · run_second_cpp is false.
1248
1249 · The compiler is not generating dependencies using -MD or -MMD.
1250
1252 If modification time (mtime) or status change time (ctime) of one of
1253 the include files is the same second as the time compilation is being
1254 done, ccache disables the direct mode (or, in the case of a precompiled
1255 header, disables caching completely). This done as a safety measure to
1256 avoid a race condition (see below).
1257
1258 To be able to use a newly created header files in direct mode (or use a
1259 newly precompiled header), either:
1260
1261 · create the include file earlier in the build process, or
1262
1263 · set sloppiness to include_file_ctime,include_file_mtime if you are
1264 willing to take the risk, for instance if you know that your build
1265 system is robust enough not to trigger the race condition.
1266
1267 For reference, the race condition mentioned above consists of these
1268 events:
1269
1270 1. The preprocessor is run.
1271
1272 2. An include file is modified by someone.
1273
1274 3. The new include file is hashed by ccache.
1275
1276 4. The real compiler is run on the preprocessor’s output, which
1277 contains data from the old header file.
1278
1279 5. The wrong object file is stored in the cache.
1280
1282 To find out what information ccache actually is hashing, you can enable
1283 the debug mode via the configuration option debug or by setting
1284 CCACHE_DEBUG in the environment. This can be useful if you are
1285 investigating why you don’t get cache hits. Note that performance will
1286 be reduced slightly.
1287
1288 When the debug mode is enabled, ccache will create up to five
1289 additional files next to the object file:
1290
1291 ┌───────────────────────────────┬───────────────────────────┐
1292 │Filename │ Description │
1293 ├───────────────────────────────┼───────────────────────────┤
1294 │ │ │
1295 │<objectfile>.ccache-input-c │ Binary input hashed by │
1296 │ │ both the direct mode and │
1297 │ │ the preprocessor mode. │
1298 ├───────────────────────────────┼───────────────────────────┤
1299 │ │ │
1300 │<objectfile>.ccache-input-d │ Binary input only hashed │
1301 │ │ by the direct mode. │
1302 ├───────────────────────────────┼───────────────────────────┤
1303 │ │ │
1304 │<objectfile>.ccache-input-p │ Binary input only hashed │
1305 │ │ by the preprocessor mode. │
1306 ├───────────────────────────────┼───────────────────────────┤
1307 │ │ │
1308 │<objectfile>.ccache-input-text │ Human-readable combined │
1309 │ │ diffable text version of │
1310 │ │ the three files above. │
1311 ├───────────────────────────────┼───────────────────────────┤
1312 │ │ │
1313 │<objectfile>.ccache-log │ Log for this object file. │
1314 └───────────────────────────────┴───────────────────────────┘
1315
1316 If config_dir (environment variable CCACHE_DEBUGDIR) is set, the files
1317 above will be written to that directory with full absolute paths
1318 instead of next to the object file.
1319
1320 In the direct mode, ccache uses the 160 bit BLAKE3 hash of the
1321 ccache-input-c + ccache-input-d data (where + means concatenation),
1322 while the ccache-input-c + ccache-input-p data is used in the
1323 preprocessor mode.
1324
1325 The ccache-input-text file is a combined text version of the three
1326 binary input files. It has three sections (“COMMON”, “DIRECT MODE” and
1327 “PREPROCESSOR MODE”), which is turn contain annotations that say what
1328 kind of data comes next.
1329
1330 To debug why you don’t get an expected cache hit for an object file,
1331 you can do something like this:
1332
1333 1. Build with debug mode enabled.
1334
1335 2. Save the <objectfile>.ccache-* files.
1336
1337 3. Build again with debug mode enabled.
1338
1339 4. Compare <objectfile>.ccache-input-text for the two builds. This
1340 together with the <objectfile>.ccache-log files should give you
1341 some clues about what is happening.
1342
1344 Some information included in the hash that identifies a unique
1345 compilation can contain absolute paths:
1346
1347 · The preprocessed source code may contain absolute paths to include
1348 files if the compiler option -g is used or if absolute paths are
1349 given to -I and similar compiler options.
1350
1351 · Paths specified by compiler options (such as -I, -MF, etc) on the
1352 command line may be absolute.
1353
1354 · The source code file path may be absolute, and that path may
1355 substituted for __FILE__ macros in the source code or included in
1356 warnings emitted to standard error by the preprocessor.
1357
1358 This means that if you compile the same code in different locations,
1359 you can’t share compilation results between the different build
1360 directories since you get cache misses because of the absolute build
1361 directory paths that are part of the hash.
1362
1363 Here’s what can be done to enable cache hits between different build
1364 directories:
1365
1366 · If you build with -g (or similar) to add debug information to the
1367 object file, you must either:
1368
1369 · use the compiler option -fdebug-prefix-map=old=new for
1370 relocating debug info to a common prefix (e.g.
1371 -fdebug-prefix-map=$PWD=.); or
1372
1373 · set hash_dir = false.
1374
1375 · If you use absolute paths anywhere on the command line (e.g. the
1376 source code file path or an argument to compiler options like -I
1377 and -MF), you must set base_dir to an absolute path to a “base
1378 directory”. Ccache will then rewrite absolute paths under that
1379 directory to relative before computing the hash.
1380
1382 Ccache has support for GCC’s precompiled headers. However, you have to
1383 do some things to make it work properly:
1384
1385 · You must set sloppiness to pch_defines,time_macros. The reason is
1386 that ccache can’t tell whether __TIME__, __DATE__ or __TIMESTAMP__
1387 is used when using a precompiled header. Further, it can’t detect
1388 changes in #defines in the source code because of how preprocessing
1389 works in combination with precompiled headers.
1390
1391 · You may also want to include include_file_mtime,include_file_ctime
1392 in sloppiness. See Handling of newly created header files.
1393
1394 · You must either:
1395
1396 · use the compiler option -include to include the precompiled
1397 header (i.e., don’t use #include in the source code to include
1398 the header; the filename itself must be sufficient to find the
1399 header, i.e. -I paths are not searched); or
1400
1401 · (for the Clang compiler) use the compiler option -include-pch
1402 to include the PCH file generated from the precompiled header;
1403 or
1404
1405 · (for the GCC compiler) add the compiler option -fpch-preprocess
1406 when compiling.
1407
1408 If you don’t do this, either the non-precompiled version of the
1409 header file will be used (if available) or ccache will fall back to
1410 running the real compiler and increase the statistics counter
1411 “preprocessor error” (if the non-precompiled header file is not
1412 available).
1413
1415 Ccache has support for Clang’s -fmodules option. In practice ccache
1416 only additionally hashes module.modulemap files; it does not know how
1417 Clang handles its cached binary form of modules so those are ignored.
1418 This should not matter in practice: as long as everything else
1419 (including module.modulemap files) is the same the cached result should
1420 work. Still, you must set sloppiness to modules to allow caching.
1421
1422 You must use both direct mode and depend mode. When using the
1423 preprocessor mode Clang does not provide enough information to allow
1424 hashing of module.modulemap files.
1425
1427 A group of developers can increase the cache hit rate by sharing a
1428 cache directory. To share a cache without unpleasant side effects, the
1429 following conditions should to be met:
1430
1431 · Use the same cache directory.
1432
1433 · Make sure that the configuration option hard_link is false (which
1434 is the default).
1435
1436 · Make sure that all users are in the same group.
1437
1438 · Set the configuration option umask to 002. This ensures that cached
1439 files are accessible to everyone in the group.
1440
1441 · Make sure that all users have write permission in the entire cache
1442 directory (and that you trust all users of the shared cache).
1443
1444 · Make sure that the setgid bit is set on all directories in the
1445 cache. This tells the filesystem to inherit group ownership for new
1446 directories. The following command might be useful for this:
1447
1448 find $CCACHE_DIR -type d | xargs chmod g+s
1449
1450 The reason to avoid the hard link mode is that the hard links cause
1451 unwanted side effects, as all links to a cached file share the file’s
1452 modification timestamp. This results in false dependencies to be
1453 triggered by timestamp-based build systems whenever another user links
1454 to an existing file. Typically, users will see that their libraries and
1455 binaries are relinked without reason.
1456
1457 You may also want to make sure that a base directory is set
1458 appropriately, as discussed in a previous section.
1459
1461 It is possible to put the cache directory on an NFS filesystem (or
1462 similar filesystems), but keep in mind that:
1463
1464 · Having the cache on NFS may slow down compilation. Make sure to do
1465 some benchmarking to see if it’s worth it.
1466
1467 · Ccache hasn’t been tested very thoroughly on NFS.
1468
1469 A tip is to set temporary_dir to a directory on the local host to avoid
1470 NFS traffic for temporary files.
1471
1472 It is recommended to use the same operating system version when using a
1473 shared cache. If operating system versions are different then system
1474 include files will likely be different and there will be few or no
1475 cache hits between the systems. One way of improving cache hit rate in
1476 that case is to set sloppiness to system_headers to ignore system
1477 headers.
1478
1480 The recommended way of combining ccache with another compiler wrapper
1481 (such as “distcc”) is by letting ccache execute the compiler wrapper.
1482 This is accomplished by defining prefix_command, for example by setting
1483 the environment variable CCACHE_PREFIX to the name of the wrapper (e.g.
1484 distcc). Ccache will then prefix the command line with the specified
1485 command when running the compiler. To specify several prefix commands,
1486 set prefix_command to a colon-separated list of commands.
1487
1488 Unless you set compiler_check to a suitable command (see the
1489 description of that configuration option), it is not recommended to use
1490 the form ccache anotherwrapper compiler args as the compilation
1491 command. It’s also not recommended to use the masquerading technique
1492 for the other compiler wrapper. The reason is that by default, ccache
1493 will in both cases hash the mtime and size of the other wrapper instead
1494 of the real compiler, which means that:
1495
1496 · Compiler upgrades will not be detected properly.
1497
1498 · The cached results will not be shared between compilations with and
1499 without the other wrapper.
1500
1501 Another minor thing is that if prefix_command is used, ccache will not
1502 invoke the other wrapper when running the preprocessor, which increases
1503 performance. You can use prefix_command_cpp if you also want to invoke
1504 the other wrapper when doing preprocessing (normally by adding -E).
1505
1507 · The direct mode fails to pick up new header files in some rare
1508 scenarios. See The direct mode above.
1509
1511 General
1512 A general tip for getting information about what ccache is doing is to
1513 enable debug logging by setting the configuration option debug (or the
1514 environment variable CCACHE_DEBUG); see Cache debugging for more
1515 information. Another way of keeping track of what is happening is to
1516 check the output of ccache -s.
1517
1518 Performance
1519 Ccache has been written to perform well out of the box, but sometimes
1520 you may have to do some adjustments of how you use the compiler and
1521 ccache in order to improve performance.
1522
1523 Since ccache works best when I/O is fast, put the cache directory on a
1524 fast storage device if possible. Having lots of free memory so that
1525 files in the cache directory stay in the disk cache is also preferable.
1526
1527 A good way of monitoring how well ccache works is to run ccache -s
1528 before and after your build and then compare the statistics counters.
1529 Here are some common problems and what may be done to increase the hit
1530 rate:
1531
1532 · If “cache hit (preprocessed)” has been incremented instead of
1533 “cache hit (direct)”, ccache has fallen back to preprocessor mode,
1534 which is generally slower. Some possible reasons are:
1535
1536 · The source code has been modified in such a way that the
1537 preprocessor output is not affected.
1538
1539 · Compiler arguments that are hashed in the direct mode but not
1540 in the preprocessor mode have changed (-I, -include, -D, etc)
1541 and they didn’t affect the preprocessor output.
1542
1543 · The compiler option -Xpreprocessor or -Wp,X (except
1544 -Wp,-MD,path, -Wp,-MMD,path, and -Wp,-D_define_) is used.
1545
1546 · This was the first compilation with a new value of the base
1547 directory.
1548
1549 · A modification or status change time of one of the include
1550 files is too new (created the same second as the compilation is
1551 being done). See Handling of newly created header files.
1552
1553 · The __TIME__ preprocessor macro is (potentially) being used.
1554 Ccache turns off direct mode if __TIME__ is present in the
1555 source code. This is done as a safety measure since the string
1556 indicates that a __TIME__ macro may affect the output. (To be
1557 sure, ccache would have to run the preprocessor, but the sole
1558 point of the direct mode is to avoid that.) If you know that
1559 __TIME__ isn’t used in practise, or don’t care if ccache
1560 produces objects where __TIME__ is expanded to something in the
1561 past, you can set sloppiness to time_macros.
1562
1563 · The __DATE__ preprocessor macro is (potentially) being used and
1564 the date has changed. This is similar to how __TIME__ is
1565 handled. If __DATE__ is present in the source code, ccache
1566 hashes the current date in order to be able to produce the
1567 correct object file if the __DATE__ macro affects the output.
1568 If you know that __DATE__ isn’t used in practise, or don’t care
1569 if ccache produces objects where __DATE__ is expanded to
1570 something in the past, you can set sloppiness to time_macros.
1571
1572 · The __TIMESTAMP__ preprocessor macro is (potentially) being
1573 used and the source file’s modification time has changed. This
1574 is similar to how __TIME__ is handled. If __TIMESTAMP__ is
1575 present in the source code, ccache hashes the string
1576 representation of the source file’s modification time in order
1577 to be able to produce the correct object file if the
1578 __TIMESTAMP__ macro affects the output. If you know that
1579 __TIMESTAMP__ isn’t used in practise, or don’t care if ccache
1580 produces objects where __TIMESTAMP__ is expanded to something
1581 in the past, you can set sloppiness to time_macros.
1582
1583 · The input file path has changed. Ccache includes the input file
1584 path in the direct mode hash to be able to take relative
1585 include files into account and to produce a correct object file
1586 if the source code includes a __FILE__ macro.
1587
1588 · If “cache miss” has been incremented even though the same code has
1589 been compiled and cached before, ccache has either detected that
1590 something has changed anyway or a cleanup has been performed
1591 (either explicitly or implicitly when a cache limit has been
1592 reached). Some perhaps unobvious things that may result in a cache
1593 miss are usage of __TIME__, __DATE__ or __TIMESTAMP__ macros, or
1594 use of automatically generated code that contains a timestamp,
1595 build counter or other volatile information.
1596
1597 · If “multiple source files” has been incremented, it’s an indication
1598 that the compiler has been invoked on several source code files at
1599 once. Ccache doesn’t support that. Compile the source code files
1600 separately if possible.
1601
1602 · If “unsupported compiler option” has been incremented, enable debug
1603 logging and check which compiler option was rejected.
1604
1605 · If “preprocessor error” has been incremented, one possible reason
1606 is that precompiled headers are being used. See Precompiled headers
1607 for how to remedy this.
1608
1609 · If “can’t use precompiled header” has been incremented, see
1610 Precompiled headers.
1611
1612 · If “can’t use modules” has been incremented, see C++ modules.
1613
1614 Corrupt object files
1615 It should be noted that ccache is susceptible to general storage
1616 problems. If a bad object file sneaks into the cache for some reason,
1617 it will of course stay bad. Some possible reasons for erroneous object
1618 files are bad hardware (disk drive, disk controller, memory, etc),
1619 buggy drivers or file systems, a bad prefix_command or compiler
1620 wrapper. If this happens, the easiest way of fixing it is this:
1621
1622 1. Build so that the bad object file ends up in the build tree.
1623
1624 2. Remove the bad object file from the build tree.
1625
1626 3. Rebuild with CCACHE_RECACHE set.
1627
1628 An alternative is to clear the whole cache with ccache -C if you don’t
1629 mind losing other cached results.
1630
1631 There are no reported issues about ccache producing broken object files
1632 reproducibly. That doesn’t mean it can’t happen, so if you find a
1633 repeatable case, please report it.
1634
1636 Credits, mailing list information, bug reporting instructions, source
1637 code, etc, can be found on ccache’s web site: https://ccache.dev.
1638
1640 Ccache was originally written by Andrew Tridgell and is currently
1641 developed and maintained by Joel Rosdahl. See AUTHORS.txt or
1642 AUTHORS.html and https://ccache.dev/credits.html for a list of
1643 contributors.
1644
1645
1646
1647ccache 4.2 02/03/2021 CCACHE(1)