diff options
author | H.J. Lu <hjl.tools@gmail.com> | 2025-08-03 10:28:40 -0700 |
---|---|---|
committer | H.J. Lu <hjl.tools@gmail.com> | 2025-08-06 04:51:20 -0700 |
commit | c2729c37f10af09126b2916215cae425ae724f55 (patch) | |
tree | 96223ddb0cdb402f063147be060f247005138994 /bfd | |
parent | d6e93eedfb9e75846c3083f49f9015eda1a2be33 (diff) | |
download | binutils-c2729c37f10af09126b2916215cae425ae724f55.zip binutils-c2729c37f10af09126b2916215cae425ae724f55.tar.gz binutils-c2729c37f10af09126b2916215cae425ae724f55.tar.bz2 |
strip: Don't treat fat IR objects as plugin object
Fat IR objects contains both regular sections and IR sections. After
commit 717a38e9a02109fcbcb18bb2ec3aa251e2ad0a0d
Author: H.J. Lu <hjl.tools@gmail.com>
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
since fat IR objects are recognized as plugin object and copied as unknown
objects. Add a is_strip_input field to bfd to indicate called from strip.
Update bfd_check_format_matches not to treat archive member nor standalone
fat IR object as IR object so that strip can remove debug and IR sections
in fat IR object. For archive member, it is copied as an unknown object
if the plugin target is in use or it is a slim IR object. For standalone
fat IR object, it is copied as non-IR object.
bfd/
PR binutils/33246
* archive.c: Include "plugin-api.h" and "plugin.h" if plugin is
enabled.
(_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,
set LTO type to lto_fat_ir_object.
(bfd_check_format_matches): Don't set LTO type when setting
format. When called from strip, don't treat archive member nor
standalone fat IR object as an IR object.
* plugin.c (bfd_plugin_get_symbols_in_object_only): Copy LTO
type derived from input sections.
nm/
PR binutils/33246
* 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 BFD is_strip_input field of
archive member to 1 to indicate called from strip. Also copy
slim IR archive member as unknown object.
(copy_file): Set the BFD is_strip_input field of input bfd to
1 to indicate called from strip.
(strip_main): Keep .gnu.debuglto_* sections unless all GCC LTO
sections will be removed.
ld/
PR binutils/33246
* testsuite/ld-plugin/lto-binutils.exp (run_pr33246_test): New.
Run binutils/33246 tests with GCC and Clang.
* testsuite/ld-plugin/pr33246.c: New file.
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
Diffstat (limited to 'bfd')
-rw-r--r-- | bfd/archive.c | 10 | ||||
-rw-r--r-- | bfd/bfd-in2.h | 3 | ||||
-rw-r--r-- | bfd/bfd.c | 3 | ||||
-rw-r--r-- | bfd/format.c | 25 | ||||
-rw-r--r-- | bfd/plugin.c | 3 |
5 files changed, 39 insertions, 5 deletions
diff --git a/bfd/archive.c b/bfd/archive.c index c61d4b1..697b2ed 100644 --- a/bfd/archive.c +++ b/bfd/archive.c @@ -141,6 +141,10 @@ SUBSECTION #include "hashtab.h" #include "filenames.h" #include "bfdlink.h" +#if BFD_SUPPORTS_PLUGINS +#include "plugin-api.h" +#include "plugin.h" +#endif #ifndef errno extern int errno; @@ -2343,6 +2347,9 @@ _bfd_compute_and_write_armap (bfd *arch, unsigned int elength) long src_count; if (bfd_get_lto_type (current) == lto_slim_ir_object +#if BFD_SUPPORTS_PLUGINS + && !bfd_plugin_target_p (current->xvec) +#endif && report_plugin_err) { report_plugin_err = false; @@ -2400,6 +2407,9 @@ _bfd_compute_and_write_armap (bfd *arch, unsigned int elength) if (bfd_lto_slim_symbol_p (current, syms[src_count]->name) +#if BFD_SUPPORTS_PLUGINS + && !bfd_plugin_target_p (current->xvec) +#endif && report_plugin_err) { report_plugin_err = false; diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h index b013ef9..12512a3 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; + /* 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; @@ -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; . diff --git a/bfd/format.c b/bfd/format.c index d2bc318..bd9fa8d 100644 --- a/bfd/format.c +++ b/bfd/format.c @@ -389,6 +389,11 @@ bfd_set_lto_type (bfd *abfd ATTRIBUTE_UNUSED) abfd->object_only_section = sec; break; } + else if (strcmp (sec->name, ".llvm.lto") == 0) + { + type = lto_fat_ir_object; + break; + } else if (lsection.major_version == 0 && startswith (sec->name, ".gnu.lto_.lto.") && bfd_get_section_contents (abfd, sec, &lsection, 0, @@ -453,10 +458,7 @@ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching) } if (abfd->format != bfd_unknown) - { - bfd_set_lto_type (abfd); - return abfd->format == format; - } + return abfd->format == format; if (matching != NULL || *bfd_associated_vector != NULL) { @@ -510,7 +512,20 @@ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching) cleanup = BFD_SEND_FMT (abfd, _bfd_check_format, (abfd)); - if (cleanup) + /* 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 the + plugin target is in use or it is a slim IR object. For + standalone fat IR object, it will be copied as non-IR + object. */ + if (cleanup +#if BFD_SUPPORTS_PLUGINS + && (!abfd->is_strip_input + || !bfd_plugin_target_p (abfd->xvec) + || (abfd->lto_type != lto_fat_ir_object + && abfd->my_archive == NULL)) +#endif + ) goto ok_ret; /* For a long time the code has dropped through to check all diff --git a/bfd/plugin.c b/bfd/plugin.c index ebdf250..43ca444 100644 --- a/bfd/plugin.c +++ b/bfd/plugin.c @@ -206,6 +206,9 @@ bfd_plugin_get_symbols_in_object_only (bfd *abfd) bfd_close (nbfd); return; } + + /* Copy LTO type derived from input sections. */ + abfd->lto_type = nbfd->lto_type; } else { |