From: H.J. Lu Date: Wed, 14 May 2025 23:30:06 +0000 (+0800) Subject: binutils: Don't complain plugin with all LTO sections removed X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d1851edfe9d2469330568c289adb81ee7b128bfe;p=thirdparty%2Fbinutils-gdb.git 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 --- 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