Skip to content

fix: Do not rewrite -isysroot as relative path - #1661

Open
lbonn wants to merge 3 commits into
ccache:masterfrom
lbonn:basedir-pch
Open

lbonn wants to merge 3 commits into
ccache:masterfrom
lbonn:basedir-pch

Conversation

@lbonn

@lbonn lbonn commented Dec 13, 2025

Copy link
Copy Markdown

Here is an attempt to solve #1322 with one of the proposed approaches from the thread.

To reduce risk, I thought about restricting this behavior to invocations with --relocatable-pch but it would probably lead to bigger changes as hash_argument is collecting everything in one pass.

Fixes #1322

@lbonn

lbonn commented Dec 13, 2025

Copy link
Copy Markdown
Author

Ah well removing TAKES_PATH probably broke the WIN32 path conversion, it was indeed suspicious from the start. Maybe adding a new compopt flag would be necessary, I'll have a look.

Comment thread src/ccache/ccache.cpp Fixed
Comment thread src/ccache/argprocessing.cpp Outdated
Comment thread src/ccache/ccache.cpp Outdated
@jrosdahl jrosdahl added issue: bug Does not work as intended/documented compiler: clang Related to Clang labels Dec 21, 2025
@lbonn
lbonn force-pushed the basedir-pch branch 2 times, most recently from 35523da to 4824065 Compare December 22, 2025 11:09
Clang uses the .pch extension by default, but the tests were written
to use the .gch extension.

None of the suite was running with clang due to this issue
@lbonn

lbonn commented Dec 22, 2025

Copy link
Copy Markdown
Author

I've noticed that the pch tests actually did not run at all with clang due to some default extension mix-up (maybe it was updated in a more recent clang version).

Additionally, the 2 parts of the change: do not rewrite -isysroot and cache it as relative with --relocatable-pch; have also been split.

Even with BASEDIR, compilers should not be given a relative -isysroot
directory as argument.

Clang for example just ignores it in this case.
Clang recommends using -isysroot with relocatable-pch but it needs to be
passed as an absolute path.

However, we can use the relative path as a cache key in this case to
actually make a use of the relocatable pch feature.
Comment on lines +1263 to +1264
if (compopt_takes_path_abs(arg)) {
// some paths should not be made relative (eg -isysroot)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not confident that we can ignore rewriting -isysroot unconditionally like this.

Consider this test script:

#!/bin/sh

set -eu

compiler=gcc

rm -rf pr-1661-test
mkdir pr-1661-test
cd pr-1661-test

mkdir -p example/arch1/sysroot/usr/include
touch example/arch1/sysroot/usr/include/h.h
cp -a example/arch1 example/arch2

cat <<EOF >example/arch1/c.c
#include <h.h>
EOF
cp example/arch1/c.c example/arch2

dir=$PWD
export CCACHE_BASEDIR=$dir
export CCACHE_DIR=$dir/ccache
export CCACHE_DEBUG=1

cd example/arch1
ccache $compiler -isysroot $dir/example/arch1/sysroot -c c.c
grep Executing c.o.*ccache-log || true
grep Result: c.o.*ccache-log || true

echo
cd ../..

cd example/arch2
ccache $compiler -isysroot $dir/example/arch2/sysroot -c c.c
grep Executing c.o.*ccache-log || true
grep Result: c.o.*ccache-log || true

Without this PR the second compilation is a cache hit:

[2026-01-19T20:28:11.063512 3688461] Executing /usr/bin/gcc -isysroot sysroot -E -o /run/user/1000/ccache-tmp/cpp_stdout.tmp.oxOKwJ.i c.c
[2026-01-19T20:28:11.067772 3688461] Executing /usr/bin/gcc -isysroot sysroot -fdiagnostics-color -c -o c.o c.c
[2026-01-19T20:28:11.073773 3688461] Result: cache_miss
[2026-01-19T20:28:11.073774 3688461] Result: direct_cache_miss
[2026-01-19T20:28:11.073775 3688461] Result: local_storage_miss
[2026-01-19T20:28:11.073775 3688461] Result: local_storage_read_miss
[2026-01-19T20:28:11.073776 3688461] Result: local_storage_read_miss
[2026-01-19T20:28:11.073776 3688461] Result: local_storage_write
[2026-01-19T20:28:11.073777 3688461] Result: local_storage_write
[2026-01-19T20:28:11.073777 3688461] Result: preprocessed_cache_miss

[2026-01-19T20:28:11.078599 3688469] Result: direct_cache_hit
[2026-01-19T20:28:11.078600 3688469] Result: local_storage_hit
[2026-01-19T20:28:11.078600 3688469] Result: local_storage_read_hit
[2026-01-19T20:28:11.078601 3688469] Result: local_storage_read_hit

But with this PR it's a miss:

[2026-01-19T20:28:18.669134 3688663] Executing /usr/bin/gcc -isysroot /home/joel/[...]/pr-1661-test/example/arch1/sysroot -E -o /run/user/1000/ccache-tmp/cpp_stdout.tmp.8xlFDp.i c.c
[2026-01-19T20:28:18.672752 3688663] Executing /usr/bin/gcc -isysroot /home/joel/[...]/pr-1661-test/example/arch1/sysroot -fdiagnostics-color -c -o c.o c.c
[2026-01-19T20:28:18.679678 3688663] Result: cache_miss
[2026-01-19T20:28:18.679680 3688663] Result: direct_cache_miss
[2026-01-19T20:28:18.679682 3688663] Result: local_storage_miss
[2026-01-19T20:28:18.679683 3688663] Result: local_storage_read_miss
[2026-01-19T20:28:18.679685 3688663] Result: local_storage_read_miss
[2026-01-19T20:28:18.679686 3688663] Result: local_storage_write
[2026-01-19T20:28:18.679687 3688663] Result: local_storage_write
[2026-01-19T20:28:18.679688 3688663] Result: preprocessed_cache_miss

[2026-01-19T20:28:18.684241 3688671] Executing /usr/bin/gcc -isysroot /home/joel/[...]/pr-1661-test/example/arch2/sysroot -E -o /run/user/1000/ccache-tmp/cpp_stdout.tmp.m4Dned.i c.c
[2026-01-19T20:28:18.688607 3688671] Executing /usr/bin/gcc -isysroot /home/joel/[...]/pr-1661-test/example/arch2/sysroot -fdiagnostics-color -c -o c.o c.c
[2026-01-19T20:28:18.702156 3688671] Result: cache_miss
[2026-01-19T20:28:18.702163 3688671] Result: direct_cache_miss
[2026-01-19T20:28:18.702167 3688671] Result: local_storage_miss
[2026-01-19T20:28:18.702170 3688671] Result: local_storage_read_miss
[2026-01-19T20:28:18.702174 3688671] Result: local_storage_read_miss
[2026-01-19T20:28:18.702177 3688671] Result: local_storage_write
[2026-01-19T20:28:18.702180 3688671] Result: local_storage_write
[2026-01-19T20:28:18.702183 3688671] Result: preprocessed_cache_miss

@jrosdahl jrosdahl added type: bug fix PR fixes a bug and removed issue: bug Does not work as intended/documented labels Jan 30, 2026
@jrosdahl jrosdahl added the status: awaiting feedback Waiting for response from issue/PR author label Sep 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

compiler: clang Related to Clang status: awaiting feedback Waiting for response from issue/PR author type: bug fix PR fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

base_dir does not play well with Clang relocatable PCH

3 participants