#632779 cc and c++ symlinks aren't updated when installing gcc or g++ after ccache

Package:
ccache
Source:
ccache
Description:
Compiler cache for fast recompilation of C/C++ code
Submitter:
José Manuel Santamaría Lema
Date:
2024-02-04 13:27:05 UTC
Severity:
normal
Tags:
#632779#5
Date:
2011-07-05 22:23:16 UTC
From:
To:
Hello,

when I install gcc/g++ before ccache the symlinks to /usr/bin/cc and
/usr/bin/c++ aren't updated. This is what happens (see below what's wrong) in
a clean chroot:

root@nemesis:/# apt-get install ccache
[snip]
Setting up ccache (3.1.5-2) ...
Updating symlinks in /usr/lib/ccache ...

root@nemesis:/# apt-get install gcc g++
[snip]
Selecting previously deselected package gcc.
Unpacking gcc (from .../gcc_4%3a4.6.0-6_amd64.deb) ...
[snip]
Selecting previously deselected package g++-4.6.
Unpacking g++-4.6 (from .../g++-4.6_4.6.1-1_amd64.deb) ...
Selecting previously deselected package g++.
Unpacking g++ (from .../g++_4%3a4.6.0-6_amd64.deb) ...
[snip]
Processing triggers for ccache ...
Updating symlinks in /usr/lib/ccache ...
[snip]
Setting up gcc (4:4.6.0-6) ...
[snip]
Setting up g++ (4:4.6.0-6) ...
update-alternatives: using /usr/bin/g++ to provide /usr/bin/c++ (c++) in auto
mode.

root@nemesis:/# ls -la /usr/lib/ccache/
total 8
drwxr-xr-x  2 root root 4096 Jul  5 20:34 .
drwxr-xr-x 25 root root 4096 Jul  5 20:34 ..
lrwxrwxrwx  1 root root   16 Jul  5 20:34 c89-gcc -> ../../bin/ccache
lrwxrwxrwx  1 root root   16 Jul  5 20:34 c99-gcc -> ../../bin/ccache
lrwxrwxrwx  1 root root   16 Jul  5 20:34 g++ -> ../../bin/ccache
lrwxrwxrwx  1 root root   16 Jul  5 20:34 g++-4.6 -> ../../bin/ccache
lrwxrwxrwx  1 root root   16 Jul  5 20:34 gcc -> ../../bin/ccache
lrwxrwxrwx  1 root root   16 Jul  5 20:34 gcc-4.6 -> ../../bin/ccache
lrwxrwxrwx  1 root root   16 Jul  5 20:34 x86_64-linux-gnu-g++ ->
../../bin/ccache
lrwxrwxrwx  1 root root   16 Jul  5 20:34 x86_64-linux-gnu-g++-4.6 ->
../../bin/ccache
lrwxrwxrwx  1 root root   16 Jul  5 20:34 x86_64-linux-gnu-gcc ->
../../bin/ccache
lrwxrwxrwx  1 root root   16 Jul  5 20:34 x86_64-linux-gnu-gcc-4.6 ->
../../bin/ccache
root@nemesis:/# update-ccache-symlinks
root@nemesis:/# ls -la /usr/lib/ccache/
total 8
drwxr-xr-x  2 root root 4096 Jul  5 20:36 .
drwxr-xr-x 25 root root 4096 Jul  5 20:34 ..
lrwxrwxrwx  1 root root   16 Jul  5 20:36 c++ -> ../../bin/ccache
lrwxrwxrwx  1 root root   16 Jul  5 20:34 c89-gcc -> ../../bin/ccache
lrwxrwxrwx  1 root root   16 Jul  5 20:34 c99-gcc -> ../../bin/ccache
lrwxrwxrwx  1 root root   16 Jul  5 20:36 cc -> ../../bin/ccache
lrwxrwxrwx  1 root root   16 Jul  5 20:34 g++ -> ../../bin/ccache
lrwxrwxrwx  1 root root   16 Jul  5 20:34 g++-4.6 -> ../../bin/ccache
lrwxrwxrwx  1 root root   16 Jul  5 20:34 gcc -> ../../bin/ccache
lrwxrwxrwx  1 root root   16 Jul  5 20:34 gcc-4.6 -> ../../bin/ccache
lrwxrwxrwx  1 root root   16 Jul  5 20:34 x86_64-linux-gnu-g++ ->
../../bin/ccache
lrwxrwxrwx  1 root root   16 Jul  5 20:34 x86_64-linux-gnu-g++-4.6 ->
../../bin/ccache
lrwxrwxrwx  1 root root   16 Jul  5 20:34 x86_64-linux-gnu-gcc ->
../../bin/ccache
lrwxrwxrwx  1 root root   16 Jul  5 20:34 x86_64-linux-gnu-gcc-4.6 ->
../../bin/ccache


As you can see in the first ls, both cc and c++ symlinks are missing in
/usr/lib/ccache/.

The problem is the following: both /usr/bin/cc and /usr/bin/c++ are
alternatives installed while executing gcc and g++ postinst scripts
respectively. The dpkg triggers for ccache are activated in the gcc/g++
configuring stage, before /usr/bin/cc and /usr/bin/c++ exist in the hard
disk, therefore they aren't considered by update-ccache-symlinks.

How to solve it? The first thing I tought was that adding a couple of file
triggers for /usr/bin/cc and /usr/bin/c++ to ccache would do the trick, but
unfortunately there's a problem with this; quoting from "File triggers"
section of /usr/share/doc/dpkg-dev/triggers.txt.gz

So file triggers can't be activated in the postinst, only during upack or
removal. Therefore the solution is making the triggers explicit, calling
them from some maintainer scripts in gcc-defaults. I'm attaching a
couple of patches implementing this solution.

So ... if the gcc maintainers accept the gcc-defaults patch, would you
accept the ccache one? If yes, I would open a new bug report against
src:gcc-defaults with the patch and mark this one as blocked. A reply just
saying "go ahead" is enough, thanks for your time.

#632779#12
Date:
2011-07-05 22:40:22 UTC
From:
To:
s/before/after/
#632779#17
Date:
2011-07-06 19:50:10 UTC
From:
To:
Sure, sounds fine to me.
#632779#22
Date:
2012-07-10 06:04:43 UTC
From:
To:
clone 632779 -1
reassign -1 distcc 3.1-5
submitter -1 !
--

Also affects distcc since it uses the same triggers.

#632779#29
Date:
2012-11-09 06:19:54 UTC
From:
To:
José Manuel Santamaría Lema wrote:

Hi José

Any update on this?

Regards

#632779#36
Date:
2017-10-02 09:30:54 UTC
From:
To:
Now it has hit me too and I cannot believe the issue has been known for
almost five years now.

Any viable fix proposal out there?

Regards,
Eduard.

#632779#41
Date:
2022-06-17 17:32:46 UTC
From:
To:
I have found a variant of this bug which is still present in Debian bookworm:
If g++ and ccache are installed at the same time then the c++ link is not
present:

# apt install g++ ccache
...
# ls -l /usr/lib/ccache/c++
ls: cannot access '/usr/lib/ccache/c++': No such file or directory

The link works properly if g++ is installed before ccache:
# apt install g++
...
# apt install ccache
...
# ls -l /usr/lib/ccache/c++
lrwxrwxrwx 1 root root 16 Jun 17 17:29 /usr/lib/ccache/c++ -> ../../bin/ccache

I guess the reason is the same as mentioned in this ticket: c++ is managed by
update-alternatives.
BTW, the same happens with the cc link if gcc and ccache are installed with the
same apt command.