]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c-family: Don't register include paths with -fpreprocessed master trunk
authorKito Cheng <kito.cheng@sifive.com>
Mon, 24 Nov 2025 07:00:07 +0000 (15:00 +0800)
committerKito Cheng <kito.cheng@sifive.com>
Tue, 25 Nov 2025 03:39:08 +0000 (11:39 +0800)
This fixes a permission error that occurs when cross-compiling with
-save-temps and a relocated toolchain, where the original build path
exists but is inaccessible.

The issue occurs when:
- Building the toolchain at /home/scratch/build/
- Installing it to another location like /home/user/rv64-toolchain/
- The /home/scratch directory exists but has insufficient permissions
  (e.g. drwx------ for /home/scratch/)

Without this fix, cc1 would report errors like:
cc1: error: /home/scratch/build/install/riscv64-unknown-elf/usr/local/include: Permission denied

This occurred because the GCC driver did not pass GCC_EXEC_PREFIX and
isysroot to cc1/cc1plus in the compile stage when using -save-temps.
This caused cc1/cc1plus to search for headers from the wrong (original
build) path instead of the relocated installation path.

The fix ensures cc1/cc1plus won't try to collect include paths when
-fpreprocessed is specified.  This prevents the permission error during
cross-compilation with -save-temps, as the preprocessed file already
contains all necessary headers.

gcc/c-family/ChangeLog:

* c-opts.cc (c_common_post_options): Skip register_include_chains
when cpp_opts->preprocessed is set.

gcc/c-family/c-opts.cc

index cb836b26a5ce9bc01df805f5bc09ab549a64af62..1e0f0c59ade0ab846d202b49d156884d184ed33b 100644 (file)
@@ -864,8 +864,12 @@ c_common_post_options (const char **pfilename)
 
   sanitize_cpp_opts ();
 
-  register_include_chains (parse_in, sysroot, iprefix, imultilib,
-                          std_inc, std_cxx_inc && c_dialect_cxx (), verbose);
+  /* Don't register include chains if under -fpreprocessed since we might not
+     have correct sysroot this mode, and this may cause file permssion
+     issue.  */
+  if (!cpp_opts->preprocessed)
+    register_include_chains (parse_in, sysroot, iprefix, imultilib,
+                            std_inc, std_cxx_inc && c_dialect_cxx (), verbose);
 
 #ifdef C_COMMON_OVERRIDE_OPTIONS
   /* Some machines may reject certain combinations of C