https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107059
--- Comment #26 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
(In reply to Tobias Burnus from comment #23)
> Regarding the $BUILD/gcc/include-fixed and xgcc -B $BUILD/gcc:
>
> In gcc.cc's driver_handle_option:
>
> add_prefix (&include_prefixes, arg, NULL,
> PREFIX_PRIORITY_B_OPT, 0, 0);
> Adds "$BUILD/gcc/" to the prefix list in include_prefix.plist (priority =
> PREFIX_PRIORITY_B_OPT, require_machine_suffix = os_multilib = 0)
> the include_prefixes.name is "include".
>
> This is later processed in do_spec_1 as:
> info.option = "-isystem";
> info.append = "include";
> ...
> for_each_path (&include_prefixes, false, info.append_len,
> spec_path, &info);
> ...
> info.append = "include-fixed";
> for_each_path (&include_prefixes, false, info.append_len,
> spec_path, &info);
> which in turn runs with (<prefix> = "$BUILD/gcc/"):
>
> <prefix>/x86_64-pc-linux-gnu/13.0.0/
> <prefix>/x86_64-linux-gnu/
> <prefix>
>
> It also sets -iprefix $BUILD/gcc/../lib/gcc/x86_64-pc-linux-gnu/13.0.0/
> -isystem $BUILD/gcc/{include,include-fixed}
Well, the upper directories to include/include-fixed should stay as they are,
that is how to find the include-fixed directory.
But for multi-arch we need to search both include-fixed/<multiarch_dir>
and include-fixed, so I think we need in addition to the comment 14 patch
also (completely untested):
--- gcc/gcc.cc 2022-09-23 09:02:56.809314447 +0200
+++ gcc/gcc.cc 2022-09-28 21:02:29.751933657 +0200
@@ -6400,6 +6400,18 @@ do_spec_1 (const char *spec, int inswitc
if (*sysroot_hdrs_suffix_spec)
info.append = concat (info.append, dir_separator_str,
multilib_dir, NULL);
+ else if (multiarch_dir)
+ {
+ /* For multiarch, search include-fixed/<multiarch-dir>
+ before include-fixed. */
+ info.append = concat (info.append, dir_separator_str,
+ multiarch_dir, NULL);
+ info.append_len = strlen (info.append);
+ for_each_path (&include_prefixes, false, info.append_len,
+ spec_path, &info);
+
+ info.append = "include-fixed";
+ }
info.append_len = strlen (info.append);
for_each_path (&include_prefixes, false, info.append_len,
spec_path, &info);
It is roughly what the comment 14 patch does, just in a different spot.