]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
binutils: Don't complain plugin with all LTO sections removed
authorH.J. Lu <hjl.tools@gmail.com>
Wed, 14 May 2025 23:30:06 +0000 (07:30 +0800)
committerH.J. Lu <hjl.tools@gmail.com>
Thu, 15 May 2025 00:43:58 +0000 (08:43 +0800)
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>
bfd/archive.c
bfd/bfd-in2.h
bfd/bfd.c
binutils/nm.c
ld/testsuite/ld-plugin/lto-binutils.exp
ld/testsuite/ld-plugin/strip-1a-s-all.nd [new file with mode: 0644]

index 6cda73ce90313d27e44112a199403041dc737c62..8e20554d781acfdb400c6f42cf7fc02e008812ee 100644 (file)
@@ -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;
index ec60f23f61b6f6e5c69d05c71dd417ddeacb8c52..eca6d0c89e90df9529821dea451068481fb69955 100644 (file)
@@ -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)
 {
index a8d1314b83f088e9879aa43d93b6b8ba1abf6823..bb8ec43ef2beb958c13287f9d6471568f0010a22 100644 (file)
--- 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)
 .{
index 7ef5d61306bc41e889d427ca99714fcc9b64d74b..a5d56311ddedd1c35d07c1feb77b219a3a811afc 100644 (file)
@@ -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;
index 36c7380c9b36baea93ff644b4304a58f233e571b..5b4e0a10991810b3fdec770b0015c6f3203c4acc 100644 (file)
@@ -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 (file)
index 0000000..612ba6a
--- /dev/null
@@ -0,0 +1,3 @@
+#...
+[0-9a-f]* C _?__gnu_lto_slim
+#pass