[PATCH v2] Limit BFD_SUPPORTS_PLUGINS check to plugin.h and targets.c

H.J. Lu hjl.tools@gmail.com
Sat Aug 16 22:05:49 GMT 2025


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

1. Update bfd_check_format_matches to require the plugin target for slim
LTO IR object if it isn't a linker input.
2. Update bfd/plugin.h to define plugin functions as static inline if
BFD_SUPPORTS_PLUGINS is 0.
3. Remove BFD_SUPPORTS_PLUGINS check from all bfd and binutils files
except plugin.h and targets.c.
4. 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): Likewise.  Require the plugin target
	for slim LTO IR object if it isn't a linker input.  Search for
	the valid target if not archive.
	* plugin.c: Remove the BFD_SUPPORTS_PLUGINS check.
	(bfd_plugin_set_program_name): Set plugin_program_name only if
	plugin is enabled.
	* plugin.h (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_plugin_target_p): Likewise.
	(bfd_link_plugin_object_p): Likewise.
	(register_ld_plugin_object_p): Likewise.
	(bfd_plugin_close_file_descriptor): Likewise.
	* targets.c (bfd_find_target): Use the default target if the
	target name is "plugin" and plugin is disabled.
	* 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.
	Pass "plugin", instead of plugin_target, to bfd_find_target.
	(open_inarch): Remove the plugin target usage.  Don't call
	set_plugin_target.
	(replace_members): Likewise.
	* arsup.c (plugin_target): Removed.
	(ar_open): Remove the plugin target usage.  Don't call
	set_plugin_target.
	(ar_addmod): Replace plugin_target with NULL.
	(ar_replace): Likewise.
	* bucomm.h (set_plugin_target): Removed.
	* 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.
	(display_archive): Remove the plugin target usage.  Don't call
	set_plugin_target.
	(display_file): Always pass target to bfd_openr.
	(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.
	(copy_file): Replace BFD_SUPPORTS_PLUGINS with the
	bfd_plugin_enabled call on LLVM bytecode files.  Remove the
	BFD_SUPPORTS_PLUGINS check.
	(strip_main): Remove the BFD_SUPPORTS_PLUGINS check.  Replace the
	BFD_SUPPORTS_PLUGINS check with the bfd_plugin_enabled call.
	Remove the BFD_SUPPORTS_PLUGINS check.

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.
	(cmdline_add_object_only_section): Set the is_linker_input
	field.
	* 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.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
---
 bfd/archive.c          |  6 ----
 bfd/bfd-in.h           |  8 +++++
 bfd/bfd-in2.h          |  8 +++++
 bfd/elflink.c          |  7 +---
 bfd/format.c           | 37 +++++++++++++-------
 bfd/plugin.c           |  3 --
 bfd/plugin.h           | 43 +++++++++++++++++++++++
 bfd/targets.c          |  8 +++--
 bfd/xtensa-dynconfig.c | 62 ++++++++++++++++-----------------
 binutils/ar.c          | 78 ++++++++++++++----------------------------
 binutils/arsup.c       | 19 ++--------
 binutils/bucomm.h      | 15 --------
 binutils/nm.c          | 39 ++++-----------------
 binutils/objcopy.c     | 35 ++++---------------
 ld/ldfile.c            |  8 -----
 ld/ldlang.c            | 31 +++--------------
 ld/ldlang.h            |  2 --
 ld/ldlex.h             |  2 --
 ld/ldmain.c            |  8 -----
 ld/lexsup.c            | 27 ++++++---------
 ld/libdep_plugin.c     |  2 --
 ld/plugin.c            |  2 --
 ld/testplug.c          |  2 --
 ld/testplug2.c         |  2 --
 ld/testplug3.c         |  2 --
 ld/testplug4.c         |  2 --
 26 files changed, 177 insertions(+), 281 deletions(-)

diff --git a/bfd/archive.c b/bfd/archive.c
index 16b725b9958..d2a9fd171a7 100644
--- a/bfd/archive.c
+++ b/bfd/archive.c
@@ -141,9 +141,7 @@ SUBSECTION
 #include "hashtab.h"
 #include "filenames.h"
 #include "bfdlink.h"
-#if BFD_SUPPORTS_PLUGINS
 #include "plugin.h"
-#endif
 
 #ifndef errno
 extern int errno;
@@ -2360,9 +2358,7 @@ _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;
@@ -2420,9 +2416,7 @@ _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-in.h b/bfd/bfd-in.h
index df5568e9639..ea2d2cb0010 100644
--- a/bfd/bfd-in.h
+++ b/bfd/bfd-in.h
@@ -159,3 +159,11 @@ startswith (const char *str, const char *prefix)
   return strncmp (str, prefix, strlen (prefix)) == 0;
 }
 
+/* Return true if plugin is enabled.  */
+
+static inline bool
+bfd_plugin_enabled (void)
+{
+  return BFD_SUPPORTS_PLUGINS != 0;
+}
+
diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
index b013ef954da..5e7c6ddf1ee 100644
--- a/bfd/bfd-in2.h
+++ b/bfd/bfd-in2.h
@@ -166,6 +166,14 @@ startswith (const char *str, const char *prefix)
   return strncmp (str, prefix, strlen (prefix)) == 0;
 }
 
+/* Return true if plugin is enabled.  */
+
+static inline bool
+bfd_plugin_enabled (void)
+{
+  return BFD_SUPPORTS_PLUGINS != 0;
+}
+
 /* Extracted from libbfd.c.  */
 void *bfd_alloc (bfd *abfd, bfd_size_type wanted);
 
diff --git a/bfd/elflink.c b/bfd/elflink.c
index 7b0375406ac..f6c0c04e82e 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -27,9 +27,7 @@
 #include "safe-ctype.h"
 #include "libiberty.h"
 #include "objalloc.h"
-#if BFD_SUPPORTS_PLUGINS
 #include "plugin.h"
-#endif
 
 #include <limits.h>
 #ifndef CHAR_BIT
@@ -3678,11 +3676,8 @@ elf_link_is_defined_archive_symbol (bfd * abfd, carsym * symdef)
      get the correct symbol table.  */
   if (abfd->plugin_format == bfd_plugin_yes
       || abfd->plugin_format == bfd_plugin_yes_unused
-#if BFD_SUPPORTS_PLUGINS
       || (abfd->plugin_format == bfd_plugin_unknown
-	  && bfd_link_plugin_object_p (abfd))
-#endif
-      )
+	  && bfd_link_plugin_object_p (abfd)))
     {
       /* Use the IR symbol table if the object has been claimed by
 	 plugin.  */
diff --git a/bfd/format.c b/bfd/format.c
index 4dbe863e742..fc4a029c4a2 100644
--- a/bfd/format.c
+++ b/bfd/format.c
@@ -46,9 +46,7 @@ SUBSECTION
 #include "sysdep.h"
 #include "bfd.h"
 #include "libbfd.h"
-#if BFD_SUPPORTS_PLUGINS
 #include "plugin.h"
-#endif
 
 /* IMPORT from targets.c.  */
 extern const size_t _bfd_target_vector_entries;
@@ -366,9 +364,8 @@ struct lto_section
 /* Set lto_type in ABFD.  */
 
 static void
-bfd_set_lto_type (bfd *abfd ATTRIBUTE_UNUSED)
+bfd_set_lto_type (bfd *abfd)
 {
-#if BFD_SUPPORTS_PLUGINS
   if (abfd->format == bfd_object
       && abfd->lto_type == lto_non_object
       && (abfd->flags
@@ -422,7 +419,6 @@ bfd_set_lto_type (bfd *abfd ATTRIBUTE_UNUSED)
 
       abfd->lto_type = type;
     }
-#endif
 }
 
 /*
@@ -523,10 +519,8 @@ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
      bfd_plugin_no excluding the plugin target condition is an
      optimisation, and can be removed if desired.  */
   fail_targ = NULL;
-#if BFD_SUPPORTS_PLUGINS
   if (!(abfd->plugin_format == bfd_plugin_no
 	&& bfd_plugin_target_p (save_targ)))
-#endif
     {
       if (bfd_seek (abfd, 0, SEEK_SET) != 0)
 	goto err_ret;
@@ -546,11 +540,22 @@ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
 		 truncated error.  */
 	      || (!bfd_has_map (abfd)
 		  && bfd_get_error () == bfd_error_file_truncated))
-	    goto ok_ret;
+	    {
+	      if (abfd->is_linker_input || format != bfd_object)
+		goto ok_ret;
+
+	      /* Require the plugin target for slim LTO IR object.  */
+	      bfd_set_lto_type (abfd);
+	      if (abfd->lto_type != lto_slim_ir_object
+		  || bfd_plugin_target_p (abfd->xvec))
+		goto ok_ret;
+	    }
 	}
       else
 	{
-	  if (!abfd->target_defaulted && !abfd->is_linker_input)
+	  if (format == bfd_archive
+	      && !abfd->target_defaulted
+	      && !abfd->is_linker_input)
 	    goto err_unrecog;
 	  fail_targ = save_targ;
 	}
@@ -582,12 +587,9 @@ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
 	 bfd_plugin_get_symbols_in_object_only.)  */
       if (*target == &binary_vec
 	  || *target == fail_targ
-#if BFD_SUPPORTS_PLUGINS
 	  || (((abfd->is_linker_input && match_count != 0)
 	       || abfd->plugin_format == bfd_plugin_no)
-	      && bfd_plugin_target_p (*target))
-#endif
-	  )
+	      && bfd_plugin_target_p (*target)))
 	continue;
 
       /* If we already tried a match, the bfd is modified and may
@@ -625,6 +627,15 @@ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
 	      || (bfd_has_map (abfd)
 		  && bfd_get_error () != bfd_error_wrong_object_format))
 	    {
+	      if (!abfd->is_linker_input && abfd->format == bfd_object)
+		{
+		  /* Require the plugin target for slim LTO IR object.  */
+		  bfd_set_lto_type (abfd);
+		  if (abfd->lto_type == lto_slim_ir_object
+		      && !bfd_plugin_target_p (abfd->xvec))
+		    continue;
+		}
+
 	      /* If this is the default target, accept it, even if
 		 other targets might match.  People who want those
 		 other targets have to set the GNUTARGET variable.  */
diff --git a/bfd/plugin.c b/bfd/plugin.c
index 2be384d8ef5..393011432a8 100644
--- a/bfd/plugin.c
+++ b/bfd/plugin.c
@@ -21,8 +21,6 @@
 #include "sysdep.h"
 #include "bfd.h"
 
-#if BFD_SUPPORTS_PLUGINS
-
 #include <assert.h>
 #ifdef HAVE_DLFCN_H
 #include <dlfcn.h>
@@ -1032,4 +1030,3 @@ const bfd_target plugin_vec =
 
   NULL				/* backend_data.  */
 };
-#endif /* BFD_SUPPORTS_PLUGINS */
diff --git a/bfd/plugin.h b/bfd/plugin.h
index d981c517996..d78186ba7f6 100644
--- a/bfd/plugin.h
+++ b/bfd/plugin.h
@@ -23,6 +23,7 @@
 
 struct ld_plugin_input_file;
 
+#if BFD_SUPPORTS_PLUGINS
 void bfd_plugin_set_program_name (const char *);
 int bfd_plugin_open_input (bfd *, struct ld_plugin_input_file *);
 void bfd_plugin_set_plugin (const char *);
@@ -30,5 +31,47 @@ bool bfd_plugin_target_p (const bfd_target *);
 bool bfd_link_plugin_object_p (bfd *);
 void register_ld_plugin_object_p (bfd_cleanup (*object_p) (bfd *, bool));
 void bfd_plugin_close_file_descriptor (bfd *, int);
+#else
+static inline void
+bfd_plugin_set_program_name (const char *name ATTRIBUTE_UNUSED)
+{
+}
+
+static inline int
+bfd_plugin_open_input (bfd *ibfd ATTRIBUTE_UNUSED,
+		       struct ld_plugin_input_file *file ATTRIBUTE_UNUSED)
+{
+  return 0;
+}
+
+static inline void
+bfd_plugin_set_plugin (const char *p ATTRIBUTE_UNUSED)
+{
+}
+
+static inline bool
+bfd_plugin_target_p (const bfd_target *target ATTRIBUTE_UNUSED)
+{
+  return false;
+}
+
+static inline bool
+bfd_link_plugin_object_p (bfd *abfd ATTRIBUTE_UNUSED)
+{
+  return false;
+}
+
+static inline void
+register_ld_plugin_object_p
+  (bfd_cleanup (*object_p) (bfd *, bool) ATTRIBUTE_UNUSED)
+{
+}
+
+static inline void
+bfd_plugin_close_file_descriptor (bfd *abfd ATTRIBUTE_UNUSED,
+				  int fd ATTRIBUTE_UNUSED)
+{
+}
+#endif
 
 #endif
diff --git a/bfd/targets.c b/bfd/targets.c
index a7b0450a005..46c0178ae05 100644
--- a/bfd/targets.c
+++ b/bfd/targets.c
@@ -1556,8 +1556,12 @@ bfd_find_target (const char *target_name, bfd *abfd)
   else
     targname = getenv ("GNUTARGET");
 
-  /* This is safe; the vector cannot be null.  */
-  if (targname == NULL || strcmp (targname, "default") == 0)
+  /* This is safe; the vector cannot be null.  Use the default target if
+     the target name is "plugin" and plugin is disabled.  */
+  if (targname == NULL
+      || strcmp (targname, "default") == 0
+      || (!bfd_plugin_enabled ()
+	  && strcmp (targname, "plugin") == 0))
     {
       if (bfd_default_vector[0] != NULL)
 	target = bfd_default_vector[0];
diff --git a/bfd/xtensa-dynconfig.c b/bfd/xtensa-dynconfig.c
index 89053f7976a..eb04b9d7e88 100644
--- a/bfd/xtensa-dynconfig.c
+++ b/bfd/xtensa-dynconfig.c
@@ -69,43 +69,44 @@ const void *xtensa_load_config (const char *name ATTRIBUTE_UNUSED,
 				const void *no_name_def ATTRIBUTE_UNUSED)
 {
   static int init;
-#if BFD_SUPPORTS_PLUGINS
-  static void *handle;
-  void *p;
-
-  if (!init)
+  if (bfd_plugin_enabled ())
     {
-      const char *path = getenv (CONFIG_ENV_NAME);
+      static void *handle;
+      void *p;
 
-      init = 1;
-      if (!path)
-	return no_plugin_def;
-      handle = dlopen (path, RTLD_LAZY);
-      if (!handle)
+      if (!init)
 	{
-	  _bfd_error_handler (_("%s is defined but could not be loaded: %s"),
-			      CONFIG_ENV_NAME, dlerror ());
-	  abort ();
+	  const char *path = getenv (CONFIG_ENV_NAME);
+
+	  init = 1;
+	  if (!path)
+	    return no_plugin_def;
+	  handle = dlopen (path, RTLD_LAZY);
+	  if (!handle)
+	    {
+	      _bfd_error_handler (_("%s is defined but could not be loaded: %s"),
+				  CONFIG_ENV_NAME, dlerror ());
+	      abort ();
+	    }
+	}
+      else if (!handle)
+	{
+	  return no_plugin_def;
 	}
-    }
-  else if (!handle)
-    {
-      return no_plugin_def;
-    }
 
-  p = dlsym (handle, name);
-  if (!p)
-    {
-      if (no_name_def)
-	return no_name_def;
+      p = dlsym (handle, name);
+      if (!p)
+	{
+	  if (no_name_def)
+	    return no_name_def;
 
-      _bfd_error_handler (_("%s is loaded but symbol \"%s\" is not found: %s"),
-			  CONFIG_ENV_NAME, name, dlerror ());
-      abort ();
+	  _bfd_error_handler (_("%s is loaded but symbol \"%s\" is not found: %s"),
+			      CONFIG_ENV_NAME, name, dlerror ());
+	  abort ();
+	}
+      return p;
     }
-  return p;
-#else
-  if (!init)
+  else if (!init)
     {
       const char *path = getenv (CONFIG_ENV_NAME);
 
@@ -118,7 +119,6 @@ const void *xtensa_load_config (const char *name ATTRIBUTE_UNUSED,
 	}
     }
   return no_plugin_def;
-#endif
 }
 
 XTENSA_CONFIG_INSTANCE_LIST;
diff --git a/binutils/ar.c b/binutils/ar.c
index 79f40db991c..647fd894642 100644
--- a/binutils/ar.c
+++ b/binutils/ar.c
@@ -32,9 +32,7 @@
 #include "arsup.h"
 #include "filenames.h"
 #include "binemul.h"
-#if BFD_SUPPORTS_PLUGINS
 #include "plugin.h"
-#endif
 
 #ifdef __GO32___
 #define EXT_NAME_LEN 3		/* Bufflen of addition to name if it's MS-DOS.  */
@@ -144,12 +142,6 @@ static int show_version = 0;
 
 static int show_help = 0;
 
-#if BFD_SUPPORTS_PLUGINS
-static const char *plugin_target = "plugin";
-#else
-static const char *plugin_target = NULL;
-#endif
-
 static const char *target = NULL;
 
 enum long_option_numbers
@@ -276,18 +268,18 @@ usage (int help)
 {
   FILE *s;
 
-#if BFD_SUPPORTS_PLUGINS
-  /* xgettext:c-format */
-  const char *command_line
-    = _("Usage: %s [emulation options] [-]{dmpqrstx}[abcDfilMNoOPsSTuvV]"
-	" [--plugin <name>] [member-name] [count] archive-file file...\n");
+  const char *command_line;
+  if (bfd_plugin_enabled ())
+    /* xgettext:c-format */
+    command_line
+      = _("Usage: %s [emulation options] [-]{dmpqrstx}[abcDfilMNoOPsSTuvV]"
+	  " [--plugin <name>] [member-name] [count] archive-file file...\n");
+  else
+    /* xgettext:c-format */
+    command_line
+      = _("Usage: %s [emulation options] [-]{dmpqrstx}[abcDfilMNoOPsSTuvV]"
+	  " [member-name] [count] archive-file file...\n");
 
-#else
-  /* xgettext:c-format */
-  const char *command_line
-    = _("Usage: %s [emulation options] [-]{dmpqrstx}[abcDfilMNoOPsSTuvV]"
-	" [member-name] [count] archive-file file...\n");
-#endif
   s = help ? stdout : stderr;
 
   fprintf (s, command_line, program_name);
@@ -339,10 +331,11 @@ usage (int help)
   fprintf (s, _("  --output=DIRNAME - specify the output directory for extraction operations\n"));
   fprintf (s, _("  --record-libdeps=<text> - specify the dependencies of this library\n"));
   fprintf (s, _("  --thin       - make a thin archive\n"));
-#if BFD_SUPPORTS_PLUGINS
-  fprintf (s, _(" optional:\n"));
-  fprintf (s, _("  --plugin <p> - load the specified plugin\n"));
-#endif
+  if (bfd_plugin_enabled ())
+    {
+      fprintf (s, _(" optional:\n"));
+      fprintf (s, _("  --plugin <p> - load the specified plugin\n"));
+    }
 
   ar_emul_usage (s);
 
@@ -366,10 +359,9 @@ ranlib_usage (int help)
   fprintf (s, _(" Generate an index to speed access to archives\n"));
   fprintf (s, _(" The options are:\n\
   @<file>                      Read options from <file>\n"));
-#if BFD_SUPPORTS_PLUGINS
-  fprintf (s, _("\
+  if (bfd_plugin_enabled ())
+    fprintf (s, _("\
   --plugin <name>              Load the specified plugin\n"));
-#endif
   if (DEFAULT_AR_DETERMINISTIC)
     fprintf (s, _("\
   -D                           Use zero for symbol map timestamp (default)\n\
@@ -596,12 +588,9 @@ decode_options (int argc, char **argv)
           deterministic = false;
           break;
 	case OPTION_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
-	  fprintf (stderr, _("sorry - this program has been built without plugin support\n"));
-	  xexit (1);
-#endif
 	  break;
 	case OPTION_TARGET:
 	  target = optarg;
@@ -671,12 +660,9 @@ ranlib_main (int argc, char **argv)
 
 	  /* PR binutils/13493: Support plugins.  */
 	case OPTION_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
-	  fprintf (stderr, _("sorry - this program has been built without plugin support\n"));
-	  xexit (1);
-#endif
 	  break;
 	}
     }
@@ -727,9 +713,7 @@ main (int argc, char **argv)
   program_name = argv[0];
   xmalloc_set_program_name (program_name);
   bfd_set_error_program_name (program_name);
-#if BFD_SUPPORTS_PLUGINS
   bfd_plugin_set_program_name (program_name);
-#endif
 
   expandargv (&argc, &argv);
 
@@ -884,7 +868,7 @@ main (int argc, char **argv)
 	  if (! bfd_make_readable (libdeps_bfd))
 	    fatal (_("Cannot make libdeps object readable."));
 
-	  if (bfd_find_target (plugin_target, libdeps_bfd) == NULL)
+	  if (bfd_find_target ("plugin", libdeps_bfd) == NULL)
 	    fatal (_("Cannot reset libdeps record type."));
 
 	  /* Insert our libdeps record in 2nd slot of the list of files
@@ -974,7 +958,6 @@ open_inarch (const char *archive_filename, const char *file)
   bfd *arch;
   char **matching;
   const char *arch_target = target;
-  const struct bfd_target *plugin_vec;
 
   bfd_set_error (bfd_error_no_error);
 
@@ -1064,21 +1047,12 @@ open_inarch (const char *archive_filename, const char *file)
 	}
     }
 
-  /* We didn't open the archive using plugin_target, because the
-     plugin bfd_target does not support archives.  Select
-     plugin_target now for elements so that we can recognise LTO IR
-     files and read IR symbols for use in the archive map.  */
-  plugin_vec = NULL;
-  if (!target && plugin_target)
-    plugin_vec = bfd_find_target (plugin_target, NULL);
-
   /* Open all the archive contents.  */
   last_one = &(arch->archive_next);
   for (next_one = bfd_openr_next_archived_file (arch, NULL);
        next_one;
        next_one = bfd_openr_next_archived_file (arch, next_one))
     {
-      set_plugin_target (next_one, plugin_vec);
       *last_one = next_one;
       last_one = &next_one->archive_next;
     }
@@ -1570,9 +1544,8 @@ replace_members (bfd *arch, char **files_to_move, bool quick)
 		    }
 		  else
 		    {
-		      const char *targ = target ? target : plugin_target;
 		      replaced = ar_emul_replace (after_bfd, *files_to_move,
-						  targ, verbose);
+						  target, verbose);
 		    }
 		  if (replaced)
 		    {
@@ -1598,8 +1571,7 @@ replace_members (bfd *arch, char **files_to_move, bool quick)
 	}
       else
         {
-	  const char *targ = target ? target : plugin_target;
-	  changed |= ar_emul_append (after_bfd, *files_to_move, targ,
+	  changed |= ar_emul_append (after_bfd, *files_to_move, target,
 				     verbose, make_thin_archive);
 	}
 
diff --git a/binutils/arsup.c b/binutils/arsup.c
index e71c860e9e1..c7b65642607 100644
--- a/binutils/arsup.c
+++ b/binutils/arsup.c
@@ -41,12 +41,6 @@ static char *temp_name;
 static int temp_fd;
 static FILE *outfile;
 
-#if BFD_SUPPORTS_PLUGINS
-static const char *plugin_target = "plugin";
-#else
-static const char *plugin_target = NULL;
-#endif
-
 static void
 map_over_list (bfd *arch, void (*function) (bfd *, bfd *), struct list *list)
 {
@@ -203,15 +197,8 @@ ar_open (char *name, int t)
 	  ptr = &(obfd->archive_head);
 	  element = bfd_openr_next_archived_file (ibfd, NULL);
 
-#if BFD_SUPPORTS_PLUGINS
-	  const struct bfd_target *plugin_vec
-	    = bfd_find_target (plugin_target, NULL);
-#endif
 	  while (element)
 	    {
-#if BFD_SUPPORTS_PLUGINS
-	      set_plugin_target (element, plugin_vec);
-#endif
 	      *ptr = element;
 	      ptr = &element->archive_next;
 	      element = bfd_openr_next_archived_file (ibfd, element);
@@ -270,7 +257,7 @@ ar_addmod (struct list *list)
 	{
 	  bfd *abfd;
 
-	  abfd = bfd_openr (list->name, plugin_target);
+	  abfd = bfd_openr (list->name, NULL);
 	  if (!abfd)
 	    {
 	      fprintf (stderr, _("%s: can't open file %s\n"),
@@ -397,7 +384,7 @@ ar_replace (struct list *list)
 	      if (FILENAME_CMP (bfd_get_filename (member), list->name) == 0)
 		{
 		  /* Found the one to replace.  */
-		  bfd *abfd = bfd_openr (list->name, plugin_target);
+		  bfd *abfd = bfd_openr (list->name, NULL);
 
 		  if (!abfd)
 		    {
@@ -421,7 +408,7 @@ ar_replace (struct list *list)
 
 	  if (!found)
 	    {
-	      bfd *abfd = bfd_openr (list->name, plugin_target);
+	      bfd *abfd = bfd_openr (list->name, NULL);
 
 	      fprintf (stderr,_("%s: can't find module file %s\n"),
 		       program_name, list->name);
diff --git a/binutils/bucomm.h b/binutils/bucomm.h
index 54f54d74286..9815e71f2cb 100644
--- a/binutils/bucomm.h
+++ b/binutils/bucomm.h
@@ -84,19 +84,4 @@ extern int smart_rename (const char *, const char *, int,
   ((*res) = (a), (*res) *= (b), (b) != 0 && (*res) / (b) != (a))
 #endif
 
-/* Change ABFD target vector to TARG.  ABFD is an archive element.
-   TARG is plugin_vec, or NULL if plugins are not supported.  */
-static inline void
-set_plugin_target (bfd *abfd, const struct bfd_target *targ)
-{
-  /* Don't change the target for archives like pdb that handle
-     elements specially, as detected by my_archive being NULL.  */
-  if (abfd->my_archive && targ)
-    {
-      abfd->xvec = targ;
-      /* Don't fail if the element isn't recognised by the plugin.  */
-      abfd->target_defaulted = true;
-    }
-}
-
 #endif /* _BUCOMM_H */
diff --git a/binutils/nm.c b/binutils/nm.c
index 130b6e6015e..dce9207f44f 100644
--- a/binutils/nm.c
+++ b/binutils/nm.c
@@ -37,9 +37,7 @@
 #include "bucomm.h"
 #include "demanguse.h"
 #include "safe-ctype.h"
-#if BFD_SUPPORTS_PLUGINS
 #include "plugin.h"
-#endif
 
 #ifndef streq
 #define streq(a,b) (strcmp ((a),(b)) == 0)
@@ -222,11 +220,6 @@ static char other_format[] = "%02x";
 static char desc_format[] = "%04x";
 
 static char *target = NULL;
-#if BFD_SUPPORTS_PLUGINS
-static const char *plugin_target = "plugin";
-#else
-static const char *plugin_target = NULL;
-#endif
 
 typedef enum unicode_display_type
 {
@@ -344,10 +337,9 @@ usage (FILE *stream, int status)
   -P, --portability      Same as --format=posix\n"));
   fprintf (stream, _("\
   -r, --reverse-sort     Reverse the sense of the sort\n"));
-#if BFD_SUPPORTS_PLUGINS
-  fprintf (stream, _("\
+  if (bfd_plugin_enabled ())
+    fprintf (stream, _("\
       --plugin NAME      Load the specified plugin\n"));
-#endif
   fprintf (stream, _("\
   -S, --print-size       Print size of defined symbols\n"));
   fprintf (stream, _("\
@@ -803,9 +795,7 @@ filter_symbols (bfd *abfd, bool is_dynamic, void *minisyms,
 	continue;
 
       if (bfd_lto_slim_symbol_p (abfd, sym->name)
-#if BFD_SUPPORTS_PLUGINS
 	  && !bfd_plugin_target_p (abfd->xvec)
-#endif
 	  && report_plugin_err)
 	{
 	  report_plugin_err = false;
@@ -1489,10 +1479,7 @@ display_rel_file (bfd *abfd, bfd *archive_bfd)
   /* lto_type is set to lto_non_ir_object when a bfd is loaded with a
      compiler LTO plugin.  */
   if (bfd_get_lto_type (abfd) == lto_slim_ir_object
-#if BFD_SUPPORTS_PLUGINS
-      && !bfd_plugin_target_p (abfd->xvec)
-#endif
-     )
+      && !bfd_plugin_target_p (abfd->xvec))
     {
       report_plugin_err = false;
       non_fatal (_("%s: plugin needed to handle lto object"),
@@ -1601,14 +1588,6 @@ display_archive (bfd *file)
   if (print_armap)
     print_symdef_entry (file);
 
-  /* We didn't open the archive using plugin_target, because the
-     plugin bfd_target does not support archives.  Select
-     plugin_target now for elements so that we can recognise LTO IR
-     files and print IR symbols.  */
-  const struct bfd_target *plugin_vec = NULL;
-  if (!target && plugin_target)
-    plugin_vec = bfd_find_target (plugin_target, NULL);
-
   bfd *last_arfile = NULL;
   for (;;)
     {
@@ -1626,8 +1605,6 @@ display_archive (bfd *file)
       if (last_arfile != NULL)
 	bfd_close (last_arfile);
 
-      set_plugin_target (arfile, plugin_vec);
-
       char **matching;
       if (bfd_check_format_matches (arfile, bfd_object, &matching))
 	{
@@ -1660,7 +1637,7 @@ display_file (char *filename)
   if (get_file_size (filename) < 1)
     return false;
 
-  file = bfd_openr (filename, target ? target : plugin_target);
+  file = bfd_openr (filename, target);
   if (file == NULL)
     {
       bfd_nonfatal (filename);
@@ -2003,9 +1980,7 @@ main (int argc, char **argv)
   program_name = *argv;
   xmalloc_set_program_name (program_name);
   bfd_set_error_program_name (program_name);
-#if BFD_SUPPORTS_PLUGINS
   bfd_plugin_set_program_name (program_name);
-#endif
 
   expandargv (&argc, &argv);
 
@@ -2152,11 +2127,9 @@ main (int argc, char **argv)
 	  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 OPTION_IFUNC_CHARS:
diff --git a/binutils/objcopy.c b/binutils/objcopy.c
index d88422ee748..f22eddfaa78 100644
--- a/binutils/objcopy.c
+++ b/binutils/objcopy.c
@@ -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,
@@ -3795,15 +3790,7 @@ copy_archive (bfd *ibfd, bfd *obfd, const char *output_target,
 	  if (preserve_dates && stat_status == 0)
 	    set_times (output_name, &buf);
 
-	  /* Open the newly created output file and attach to our
-	     list.  We must enable the plugin target here in order to
-	     read IR symbols for the archive map.  */
-	  const char *targ = output_target;
-#if BFD_SUPPORTS_PLUGINS
-	  if (!force_output_target)
-	    targ = "plugin";
-#endif
-	  output_element = bfd_openr (output_name, targ);
+	  output_element = bfd_openr (output_name, output_target);
 
 	  list->obfd = output_element;
 
@@ -3997,8 +3984,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
@@ -4007,7 +3993,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)
@@ -4057,11 +4042,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,
@@ -4906,9 +4889,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)
@@ -5001,11 +4982,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.  */
@@ -5051,7 +5030,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.
@@ -5061,7 +5039,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
diff --git a/ld/ldfile.c b/ld/ldfile.c
index ce81fdc266f..bed04fbf9eb 100644
--- a/ld/ldfile.c
+++ b/ld/ldfile.c
@@ -36,9 +36,7 @@
 #include "filenames.h"
 #include <fnmatch.h>
 #include "same-inode.h"
-#if BFD_SUPPORTS_PLUGINS
 #include "plugin.h"
-#endif /* BFD_SUPPORTS_PLUGINS */
 
 bool ldfile_assumed_script = false;
 const char *ldfile_output_machine_name = "";
@@ -366,9 +364,7 @@ ldfile_try_open_bfd (const char *attempt,
     }
 
   /* PR 30568: Do not track lto generated temporary object files.  */
-#if BFD_SUPPORTS_PLUGINS
   if (!entry->flags.lto_output)
-#endif
     track_dependency_files (attempt);
 
   /* Linker needs to decompress sections.  */
@@ -377,10 +373,8 @@ ldfile_try_open_bfd (const char *attempt,
   /* This is a linker input BFD.  */
   entry->the_bfd->is_linker_input = 1;
 
-#if BFD_SUPPORTS_PLUGINS
   if (entry->flags.lto_output)
     entry->the_bfd->lto_output = 1;
-#endif
 
   /* If we are searching for this file, see if the architecture is
      compatible with the output file.  If it isn't, keep searching.
@@ -518,7 +512,6 @@ ldfile_try_open_bfd (const char *attempt,
 	}
     }
  success:
-#if BFD_SUPPORTS_PLUGINS
   /* If plugins are active, they get first chance to claim
      any successfully-opened input file.  We skip archives
      here; the plugin wants us to offer it the individual
@@ -534,7 +527,6 @@ ldfile_try_open_bfd (const char *attempt,
     plugin_maybe_claim (entry);
   else
     cmdline_check_object_only_section (entry->the_bfd, false);
-#endif /* BFD_SUPPORTS_PLUGINS */
 
   /* It opened OK, the format checked out, and the plugins have had
      their chance to claim it, so this is success.  */
diff --git a/ld/ldlang.c b/ld/ldlang.c
index fc7a7d2ced6..35ee931c960 100644
--- a/ld/ldlang.c
+++ b/ld/ldlang.c
@@ -44,9 +44,7 @@
 #include "elf-bfd.h"
 #include "bfdver.h"
 #include <errno.h>
-#if BFD_SUPPORTS_PLUGINS
 #include "plugin.h"
-#endif
 
 #ifndef offsetof
 #define offsetof(TYPE, MEMBER) ((size_t) & (((TYPE*) 0)->MEMBER))
@@ -3626,10 +3624,8 @@ enum open_bfd_mode
     OPEN_BFD_FORCE = 1,
     OPEN_BFD_RESCAN = 2
   };
-#if BFD_SUPPORTS_PLUGINS
 static lang_input_statement_type *plugin_insert = NULL;
 static struct bfd_link_hash_entry *plugin_undefs = NULL;
-#endif
 
 static void
 open_input_bfds (lang_statement_union_type *s,
@@ -3659,9 +3655,7 @@ open_input_bfds (lang_statement_union_type *s,
 	case lang_group_statement_enum:
 	  {
 	    struct bfd_link_hash_entry *undefs;
-#if BFD_SUPPORTS_PLUGINS
 	    lang_input_statement_type *plugin_insert_save;
-#endif
 
 	    /* We must continually search the entries in the group
 	       until no new symbols are added to the list of undefined
@@ -3669,21 +3663,16 @@ open_input_bfds (lang_statement_union_type *s,
 
 	    do
 	      {
-#if BFD_SUPPORTS_PLUGINS
 		plugin_insert_save = plugin_insert;
-#endif
 		undefs = link_info.hash->undefs_tail;
 		open_input_bfds (s->group_statement.children.head, os,
 				 mode | OPEN_BFD_FORCE);
 	      }
 	    while (undefs != link_info.hash->undefs_tail
-#if BFD_SUPPORTS_PLUGINS
 		   /* Objects inserted by a plugin, which are loaded
 		      before we hit this loop, may have added new
 		      undefs.  */
-		   || (plugin_insert != plugin_insert_save && plugin_undefs)
-#endif
-		   );
+		   || (plugin_insert != plugin_insert_save && plugin_undefs));
 	  }
 	  break;
 	case lang_target_statement_enum:
@@ -3704,10 +3693,8 @@ open_input_bfds (lang_statement_union_type *s,
 		 has been loaded already.  Do the same for a rescan.
 		 Likewise reload --as-needed shared libs.  */
 	      if (mode != OPEN_BFD_NORMAL
-#if BFD_SUPPORTS_PLUGINS
 		  && ((mode & OPEN_BFD_RESCAN) == 0
 		      || plugin_insert == NULL)
-#endif
 		  && s->input_statement.flags.loaded
 		  && (abfd = s->input_statement.the_bfd) != NULL
 		  && ((bfd_get_format (abfd) == bfd_archive
@@ -3751,12 +3738,10 @@ open_input_bfds (lang_statement_union_type *s,
 		    }
 		}
 	    }
-#if BFD_SUPPORTS_PLUGINS
 	  /* If we have found the point at which a plugin added new
 	     files, clear plugin_insert to enable archive rescan.  */
 	  if (&s->input_statement == plugin_insert)
 	    plugin_insert = NULL;
-#endif
 	  break;
 	case lang_assignment_statement_enum:
 	  if (s->assignment_statement.exp->type.node_class != etree_assert)
@@ -7342,11 +7327,9 @@ lang_check (void)
        file != NULL;
        file = file->next)
     {
-#if BFD_SUPPORTS_PLUGINS
       /* Don't check format of files claimed by plugin.  */
       if (file->flags.claimed)
 	continue;
-#endif /* BFD_SUPPORTS_PLUGINS */
       input_bfd = file->the_bfd;
       compatible
 	= bfd_arch_get_compatible (input_bfd, link_info.output_bfd,
@@ -7873,10 +7856,8 @@ lang_gc_sections (void)
       LANG_FOR_EACH_INPUT_STATEMENT (f)
 	{
 	  asection *sec;
-#if BFD_SUPPORTS_PLUGINS
 	  if (f->flags.claimed)
 	    continue;
-#endif
 	  for (sec = f->the_bfd->sections; sec != NULL; sec = sec->next)
 	    if ((sec->flags & SEC_DEBUGGING) == 0
 		|| strcmp (sec->name, ".stabstr") != 0)
@@ -8020,7 +8001,6 @@ lang_relax_sections (bool need_layout)
     }
 }
 
-#if BFD_SUPPORTS_PLUGINS
 /* Find the insert point for the plugin's replacement files.  We
    place them after the first claimed real object file, or if the
    first claimed object is an archive member, after the last real
@@ -8148,7 +8128,6 @@ find_next_input_statement (lang_statement_union_type **s)
     }
   return s;
 }
-#endif /* BFD_SUPPORTS_PLUGINS */
 
 /* Insert SRCLIST into DESTLIST after given element by chaining
    on FIELD as the next-pointer.  (Counterintuitively does not need
@@ -8324,7 +8303,6 @@ lang_process (void)
 
   ldemul_before_plugin_all_symbols_read ();
 
-#if BFD_SUPPORTS_PLUGINS
   if (link_info.lto_plugin_active)
     {
       lang_statement_list_type added;
@@ -8435,9 +8413,7 @@ lang_process (void)
 	    }
 	}
     }
-  else
-#endif /* BFD_SUPPORTS_PLUGINS */
-    if (bfd_link_relocatable (&link_info))
+  else if (bfd_link_relocatable (&link_info))
     {
       /* Check if .gnu_object_only section should be created.  */
       bfd *p;
@@ -10692,6 +10668,9 @@ cmdline_add_object_only_section (bfd_byte *contents, size_t size)
       goto loser;
     }
 
+  /* This is a linker input BFD.  */
+  ibfd->is_linker_input = 1;
+
   if (!bfd_check_format_matches (ibfd, bfd_object, &matching))
     {
       err = bfd_errmsg (bfd_get_error ());
diff --git a/ld/ldlang.h b/ld/ldlang.h
index 8d905f04742..a9607bef765 100644
--- a/ld/ldlang.h
+++ b/ld/ldlang.h
@@ -287,7 +287,6 @@ struct lang_input_statement_flags
   /* Set if reloading an archive or --as-needed lib.  */
   unsigned int reload : 1;
 
-#if BFD_SUPPORTS_PLUGINS
   /* Set if the file was claimed by a plugin.  */
   unsigned int claimed : 1;
 
@@ -296,7 +295,6 @@ struct lang_input_statement_flags
 
   /* Set if added by the lto plugin add_input_file callback.  */
   unsigned int lto_output : 1;
-#endif /* BFD_SUPPORTS_PLUGINS */
 
   /* Head of list of pushed flags.  */
   struct lang_input_statement_flags *pushed;
diff --git a/ld/ldlex.h b/ld/ldlex.h
index 815da76a4c0..d0c2e5d6db8 100644
--- a/ld/ldlex.h
+++ b/ld/ldlex.h
@@ -146,11 +146,9 @@ enum option_values
   OPTION_WARN_ALTERNATE_EM,
   OPTION_REDUCE_MEMORY_OVERHEADS,
   OPTION_MAX_CACHE_SIZE,
-#if BFD_SUPPORTS_PLUGINS
   OPTION_PLUGIN,
   OPTION_PLUGIN_OPT,
   OPTION_PLUGIN_SAVE_TEMPS,
-#endif /* BFD_SUPPORTS_PLUGINS */
   OPTION_DEFAULT_SCRIPT,
   OPTION_PRINT_OUTPUT_FORMAT,
   OPTION_PRINT_SYSROOT,
diff --git a/ld/ldmain.c b/ld/ldmain.c
index 13b8e3dce9d..157f205671e 100644
--- a/ld/ldmain.c
+++ b/ld/ldmain.c
@@ -40,9 +40,7 @@
 #include "ldfile.h"
 #include "ldemul.h"
 #include "ldctor.h"
-#if BFD_SUPPORTS_PLUGINS
 #include "plugin.h"
-#endif /* BFD_SUPPORTS_PLUGINS */
 
 /* Somewhere above, sys/stat.h got included.  */
 #if !defined(S_ISDIR) && defined(S_IFDIR)
@@ -227,13 +225,11 @@ ld_cleanup (void)
       inext = ibfd->link.next;
       bfd_close_all_done (ibfd);
     }
-#if BFD_SUPPORTS_PLUGINS
   /* Note - we do not call ld_plugin_start (PHASE_PLUGINS) here as this
      function is only called when the linker is exiting - ie after any
      stats may have been reported, and potentially in the middle of a
      phase where we have already started recording plugin stats.  */
   plugin_call_cleanup ();
-#endif
   if (output_filename && delete_output_file_on_failure)
     unlink_if_ordinary (output_filename);
 }
@@ -724,12 +720,10 @@ main (int argc, char **argv)
 
   ld_stop_phase (PHASE_PARSE);
   
-#if BFD_SUPPORTS_PLUGINS
   ld_start_phase (PHASE_PLUGINS);
   /* Now all the plugin arguments have been gathered, we can load them.  */
   plugin_load_plugins ();
   ld_stop_phase (PHASE_PLUGINS);
-#endif /* BFD_SUPPORTS_PLUGINS */
 
   ld_start_phase (PHASE_PARSE);
 
@@ -1307,7 +1301,6 @@ add_archive_element (struct bfd_link_info *info,
      (if enabled) may possibly alter it to point to a replacement
      BFD, but we still want to output the original BFD filename.  */
   orig_input = *input;
-#if BFD_SUPPORTS_PLUGINS
   /* Don't claim a fat IR object if no IR object should be claimed.  */
   if (link_info.lto_plugin_active
       && (!no_more_claiming
@@ -1336,7 +1329,6 @@ add_archive_element (struct bfd_link_info *info,
     }
   else
     cmdline_check_object_only_section (input->the_bfd, false);
-#endif /* BFD_SUPPORTS_PLUGINS */
 
   if (link_info.input_bfds_tail == &input->the_bfd->link.next
       || input->the_bfd->link.next != NULL)
diff --git a/ld/lexsup.c b/ld/lexsup.c
index bde20465835..5cb77992733 100644
--- a/ld/lexsup.c
+++ b/ld/lexsup.c
@@ -41,9 +41,7 @@
 #include "ldver.h"
 #include "ldemul.h"
 #include "demangle.h"
-#if BFD_SUPPORTS_PLUGINS
 #include "plugin.h"
-#endif /* BFD_SUPPORTS_PLUGINS */
 
 #ifndef PATH_SEPARATOR
 #if defined (__MSDOS__) || (defined (_WIN32) && ! defined (__CYGWIN32__))
@@ -182,7 +180,6 @@ static const struct ld_option ld_options[] =
     'O', NULL, N_("Optimize output file"), ONE_DASH },
   { {"out-implib", required_argument, NULL, OPTION_OUT_IMPLIB},
     '\0', N_("FILE"), N_("Generate import library"), TWO_DASHES },
-#if BFD_SUPPORTS_PLUGINS
   { {"plugin", required_argument, NULL, OPTION_PLUGIN},
     '\0', N_("PLUGIN"), N_("Load named plugin"), ONE_DASH },
   { {"plugin-opt", required_argument, NULL, OPTION_PLUGIN_OPT},
@@ -196,12 +193,6 @@ static const struct ld_option ld_options[] =
   { {"flto-partition=", required_argument, NULL, OPTION_IGNORE},
     '\0', NULL, N_("Ignored for GCC LTO option compatibility"),
     ONE_DASH },
-#else
-  { {"plugin", required_argument, NULL, OPTION_IGNORE},
-    '\0', N_("PLUGIN"), N_("Load named plugin (ignored)"), ONE_DASH },
-  { {"plugin-opt", required_argument, NULL, OPTION_IGNORE},
-    '\0', N_("ARG"), N_("Send arg to last-loaded plugin (ignored)"), ONE_DASH },
-#endif /* BFD_SUPPORTS_PLUGINS */
   { {"fuse-ld=", required_argument, NULL, OPTION_IGNORE},
     '\0', NULL, N_("Ignored for GCC linker option compatibility"),
     ONE_DASH },
@@ -1213,18 +1204,18 @@ parse_args (unsigned argc, char **argv)
 	case OPTION_PRINT_OUTPUT_FORMAT:
 	  command_line.print_output_format = true;
 	  break;
-#if BFD_SUPPORTS_PLUGINS
 	case OPTION_PLUGIN:
-	  plugin_opt_plugin (optarg);
+	  if (bfd_plugin_enabled ())
+	    plugin_opt_plugin (optarg);
 	  break;
 	case OPTION_PLUGIN_OPT:
-	  if (plugin_opt_plugin_arg (optarg))
+	  if (bfd_plugin_enabled ()
+	      && plugin_opt_plugin_arg (optarg))
 	    fatal (_("%P: bad -plugin-opt option\n"));
 	  break;
 	case OPTION_PLUGIN_SAVE_TEMPS:
 	  config.plugin_save_temps = true;
 	  break;
-#endif /* BFD_SUPPORTS_PLUGINS */
 	case 'q':
 	  link_info.emitrelocations = true;
 	  break;
@@ -1543,9 +1534,7 @@ parse_args (unsigned argc, char **argv)
 	      int level ATTRIBUTE_UNUSED = strtoul (optarg, &end, 0);
 	      if (*end)
 		fatal (_("%P: invalid number `%s'\n"), optarg);
-#if BFD_SUPPORTS_PLUGINS
 	      report_plugin_symbols = level > 1;
-#endif /* BFD_SUPPORTS_PLUGINS */
 	    }
 	  break;
 	case 'v':
@@ -2474,7 +2463,13 @@ help (void)
 	  for (; len < 30; len++)
 	    putchar (' ');
 
-	  printf ("%s\n", _(ld_options[i].doc));
+	  printf ("%s", _(ld_options[i].doc));
+	  if ((ld_options[i].opt.val == OPTION_PLUGIN
+	       || ld_options[i].opt.val == OPTION_PLUGIN_OPT)
+	      && !bfd_plugin_enabled ())
+	    puts (_(" (ignored)"));
+	  else
+	    putchar ('\n');
 	}
     }
   printf (_("  @FILE"));
diff --git a/ld/libdep_plugin.c b/ld/libdep_plugin.c
index 605d5976aa3..e1dbf1895b2 100644
--- a/ld/libdep_plugin.c
+++ b/ld/libdep_plugin.c
@@ -20,7 +20,6 @@
 
 #include "sysdep.h"
 #include "bfd.h"
-#if BFD_SUPPORTS_PLUGINS
 #include "plugin-api.h"
 
 #include <ctype.h> /* For isspace.  */
@@ -340,4 +339,3 @@ onload (struct ld_plugin_tv *tv)
   fflush (NULL);
   return LDPS_OK;
 }
-#endif /* BFD_SUPPORTS_PLUGINS */
diff --git a/ld/plugin.c b/ld/plugin.c
index dedd1a08b30..08d827c1ec7 100644
--- a/ld/plugin.c
+++ b/ld/plugin.c
@@ -21,7 +21,6 @@
 #include "sysdep.h"
 #include "libiberty.h"
 #include "bfd.h"
-#if BFD_SUPPORTS_PLUGINS
 #include "bfdlink.h"
 #include "bfdver.h"
 #include "ctf-api.h"
@@ -1536,4 +1535,3 @@ plugin_notice (struct bfd_link_info *info,
 				      abfd, section, value, flags);
   return true;
 }
-#endif /* BFD_SUPPORTS_PLUGINS */
diff --git a/ld/testplug.c b/ld/testplug.c
index ffb7787e969..e5c3ec2055b 100644
--- a/ld/testplug.c
+++ b/ld/testplug.c
@@ -20,7 +20,6 @@
 
 #include "sysdep.h"
 #include "bfd.h"
-#if BFD_SUPPORTS_PLUGINS
 #include "plugin-api.h"
 /* For ARRAY_SIZE macro only - we don't link the library itself.  */
 #include "libiberty.h"
@@ -673,4 +672,3 @@ oncleanup (void)
   fflush (NULL);
   return cleanup_ret;
 }
-#endif /* BFD_SUPPORTS_PLUGINS */
diff --git a/ld/testplug2.c b/ld/testplug2.c
index f7923831942..788d1930e3a 100644
--- a/ld/testplug2.c
+++ b/ld/testplug2.c
@@ -21,7 +21,6 @@
 
 #include "sysdep.h"
 #include "bfd.h"
-#if BFD_SUPPORTS_PLUGINS
 #include "plugin-api.h"
 #include "filenames.h"
 /* For ARRAY_SIZE macro only - we don't link the library itself.  */
@@ -675,4 +674,3 @@ oncleanup (void)
   fflush (NULL);
   return cleanup_ret;
 }
-#endif /* BFD_SUPPORTS_PLUGINS */
diff --git a/ld/testplug3.c b/ld/testplug3.c
index 03735340af7..91a9661e8be 100644
--- a/ld/testplug3.c
+++ b/ld/testplug3.c
@@ -21,7 +21,6 @@
 
 #include "sysdep.h"
 #include "bfd.h"
-#if BFD_SUPPORTS_PLUGINS
 #include "plugin-api.h"
 #include "filenames.h"
 /* For ARRAY_SIZE macro only - we don't link the library itself.  */
@@ -633,4 +632,3 @@ oncleanup (void)
   fflush (NULL);
   return cleanup_ret;
 }
-#endif /* BFD_SUPPORTS_PLUGINS */
diff --git a/ld/testplug4.c b/ld/testplug4.c
index 71eaf593ad3..21a2cd119d3 100644
--- a/ld/testplug4.c
+++ b/ld/testplug4.c
@@ -21,7 +21,6 @@
 
 #include "sysdep.h"
 #include "bfd.h"
-#if BFD_SUPPORTS_PLUGINS
 #include "plugin-api.h"
 #include "filenames.h"
 /* For ARRAY_SIZE macro only - we don't link the library itself.  */
@@ -681,4 +680,3 @@ oncleanup (void)
   fflush (NULL);
   return cleanup_ret;
 }
-#endif /* BFD_SUPPORTS_PLUGINS */
-- 
2.50.1



More information about the Binutils mailing list