commit:     afaa35ce4365c9038d49086d0b1068d61d86ead3
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Mon Aug  4 11:06:06 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Mon Aug  4 11:06:06 2025 +0000
URL:        
https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=afaa35ce

9999: refresh strip LTO patch

Signed-off-by: Sam James <sam <AT> gentoo.org>

 ...-strip-Don-t-use-plugin-on-fat-IR-objects.patch | 224 +++++++++++++++------
 1 file changed, 160 insertions(+), 64 deletions(-)

diff --git a/9999/0006-strip-Don-t-use-plugin-on-fat-IR-objects.patch 
b/9999/0006-strip-Don-t-use-plugin-on-fat-IR-objects.patch
index 5347343..c6d732b 100644
--- a/9999/0006-strip-Don-t-use-plugin-on-fat-IR-objects.patch
+++ b/9999/0006-strip-Don-t-use-plugin-on-fat-IR-objects.patch
@@ -1,6 +1,6 @@
-https://sourceware.org/bugzilla/show_bug.cgi?id=33246#c10
+https://sourceware.org/bugzilla/show_bug.cgi?id=33246#c12
 
-From d499c2eea8d7f74f89f55a5a740f0d43e0c46c9b Mon Sep 17 00:00:00 2001
+From 4ef8b87fc5466a0b3cb162dfacfc0ffefd90670c Mon Sep 17 00:00:00 2001
 From: "H.J. Lu" <[email protected]>
 Date: Sun, 3 Aug 2025 10:28:40 -0700
 Subject: [PATCH] strip: Don't use plugin on fat IR objects
@@ -14,12 +14,13 @@ Date:   Sun May 4 05:12:46 2025 +0800
 
     strip: Add GCC LTO IR support
 
-"strip --strip-debug" no longer strips debug sections in fat IR objects.
-When called from strip, don't treat archive member nor standalone fat
-IR object as an IR object.  For archive member, it will be copied as
-an unknown object if it isn't a fat IR object.  For standalone fat IR
-object, it will be copied as non-IR object.  Debug sections and IR
-sections can be removed by strip as usual.
+"strip --strip-debug" no longer strips debug sections in fat IR objects
+since fat IR objects are copied as unknown objects.  When called from
+strip, don't treat archive member nor standalone fat IR object as an IR
+object.  For archive member, it will be copied as an unknown object if
+it isn't a fat IR object.  For standalone fat IR object, it will be
+copied as non-IR object.  Debug sections and IR sections can be removed
+by strip as usual.
 
 bfd/
 
@@ -29,12 +30,16 @@ bfd/
        (_bfd_compute_and_write_armap): Don't complain plugin is needed
        when the plugin target is in use.
        * bfd-in2.h: Regenerated.
-       * bfd.c (bfd): Add is_strip_input.
-       * format.c (bfd_set_lto_type): If there is .llvm.lto section,
+       * format.c (bfd_check_format_lto): Add a bool argument to
+       indicate called from strip.
+       (bfd_check_format): Updated.
+       (bfd_set_lto_type): If there is .llvm.lto section,
        set LTO type to lto_fat_ir_object.
-       (bfd_check_format_matches_lto): When called from strip, don't
-       treat archive member nor standalone fat IR object as an IR
-       object.  Set LTO type if IR sections won't be removed.
+       (bfd_check_format_matches_lto): Add a bool argument to indicate
+       called from strip.  When called from strip, don't treat archive
+       member nor standalone fat IR object as an IR object.  Set LTO
+       type if IR sections won't be removed.
+       (bfd_check_format_matches): Updated.
        * plugin.c (bfd_plugin_get_symbols_in_object_only): Copy LTO
        type derived from input sections.
 
@@ -44,9 +49,11 @@ nm/
        * nm.c (filter_symbols): Don't complain plugin is needed when
        the plugin target is in use.
        (display_rel_file): Likewise.
-       * objcopy.c (copy_archive): Set the is_strip_input field to 1
-       on input archive member.
-       (copy_file): Set the is_strip_input field to 1 on input object.
+       * objcopy.c (copy_archive): Pass true to bfd_check_format_lto
+       to indicat called from strip.
+       (copy_file): Call bfd_check_format_lto, instead of
+       bfd_check_format.  Pass true to bfd_check_format_lto and
+       bfd_check_format_matches_lto.
        (strip_main): Keep .gnu.debuglto_* sections unless all GCC LTO
        sections will be removed.
 
@@ -60,15 +67,14 @@ ld/
 Signed-off-by: H.J. Lu <[email protected]>
 ---
  bfd/archive.c                           |  10 +-
- bfd/bfd-in2.h                           |   3 +
- bfd/bfd.c                               |   3 +
- bfd/format.c                            |  21 +++-
+ bfd/bfd-in2.h                           |   5 +-
+ bfd/format.c                            |  43 +++++--
  bfd/plugin.c                            |   3 +
  binutils/nm.c                           |   6 +-
- binutils/objcopy.c                      |   9 ++
+ binutils/objcopy.c                      |  17 ++-
  ld/testsuite/ld-plugin/lto-binutils.exp | 153 ++++++++++++++++++++++++
  ld/testsuite/ld-plugin/pr33246.c        |   4 +
- 9 files changed, 207 insertions(+), 5 deletions(-)
+ 8 files changed, 222 insertions(+), 19 deletions(-)
  create mode 100644 ld/testsuite/ld-plugin/pr33246.c
 
 diff --git a/bfd/archive.c b/bfd/archive.c
@@ -107,38 +113,73 @@ index c61d4b12658..c323fb4fbd3 100644
                          && report_plugin_err)
                        {
 diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
-index 2ff3e930bfa..bcff44a0f44 100644
+index 2ff3e930bfa..351c9a97c52 100644
 --- a/bfd/bfd-in2.h
 +++ b/bfd/bfd-in2.h
-@@ -2131,6 +2131,9 @@ struct bfd
-   /* Set if this is the linker input BFD.  */
-   unsigned int is_linker_input : 1;
+@@ -2904,13 +2904,14 @@ bool generic_core_file_matches_executable_p
  
-+  /* Set if this is the strip input BFD.  */
-+  unsigned int is_strip_input : 1;
-+
-   /* If this is an input for a compiler plug-in library.  */
-   ENUM_BITFIELD (bfd_plugin_format) plugin_format : 2;
+ /* Extracted from format.c.  */
+ bool bfd_check_format_lto (bfd *abfd, bfd_format format,
+-    bool lto_sections_removed);
++    bool lto_sections_removed,
++    bool from_strip);
+ 
+ bool bfd_check_format (bfd *abfd, bfd_format format);
+ 
+ bool bfd_check_format_matches_lto
+    (bfd *abfd, bfd_format format, char ***matching,
+-    bool lto_sections_removed);
++    bool lto_sections_removed, bool from_strip);
  
-diff --git a/bfd/bfd.c b/bfd/bfd.c
-index 858ab5ce017..4aded6809bb 100644
---- a/bfd/bfd.c
-+++ b/bfd/bfd.c
-@@ -296,6 +296,9 @@ CODE_FRAGMENT
- .  {* Set if this is the linker input BFD.  *}
- .  unsigned int is_linker_input : 1;
- .
-+.  {* Set if this is the strip input BFD.  *}
-+.  unsigned int is_strip_input : 1;
-+.
- .  {* If this is an input for a compiler plug-in library.  *}
- .  ENUM_BITFIELD (bfd_plugin_format) plugin_format : 2;
- .
+ bool bfd_check_format_matches
+    (bfd *abfd, bfd_format format, char ***matching);
 diff --git a/bfd/format.c b/bfd/format.c
-index f3a0774af08..f88b9be1adc 100644
+index f3a0774af08..ea827bf3001 100644
 --- a/bfd/format.c
 +++ b/bfd/format.c
-@@ -413,6 +413,11 @@ bfd_set_lto_type (bfd *abfd ATTRIBUTE_UNUSED)
+@@ -60,7 +60,8 @@ FUNCTION
+ 
+ SYNOPSIS
+       bool bfd_check_format_lto (bfd *abfd, bfd_format format,
+-                                 bool lto_sections_removed);
++                                 bool lto_sections_removed,
++                                 bool from_strip);
+ 
+ DESCRIPTION
+       Verify if the file attached to the BFD @var{abfd} is compatible
+@@ -69,6 +70,8 @@ DESCRIPTION
+ 
+       If LTO_SECTION_REMOVED is true, ignore plugin target.
+ 
++      If FROM_STRIP is true, this is called from strip.
++
+       If the BFD has been set to a specific target before the
+       call, only the named target and format combination is
+       checked. If the target has not been set, or has been set to
+@@ -104,10 +107,11 @@ DESCRIPTION
+ 
+ bool
+ bfd_check_format_lto (bfd *abfd, bfd_format format,
+-                    bool lto_sections_removed)
++                    bool lto_sections_removed, bool from_strip)
+ {
+   return bfd_check_format_matches_lto (abfd, format, NULL,
+-                                     lto_sections_removed);
++                                     lto_sections_removed,
++                                     from_strip);
+ }
+ 
+ 
+@@ -126,7 +130,7 @@ DESCRIPTION
+ bool
+ bfd_check_format (bfd *abfd, bfd_format format)
+ {
+-  return bfd_check_format_matches_lto (abfd, format, NULL, false);
++  return bfd_check_format_matches_lto (abfd, format, NULL, false, false);
+ }
+ 
+ struct bfd_preserve
+@@ -413,6 +417,11 @@ bfd_set_lto_type (bfd *abfd ATTRIBUTE_UNUSED)
            abfd->object_only_section = sec;
            break;
          }
@@ -150,7 +191,33 @@ index f3a0774af08..f88b9be1adc 100644
        else if (lsection.major_version == 0
                 && startswith (sec->name, ".gnu.lto_.lto.")
                 && bfd_get_section_contents (abfd, sec, &lsection, 0,
-@@ -537,7 +542,16 @@ bfd_check_format_matches_lto (bfd *abfd, bfd_format 
format,
+@@ -436,7 +445,7 @@ FUNCTION
+ SYNOPSIS
+       bool bfd_check_format_matches_lto
+         (bfd *abfd, bfd_format format, char ***matching,
+-         bool lto_sections_removed);
++         bool lto_sections_removed, bool from_strip);
+ 
+ DESCRIPTION
+       Like <<bfd_check_format>>, except when it returns FALSE with
+@@ -450,12 +459,15 @@ DESCRIPTION
+       should free it.
+ 
+       If LTO_SECTION_REMOVED is true, ignore plugin target.
++
++      If FROM_STRIP is true, this is called from strip.
+ */
+ 
+ bool
+ bfd_check_format_matches_lto (bfd *abfd, bfd_format format,
+                             char ***matching,
+-                            bool lto_sections_removed ATTRIBUTE_UNUSED)
++                            bool lto_sections_removed ATTRIBUTE_UNUSED,
++                            bool from_strip ATTRIBUTE_UNUSED)
+ {
+   extern const bfd_target binary_vec;
+   const bfd_target * const *target;
+@@ -537,7 +549,16 @@ bfd_check_format_matches_lto (bfd *abfd, bfd_format 
format,
  
        cleanup = BFD_SEND_FMT (abfd, _bfd_check_format, (abfd));
  
@@ -161,14 +228,14 @@ index f3a0774af08..f88b9be1adc 100644
 +       isn't a fat IR object.  For standalone fat IR object,
 +       it will be copied as non-IR object.  */
 +      if (cleanup
-+        && (!abfd->is_strip_input
++        && (!from_strip
 +            || !bfd_plugin_target_p (abfd->xvec)
 +            || (abfd->lto_type != lto_fat_ir_object
 +                && abfd->my_archive == NULL)))
        goto ok_ret;
  
        /* For a long time the code has dropped through to check all
-@@ -621,6 +635,11 @@ bfd_check_format_matches_lto (bfd *abfd, bfd_format 
format,
+@@ -621,6 +642,11 @@ bfd_check_format_matches_lto (bfd *abfd, bfd_format 
format,
        {
          int match_priority = abfd->xvec->match_priority;
  
@@ -180,6 +247,16 @@ index f3a0774af08..f88b9be1adc 100644
          if (abfd->format != bfd_archive
              || (bfd_has_map (abfd)
                  && bfd_get_error () != bfd_error_wrong_object_format))
+@@ -854,7 +880,8 @@ DESCRIPTION
+ bool
+ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
+ {
+-  return bfd_check_format_matches_lto (abfd, format, matching, false);
++  return bfd_check_format_matches_lto (abfd, format, matching, false,
++                                     false);
+ }
+ 
+ /*
 diff --git a/bfd/plugin.c b/bfd/plugin.c
 index 1c72b748a8f..6dd22d75137 100644
 --- a/bfd/plugin.c
@@ -219,28 +296,47 @@ index a5d56311dde..94333042ee2 100644
        report_plugin_err = false;
        non_fatal (_("%s: plugin needed to handle lto object"),
 diff --git a/binutils/objcopy.c b/binutils/objcopy.c
-index 5774711abe6..1f3b288be00 100644
+index 5774711abe6..72ecf2cb2b1 100644
 --- a/binutils/objcopy.c
 +++ b/binutils/objcopy.c
-@@ -3687,6 +3687,8 @@ copy_archive (bfd *ibfd, bfd *obfd, const char 
*output_target,
-       bool ok_object;
-       const char *element_name;
- 
-+      this_element->is_strip_input = 1;
-+
-       element_name = bfd_get_filename (this_element);
-       /* PR binutils/17533: Do not allow directory traversal
-        outside of the current directory tree by archive members.  */
-@@ -3946,6 +3948,8 @@ copy_file (const char *input_filename, const char 
*output_filename, int ofd,
+@@ -3746,7 +3746,7 @@ copy_archive (bfd *ibfd, bfd *obfd, const char 
*output_target,
+ #if BFD_SUPPORTS_PLUGINS
+       /* Ignore plugin target if all LTO sections should be removed.  */
+       ok_object = bfd_check_format_lto (this_element, bfd_object,
+-                                      lto_sections_removed);
++                                      lto_sections_removed, true);
+ #else
+       ok_object = bfd_check_format (this_element, bfd_object);
+ #endif
+@@ -3946,7 +3946,8 @@ copy_file (const char *input_filename, const char 
*output_filename, int ofd,
        break;
      }
  
-+  ibfd->is_strip_input = 1;
-+
-   if (bfd_check_format (ibfd, bfd_archive))
+-  if (bfd_check_format (ibfd, bfd_archive))
++  if (bfd_check_format_lto (ibfd, bfd_archive, lto_sections_removed,
++                          true))
      {
        bool force_output_target;
-@@ -5066,6 +5070,11 @@ strip_main (int argc, char *argv[])
+       bfd *obfd;
+@@ -3994,13 +3995,14 @@ copy_file (const char *input_filename, const char 
*output_filename, int ofd,
+             removed.  Try with plugin target next if ignoring plugin
+             target fails to match the format.  */
+          bfd_check_format_matches_lto (ibfd, bfd_object, &obj_matching,
+-                                       lto_sections_removed)
++                                       lto_sections_removed, true)
+          || (lto_sections_removed
+              && bfd_check_format_matches_lto (ibfd, bfd_object,
+-                                              &obj_matching, false))
++                                              &obj_matching, false,
++                                              true))
+ #else
+          bfd_check_format_matches_lto (ibfd, bfd_object, &obj_matching,
+-                                       false)
++                                       false, true)
+ #endif
+          )
+     {
+@@ -5066,6 +5068,11 @@ strip_main (int argc, char *argv[])
                                               SECTION_CONTEXT_REMOVE)
                          || !!find_section_list (".llvm.lto", false,
                                               SECTION_CONTEXT_REMOVE));

Reply via email to