commit:     c088e880493faa16c2684fced43a2eb4cb67fe23
Author:     James Le Cuirot <chewi <AT> gentoo <DOT> org>
AuthorDate: Sat Jan  4 21:49:18 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Fri Feb  7 21:18:50 2025 +0000
URL:        https://gitweb.gentoo.org/proj/gcc-patches.git/commit/?id=c088e880

15.0.0: Update esysroot patch to fix prefix and Canadian Cross issues

Closes: https://bugs.gentoo.org/942672
Signed-off-by: James Le Cuirot <chewi <AT> gentoo.org>
Closes: https://github.com/gentoo/gcc-patches/pull/7
Signed-off-by: Sam James <sam <AT> gentoo.org>

 15.0.0/gentoo/09_all_esysroot.patch | 77 ++++++++++++++++++++++++-------------
 15.0.0/gentoo/README.history        |  6 ++-
 2 files changed, 56 insertions(+), 27 deletions(-)

diff --git a/15.0.0/gentoo/09_all_esysroot.patch 
b/15.0.0/gentoo/09_all_esysroot.patch
index 80e0561..85a4b5e 100644
--- a/15.0.0/gentoo/09_all_esysroot.patch
+++ b/15.0.0/gentoo/09_all_esysroot.patch
@@ -1,67 +1,92 @@
-From 71e048084d32811f6e17e73b6ebadfe550ef1193 Mon Sep 17 00:00:00 2001
+From c012b20eca546ec60878058094e59267ebfba1a9 Mon Sep 17 00:00:00 2001
 From: James Le Cuirot <[email protected]>
-Date: Sun, 4 Aug 2024 17:02:06 +0100
-Subject: [PATCH] Allow setting target sysroot with ESYSROOT env var for
+Date: Mon, 23 Dec 2024 16:50:25 +0000
+Subject: [PATCH 3/3] Allow setting target sysroot with ESYSROOT env var for
  cross-compilers
 
-The variable is ignored for native compilers. The --sysroot command line
-option takes precedence.
+The variable is ignored for native compilers, when it matches BROOT, and
+when the target machine does not match CHOST (if set). The --sysroot
+command line option takes precedence.
+
+The CHOST check is necessary for a Canadian Cross. In that case, two
+cross-compilers are invoked, but only the one matching CHOST should have
+its sysroot set by ESYSROOT.
 
 Signed-off-by: James Le Cuirot <[email protected]>
 ---
- gcc/doc/invoke.texi | 10 ++++++++++
- gcc/gcc.cc          | 10 ++++++++++
- 2 files changed, 20 insertions(+)
+ gcc/doc/invoke.texi | 11 +++++++++++
+ gcc/gcc.cc          | 29 +++++++++++++++++++++++++++++
+ 2 files changed, 40 insertions(+)
 
 diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
-index 0fe99ca8e..434cf30e2 100644
+index 0a7a81b20..d66f53b65 100644
 --- a/gcc/doc/invoke.texi
 +++ b/gcc/doc/invoke.texi
-@@ -19230,6 +19230,10 @@ for this option.  If your linker does not support 
this option, the
+@@ -19355,6 +19355,10 @@ for this option.  If your linker does not support 
this option, the
  header file aspect of @option{--sysroot} still works, but the
  library aspect does not.
  
 +On Gentoo Linux, this option can also be set for cross-compilers using the
-+@env{ESYSROOT} environmnent variable.  The variable is ignored for native
-+compilers.  The command line option takes precedence.
++@env{ESYSROOT} environmnent variable.  The command line option takes
++precedence.
 +
  @opindex no-sysroot-suffix
  @item --no-sysroot-suffix
  For some targets, a suffix is added to the root directory specified
-@@ -37657,6 +37661,12 @@ using GCC also uses these directories when searching 
for ordinary
+@@ -37590,6 +37594,13 @@ using GCC also uses these directories when searching 
for ordinary
  libraries for the @option{-l} option (but directories specified with
  @option{-L} come first).
  
 +@vindex ESYSROOT
 +@item ESYSROOT
 +On Gentoo Linux, this variable sets the logical root directory for headers and
-+libraries for cross-compilers.  It is ignored for native compilers.  The
-+@option{--sysroot} option takes precedence.
++libraries for cross-compilers.  It is ignored for native compilers, when it
++matches @env{BROOT}, and when the target machine does not match @env{CHOST}
++(if set).  The @option{--sysroot} option takes precedence.
 +
  @vindex LANG
  @cindex locale definition
  @item LANG
 diff --git a/gcc/gcc.cc b/gcc/gcc.cc
-index abdb40bfe..956363ddb 100644
+index 4188f0049..e88c7067f 100644
 --- a/gcc/gcc.cc
 +++ b/gcc/gcc.cc
-@@ -5516,6 +5516,16 @@ process_command (unsigned int decoded_options_count,
-             "BINUTILS", PREFIX_PRIORITY_LAST, 0, 1);
-   free (tooldir_prefix);
+@@ -5486,6 +5486,35 @@ process_command (unsigned int decoded_options_count,
+       gcc_assert (!compare_debug_opt);
+     }
  
 +  if (*cross_compile == '1' && !target_system_root_changed)
 +    {
 +      const char *esysroot = env.get("ESYSROOT");
-+      if (esysroot && esysroot[0] != '\0' && strcmp(esysroot, "/") != 0 && 
(!target_system_root || strcmp(esysroot, target_system_root) != 0))
++      const char *chost = env.get("CHOST");
++      if (esysroot && (!chost || strcmp(chost, spec_machine) == 0))
 +      {
-+        target_system_root = esysroot;
-+        target_system_root_changed = 1;
++        char *my_esysroot = lrealpath(esysroot);
++        if (my_esysroot[0] == '\0')
++          my_esysroot = xstrdup("/");
++
++        if (!target_system_root ||
++            !filename_eq(my_esysroot, target_system_root[0] == '\0' ? "/" : 
target_system_root))
++          {
++            const char *broot = env.get("BROOT");
++            char *my_broot = (!broot || broot[0] == '\0') ? xstrdup("/") : 
lrealpath(broot);
++
++            if (!filename_eq(my_esysroot, my_broot))
++              {
++                target_system_root = esysroot;
++                target_system_root_changed = 1;
++              }
++
++            free(my_broot);
++          }
++
++        free(my_esysroot);
 +      }
 +    }
 +
- #if defined(TARGET_SYSTEM_ROOT_RELOCATABLE) && !defined(VMS)
-   /* If the normal TARGET_SYSTEM_ROOT is inside of $exec_prefix,
-      then consider it to relocate with the rest of the GCC installation
+   /* Set up the search paths.  We add directories that we expect to
+      contain GNU Toolchain components before directories specified by
+      the machine description so that we will find GNU components (like
 -- 
-2.45.2
+2.47.1
 

diff --git a/15.0.0/gentoo/README.history b/15.0.0/gentoo/README.history
index 975777d..bac4f3e 100644
--- a/15.0.0/gentoo/README.history
+++ b/15.0.0/gentoo/README.history
@@ -1,3 +1,7 @@
+45     ????
+
+       U 09_all_esysroot.patch
+
 44     2 February 2025
 
        - 83_all-gcc-d-give-dependency-files-better-filenames.patch
@@ -117,7 +121,7 @@
 
 21     1 November 2024
 
-       + 31_all_time64.patch   
+       + 31_all_time64.patch
 
 20     28 October 2024
 

Reply via email to