[binutils-gdb] binutils: Don't complain plugin with all LTO sections removed

H.J. Lu hjl@sourceware.org
Thu May 15 00:52:25 GMT 2025


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=d1851edfe9d2469330568c289adb81ee7b128bfe

commit d1851edfe9d2469330568c289adb81ee7b128bfe
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Thu May 15 07:30:06 2025 +0800

    binutils: Don't complain plugin with all LTO sections removed
    
    When all LTO sections have been removed, the BFD lto_type is set to
    lto_non_ir_object by bfd_set_lto_type.  In this case, don't complain
    needing a plugin when seeing a LTO slim symbol.
    
    bfd/
    
            PR binutils/32967
            * archive.c (_bfd_compute_and_write_armap): Call
            bfd_lto_slim_symbol_p to check LTO slim symbol.
            * bfd-in2.h: Generated.
            * bfd.c (bfd_lto_slim_symbol_p): New.
    
    binutils/
    
            PR binutils/32967
            * nm.c (filter_symbols): Call bfd_lto_slim_symbol_p to check
            LTO slim symbol.
    
    ld/
    
            PR binutils/32967
            * testsuite/ld-plugin/lto-binutils.exp: Run PR binutils/32967
            tests.
            * testsuite/ld-plugin/strip-1a-s-all.nd: New file.
    
    Signed-off-by: H.J. Lu <hjl.tools@gmail.com>

Diff:
---
 bfd/archive.c                            |  8 ++------
 bfd/bfd-in2.h                            | 10 ++++++++++
 bfd/bfd.c                                | 10 ++++++++++
 binutils/nm.c                            |  5 +----
 ld/testsuite/ld-plugin/lto-binutils.exp  | 19 +++++++++++++++++++
 ld/testsuite/ld-plugin/strip-1a-s-all.nd |  3 +++
 6 files changed, 45 insertions(+), 10 deletions(-)

diff --git a/bfd/archive.c b/bfd/archive.c
index 6cda73ce903..8e20554d781 100644
--- a/bfd/archive.c
+++ b/bfd/archive.c
@@ -2399,12 +2399,8 @@ _bfd_compute_and_write_armap (bfd *arch, unsigned int elength)
 			  map = new_map;
 			}
 
-		      if (syms[src_count]->name != NULL
-			  && syms[src_count]->name[0] == '_'
-			  && syms[src_count]->name[1] == '_'
-			  && strcmp (syms[src_count]->name
-				     + (syms[src_count]->name[2] == '_'),
-				     "__gnu_lto_slim") == 0
+		      if (bfd_lto_slim_symbol_p (current,
+						 syms[src_count]->name)
 			  && report_plugin_err)
 			{
 			  report_plugin_err = false;
diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
index ec60f23f61b..eca6d0c89e9 100644
--- a/bfd/bfd-in2.h
+++ b/bfd/bfd-in2.h
@@ -2302,6 +2302,16 @@ bfd_get_lto_type (const bfd *abfd)
   return abfd->lto_type;
 }
 
+static inline bool
+bfd_lto_slim_symbol_p (const bfd *abfd, const char *name)
+{
+  return (bfd_get_lto_type (abfd) != lto_non_ir_object
+	  && name != NULL
+	  && name[0] == '_'
+	  && name[1] == '_'
+	  && strcmp (name + (name[2] == '_'), "__gnu_lto_slim") == 0);
+}
+
 static inline flagword
 bfd_get_file_flags (const bfd *abfd)
 {
diff --git a/bfd/bfd.c b/bfd/bfd.c
index a8d1314b83f..bb8ec43ef2b 100644
--- a/bfd/bfd.c
+++ b/bfd/bfd.c
@@ -470,6 +470,16 @@ EXTERNAL
 .  return abfd->lto_type;
 .}
 .
+.static inline bool
+.bfd_lto_slim_symbol_p (const bfd *abfd, const char *name)
+.{
+.  return (bfd_get_lto_type (abfd) != lto_non_ir_object
+.	   && name != NULL
+.	   && name[0] == '_'
+.	   && name[1] == '_'
+.	   && strcmp (name + (name[2] == '_'), "__gnu_lto_slim") == 0);
+.}
+.
 .static inline flagword
 .bfd_get_file_flags (const bfd *abfd)
 .{
diff --git a/binutils/nm.c b/binutils/nm.c
index 7ef5d61306b..a5d56311dde 100644
--- a/binutils/nm.c
+++ b/binutils/nm.c
@@ -801,10 +801,7 @@ filter_symbols (bfd *abfd, bool is_dynamic, void *minisyms,
       if (sym == NULL)
 	continue;
 
-      if (sym->name != NULL
-	  && sym->name[0] == '_'
-	  && sym->name[1] == '_'
-	  && strcmp (sym->name + (sym->name[2] == '_'), "__gnu_lto_slim") == 0
+      if (bfd_lto_slim_symbol_p (abfd, sym->name)
 	  && report_plugin_err)
 	{
 	  report_plugin_err = false;
diff --git a/ld/testsuite/ld-plugin/lto-binutils.exp b/ld/testsuite/ld-plugin/lto-binutils.exp
index 36c7380c9b3..5b4e0a10991 100644
--- a/ld/testsuite/ld-plugin/lto-binutils.exp
+++ b/ld/testsuite/ld-plugin/lto-binutils.exp
@@ -255,6 +255,25 @@ run_lto_binutils_test [list \
     ] \
 ]
 
+if { [check_lto_fat_available] } {
+    run_lto_binutils_test [list \
+	[list \
+	    "strip" \
+	    "-R .gnu.*lto_* -N __gnu_lto_v1" \
+	    "strip-1a.o" \
+	    "strip-1a-s-all.o" \
+	    {{nm -n strip-1a-s-all.nd}} \
+	] \
+	[list \
+	    "strip" \
+	    "-R .gnu.*lto_* -N __gnu_lto_v1" \
+	    "libstrip-1a.a" \
+	    "libstrip-1a-s-all.a" \
+	    {{nm -n strip-1a-s-all.nd}} \
+	] \
+    ]
+}
+
 run_cc_link_tests [list \
     [list \
 	"Build strip-1a (strip-1a.o)" \
diff --git a/ld/testsuite/ld-plugin/strip-1a-s-all.nd b/ld/testsuite/ld-plugin/strip-1a-s-all.nd
new file mode 100644
index 00000000000..612ba6a39b1
--- /dev/null
+++ b/ld/testsuite/ld-plugin/strip-1a-s-all.nd
@@ -0,0 +1,3 @@
+#...
+[0-9a-f]* C _?__gnu_lto_slim
+#pass


More information about the Binutils-cvs mailing list