Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does ccache mean by "called for link"

Tags:

c

caching

ccache

What is meant by the ccache statistic "called for link". I thought ccache only wrapped the compiler, not the linker?

[Brian@localhost ~]$ ccache -s
cache directory                     /home/Brian/.ccache
cache hit (direct)                 19813
cache hit (preprocessed)              67
cache miss                            11
called for link                      498
called for preprocessing              10
unsupported source language          472
no input file                         12
files in cache                    258568
cache size                          33.8 Gbytes
max cache size                     100.0 Gbytes
like image 805
Brian J Murray Avatar asked Apr 23 '15 15:04

Brian J Murray


2 Answers

ccache indeed does not support linking.

It does replace the C compiler (the C compiler driver, more specifically), however (look where and how it's installed and used). Because of that, it needs to "pass through" any commands it receives and does not handle/modify itself to the respective parts of the toolchain.

like image 53
mfro Avatar answered Sep 27 '22 21:09

mfro


Reading the release notes was not very clear to me either:

The statistics counter “called for link” is now correctly updated when linking with a single object file.

But it means you are doing compilation & linking in a single operation so there is no way ccache can supply the result transparently.

Demo with a basic hello.c program. First lets clear everything:

$ ccache -Czs
Cleared cache
Statistics cleared
cache directory                     /home/jdg/.ccache
cache hit (direct)                     0
cache hit (preprocessed)               0
cache miss                             0
files in cache                         0

Doing a compile and link in one step (twice, just to be sure):

$ ccache g++ hello.c
$ ccache g++ hello.c
$ ccache -s
cache hit (direct)                     0
cache hit (preprocessed)               0
cache miss                             0
called for link                        2
files in cache                         0

Nothing is cached, because ccache just can't

Doing it in two separate steps (also twice):

$ ccache g++ -c hello.c ; g++ hello.o
$ ccache g++ -c hello.c ; g++ hello.o
$ ccache -s
cache hit (direct)                     1
cache hit (preprocessed)               0
cache miss                             1
called for link                        4
no input file                          2
files in cache                         2

Now it worked:

  • First compilation made a cache miss, and stored the results (two files: manifest plus .o)
  • Second made a cache hit
  • g++ was called for link 4 times total, including 2 times with no source but only .o

And the called for preprocessing stuff ? Simple, you just used your compiler to expand all the include/define stuff (eg. when looking for dependency)

$ g++ -E hello.c
$ g++ -M hello.c
$ ccache -s
cache hit (direct)                     1
cache hit (preprocessed)               0
cache miss                             1
called for link                        4
called for preprocessing               2
unsupported compiler option            1
no input file                          2
files in cache                         2

Hope this helps !

like image 33
JeanDo Avatar answered Sep 27 '22 23:09

JeanDo