Limit BFD_SUPPORTS_PLUGINS check to plugin.h and targets.c

Minimize the BFD_SUPPORTS_PLUGINS check to make code more readable and
maintainable by:

1. Update bfd/plugin.h to define plugin functions as static inline if
BFD_SUPPORTS_PLUGINS is 0.
2. Remove BFD_SUPPORTS_PLUGINS check from all bfd and binutils files
except plugin.h and targets.c.
3. Replace the remaining BFD_SUPPORTS_PLUGINS checks with a function so
that plugin availability is checked at run time.

bfd/

	* archive.c: Include plugin.h unconditionally.
	(_bfd_compute_and_write_armap): Remove the BFD_SUPPORTS_PLUGINS
	check.
	* bfd-in.h (bfd_plugin_enabled): New.
	* bfd-in2.h: Regenerated.
	* elflink.c: Include plugin.h unconditionally.
	(elf_link_is_defined_archive_symbol): Remove the
	BFD_SUPPORTS_PLUGINS check.
	* format.c: Include plugin.h unconditionally.
	(bfd_set_lto_type): Remove the BFD_SUPPORTS_PLUGINS check.
	(bfd_check_format_matches): Replace the BFD_SUPPORTS_PLUGINS
	check with the bfd_plugin_enabled call.  Replace plugin_vec
	with bfd_plugin_vec.  Remove the BFD_SUPPORTS_PLUGINS check.
	* plugin.c (bfd_plugin_target_p): Removed.
	* plugin.h (bfd_plugin_vec): New.
	(bfd_plugin_target_p): Likewise.
	(bfd_plugin_set_program_name): New.  Static inline
	function if BFD_SUPPORTS_PLUGINS is 0.
	(bfd_plugin_open_input): Likewise.
	(bfd_plugin_set_plugin): Likewise.
	(bfd_link_plugin_object_p): Likewise.
	(register_ld_plugin_object_p): Likewise.
	(bfd_plugin_close_file_descriptor): Likewise.
	(bfd_plugin_vec): Likewise.
	(bfd_plugin_target_p): Likewise.
	* xtensa-dynconfig.c (xtensa_load_config): Replace the
	BFD_SUPPORTS_PLUGINS check with the bfd_plugin_enabled call.

ar/

	* ar.c: Include plugin.h unconditionally.
	(plugin_target): Removed.
	(usage): Replace the BFD_SUPPORTS_PLUGINS check with the
	bfd_plugin_enabled call.
	(ranlib_usage): Likewise.
	(decode_options): Likewise.
	(ranlib_main): Likewise.
	(main): Call bfd_plugin_set_program_name unconditionally.
	* nm.c: Include plugin.h unconditionally.
	(plugin_target): Removed.
	(usage): Replace the BFD_SUPPORTS_PLUGINS check with the
	bfd_plugin_enabled call.
	(filter_symbols): Remove the BFD_SUPPORTS_PLUGINS check.
	(display_rel_file): Likewise.
	(main): Call bfd_plugin_set_program_name unconditionally.  Replace
	the BFD_SUPPORTS_PLUGINS check with the bfd_plugin_enabled call.
	* objcopy.c: Include plugin.h unconditionally.
	(strip_usage): Replace the BFD_SUPPORTS_PLUGINS check with the
	bfd_plugin_enabled call.
	(copy_archive): Remove the BFD_SUPPORTS_PLUGINS check.  Replace
	BFD_SUPPORTS_PLUGINS with the bfd_plugin_enabled call.
	(copy_file): Likewise.
	(strip_main): Likewise.

ld/

	* ldfile.c: Include plugin.h unconditionally.
	(ldfile_try_open_bfd): Remove the BFD_SUPPORTS_PLUGINS check.
	* ldlang.c: Include plugin.h unconditionally.
	(plugin_insert): Remove the BFD_SUPPORTS_PLUGINS check.
	(plugin_undefs): Likewise.
	(open_input_bfds): Likewise.
	(lang_check): Likewise.
	(lang_gc_sections): Likewise.
	(find_next_input_statement): Likewise.
	(lang_process): Likewise.
	* ldlang.h (lang_input_statement_flags): Likewise.
	* ldlex.h (option_values): Likewise.
	* ldmain.c: Include plugin.h unconditionally.
	(ld_cleanup): Remove the BFD_SUPPORTS_PLUGINS check.
	(main): Likewise.
	(add_archive_element): Likewise.
	* lexsup.c: Include plugin.h unconditionally.
	(ld_options): Remove the BFD_SUPPORTS_PLUGINS check.
	(parse_args): Replace the BFD_SUPPORTS_PLUGINS check with the
	bfd_plugin_enabled call.  Remove the BFD_SUPPORTS_PLUGINS check.
	(help): Append " (ignored)" to plugin options if bfd_plugin_enabled
	return false.
	* libdep_plugin.c: Remove the BFD_SUPPORTS_PLUGINS check.
	* plugin.c: Likewise.
	* testplug.c: Likewise.
	* testplug2.c: Likewise.
	* testplug3.c: Likewise.
	* testplug4.c: Likewise.

Co-Authored-By: Alan Modra <amodra@gmail.com>
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
This commit is contained in:
H.J. Lu
2025-08-18 06:07:39 -07:00
parent 74201a3208
commit 7e432e93f8
23 changed files with 162 additions and 214 deletions

View File

@@ -30,9 +30,7 @@
#include "coff/internal.h"
#include "libcoff.h"
#include "safe-ctype.h"
#if BFD_SUPPORTS_PLUGINS
#include "plugin.h"
#endif
/* FIXME: See bfd/peXXigen.c for why we include an architecture specific
header in generic PE code. */
@@ -763,10 +761,9 @@ strip_usage (FILE *stream, int exit_status)
--info List object formats & architectures supported\n\
-o <file> Place stripped output into <file>\n\
"));
#if BFD_SUPPORTS_PLUGINS
fprintf (stream, _("\
if (bfd_plugin_enabled ())
fprintf (stream, _("\
--plugin NAME Load the specified plugin\n"));
#endif
list_supported_targets (program_name, stream);
if (REPORT_BUGS_TO[0] && exit_status == 0)
@@ -3757,11 +3754,9 @@ copy_archive (bfd *ibfd, bfd *obfd, const char *output_target,
goto cleanup_and_exit;
}
#if BFD_SUPPORTS_PLUGINS
/* Copy slim LTO IR file as unknown object. */
if (this_element->lto_type == lto_slim_ir_object)
ok_object = false;
#endif
if (ok_object)
{
ok = copy_object (this_element, output_element, input_arch,
@@ -3991,8 +3986,7 @@ copy_file (const char *input_filename, const char *output_filename, int ofd,
free (obj_matching);
obj_error = bfd_error_no_error;
}
#if BFD_SUPPORTS_PLUGINS
else
else if (bfd_plugin_enabled ())
{
/* This is for LLVM bytecode files, which are not ELF objects.
Since objcopy/strip does nothing with these files except
@@ -4001,7 +3995,6 @@ copy_file (const char *input_filename, const char *output_filename, int ofd,
ibfd->plugin_format = bfd_plugin_unknown;
ok_plugin = bfd_check_format (ibfd, bfd_object);
}
#endif
}
if (obj_error == bfd_error_file_ambiguously_recognized)
@@ -4051,11 +4044,9 @@ copy_file (const char *input_filename, const char *output_filename, int ofd,
return;
}
#if BFD_SUPPORTS_PLUGINS
/* Copy slim LTO IR file as unknown file. */
if (ibfd->lto_type == lto_slim_ir_object)
ok_object = false;
#endif
if (ok_object
? !copy_object (ibfd, obfd, input_arch, target_defaulted)
: !copy_unknown_file (ibfd, obfd,
@@ -4900,9 +4891,7 @@ strip_main (int argc, char *argv[])
char *output_file = NULL;
bool merge_notes_set = false;
#if BFD_SUPPORTS_PLUGINS
bfd_plugin_set_program_name (argv[0]);
#endif
while ((c = getopt_long (argc, argv, "I:O:F:K:MN:R:o:sSpdgxXHhVvwDU",
strip_options, (int *) 0)) != EOF)
@@ -4995,11 +4984,9 @@ strip_main (int argc, char *argv[])
keep_section_symbols = true;
break;
case OPTION_PLUGIN: /* --plugin */
#if BFD_SUPPORTS_PLUGINS
if (!bfd_plugin_enabled ())
fatal (_("sorry - this program has been built without plugin support\n"));
bfd_plugin_set_plugin (optarg);
#else
fatal (_("sorry - this program has been built without plugin support\n"));
#endif
break;
case 0:
/* We've been given a long option. */
@@ -5045,7 +5032,6 @@ strip_main (int argc, char *argv[])
if (output_target == NULL)
output_target = input_target;
#if BFD_SUPPORTS_PLUGINS
/* Check if all GCC LTO sections should be removed, assuming all LTO
sections will be removed with -R .gnu.lto_.*. Remove .gnu.lto_.*
sections will also remove .gnu.debuglto_.* sections.
@@ -5055,7 +5041,6 @@ strip_main (int argc, char *argv[])
debug sections. */
if (!find_section_list (".gnu.lto_.*", false, SECTION_CONTEXT_REMOVE))
find_section_list (".gnu.debuglto_*", true, SECTION_CONTEXT_KEEP);
#endif
i = optind;
if (i == argc