https://gcc.gnu.org/g:994844d82f8e47a2139ef5f9b0014c3822c01225

commit r16-5568-g994844d82f8e47a2139ef5f9b0014c3822c01225
Author: Kito Cheng <[email protected]>
Date:   Mon Nov 24 15:00:07 2025 +0800

    c-family: Don't register include paths with -fpreprocessed
    
    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.

Diff:
---
 gcc/c-family/c-opts.cc | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/gcc/c-family/c-opts.cc b/gcc/c-family/c-opts.cc
index cb836b26a5ce..1e0f0c59ade0 100644
--- a/gcc/c-family/c-opts.cc
+++ b/gcc/c-family/c-opts.cc
@@ -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

Reply via email to