diff options
author | Alan Modra <amodra@gmail.com> | 2025-08-05 21:18:44 +0930 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2025-08-06 08:53:19 +0930 |
commit | b64e0a281623be62ffb610bb3c401317a1154524 (patch) | |
tree | fd11ab63ef7e1bdca1cc50c5f5cdf79e30cd0992 /binutils | |
parent | 9dd189d3ed6ea239247637656bf2990f6dfb4522 (diff) | |
download | binutils-b64e0a281623be62ffb610bb3c401317a1154524.zip binutils-b64e0a281623be62ffb610bb3c401317a1154524.tar.gz binutils-b64e0a281623be62ffb610bb3c401317a1154524.tar.bz2 |
Remove bfd_check_format_lto
Tidy changes to bfd_check_format_matches made by commit 9b854f169df9
which added a bfd_plugin_specified_p test and commit f752be8f916e
which added an lto_sections_removed arg. Both of these changes are
unnecessary if plugin_format is set to bfd_plugin_no before calling
bfd_check_format. bfd_plugin_no will prevent the plugin object_p
function from returning a match (and in the first case from a segfault
when loading plugins while a plugin is running). The plugin object_p
function already protected itself from recursive calls by setting
bfd_plugin_no before loading a plugin, but commit 9b854f169df9 opened
new bfds so they were unprotected.
It isn't strictly necessary to test for bfd_plugin_no in
bfd_check_format_matches but I kept the check to minimise functional
changes. Close inspection of the patch will notice I've added an
is_linker_input test too. That also isn't strictly necessary, I
think, but the match_count test was for the linker. See commit
999d6dff80fa.
PR 12291
PR 12430
PR 13298
PR 33198
bfd/
* format.c (bfd_check_format_lto): Revert to bfd_check_format.
(bfd_check_format_matches_lto): Revert to bfd_check_format_matches.
Correct comments. Manage both the lto_sections_removed and
bfd_plugin_specified_p cases by testing for bfd_plugin_no.
* plugin.c (bfd_plugin_get_symbols_in_object_only): Set
plugin_format to bfd_plugin_no before checking new bfds.
(try_load_plugin): Comment setting bfd_plugin_no.
(bfd_plugin_specified_p): Delete.
* plugin.h (bfd_plugin_specified_p): Delete.
* bfd-in2.h: Regenerate.
binutils/
* objcopy.c (copy_archive): Replace bfd_check_format_lto calls
with bfd_check_format using plugin_format set to bfd_plugin_no.
(check_format_object): New function.
(copy_file): Use it.
Diffstat (limited to 'binutils')
-rw-r--r-- | binutils/objcopy.c | 44 |
1 files changed, 25 insertions, 19 deletions
diff --git a/binutils/objcopy.c b/binutils/objcopy.c index 5774711..8bd523a 100644 --- a/binutils/objcopy.c +++ b/binutils/objcopy.c @@ -170,6 +170,8 @@ static bool sections_removed; #if BFD_SUPPORTS_PLUGINS /* TRUE if all GCC LTO sections are to be removed. */ static bool lto_sections_removed; +#else +#define lto_sections_removed false #endif /* TRUE if only some sections are to be copied. */ @@ -3745,11 +3747,10 @@ 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); -#else - ok_object = bfd_check_format (this_element, bfd_object); + if (lto_sections_removed) + this_element->plugin_format = bfd_plugin_no; #endif + ok_object = bfd_check_format (this_element, bfd_object); /* PR binutils/3110: Cope with archives containing multiple target types. */ @@ -3863,6 +3864,25 @@ copy_archive (bfd *ibfd, bfd *obfd, const char *output_target, return ok; } +static bool +check_format_object (bfd *ibfd, char ***obj_matching, + bool no_plugins ATTRIBUTE_UNUSED) +{ +#if BFD_SUPPORTS_PLUGINS + /* Ignore plugin target first if all LTO sections should be + removed. Try with plugin target next if ignoring plugin + target fails to match the format. */ + if (no_plugins && ibfd->plugin_format == bfd_plugin_unknown) + { + ibfd->plugin_format = bfd_plugin_no; + if (bfd_check_format_matches (ibfd, bfd_object, obj_matching)) + return true; + ibfd->plugin_format = bfd_plugin_unknown; + } +#endif + return bfd_check_format_matches (ibfd, bfd_object, obj_matching); +} + /* The top-level control. */ static void @@ -3988,21 +4008,7 @@ copy_file (const char *input_filename, const char *output_filename, int ofd, input_arch, target_defaulted)) status = 1; } - else if ( -#if BFD_SUPPORTS_PLUGINS - /* Ignore plugin target first if all LTO sections should be - 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 - && bfd_check_format_matches_lto (ibfd, bfd_object, - &obj_matching, false)) -#else - bfd_check_format_matches_lto (ibfd, bfd_object, &obj_matching, - false) -#endif - ) + else if (check_format_object (ibfd, &obj_matching, lto_sections_removed)) { bfd *obfd; do_copy: |