[PATCH v2] bfd: Replace BFD_SUPPORTS_PLUGINS with a function

H.J. Lu hjl.tools@gmail.com
Fri Aug 8 03:14:33 GMT 2025


Currently although plugin is used by more than 99% of binutils users,
plugin is enabled and checked at build time by checking a pre-processor
macro, BFD_SUPPORTS_PLUGINS.  It makes code harder to follow and less
maintainable.  Replace BFD_SUPPORTS_PLUGINS with a function:

/* Return true if plugin is enabled.  */

static inline bool
bfd_plugin_enabled (void)
{
  return @supports_plugins@;
}

so that plugin is checked at run time.  Change bfd_plugin_object_p() to
return NULL if plugin isn't enabled.  Add bfd_plugin_archive_p() to return
NULL if plugin isn't enabled.  These make the plugin target disabled at
run time when plugin is disabled at build time.

bfd/

	* Makefile.am (BFD32_LIBS): Add plugin.lo.
	(BFD32_LIBS_CFILES): Add plugin.c.
	* Makefile.in: Regenerated.
	* archive.c: Include plugin.h unconditionally.
	(_bfd_compute_and_write_armap): Remove the BFD_SUPPORTS_PLUGINS
	check.
	* bfd-in.h (BFD_SUPPORTS_PLUGINS): Removed.
	(bfd_plugin_enabled): New.
	* bfd-in2.h: Regenerated.
	* config.in: Likewise.
	* configure: Likewise.
	* configure.ac (tb): Don't append plugin.lo.
	(supports_plugins): Set to true/false.
	* 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.
	* libbfd.h: Regenerated.
	* plugin.c: Remove the BFD_SUPPORTS_PLUGINS check.
	(bfd_plugin_set_program_name): Set plugin_program_name only if
	plugin is enabled.
	(bfd_plugin_object_p): Return NULL if plugin isn't enabled.
	(bfd_plugin_archive_p): New.
	(plugin_vec): Replace bfd_generic_archive_p with
	bfd_plugin_archive_p.
	* targets.c (_bfd_target_vector): Remove the BFD_SUPPORTS_PLUGINS
	check.
	* 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" to bfd_find_target if plugin is enabled.
	(open_inarch): Set target to "plugin" if plugin is enabled.
	* arsup.c (ar_open): Likewise.
	* 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_file): Pass "plugin" to bfd_openr if plugin is enabled.
	(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.
	(lto_sections_removed): Remove the BFD_SUPPORTS_PLUGINS check.
	(strip_usage): Replace the BFD_SUPPORTS_PLUGINS check with the
	bfd_plugin_enabled call.
	(copy_archive): Remove the BFD_SUPPORTS_PLUGINS check.
	(check_format_object): Likewise.
	(copy_file): Likewise.  Set target to "plugin" if plugin is
	enabled.
	(strip_main): Call bfd_plugin_set_program_name unconditionally.
	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.
	* 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/Makefile.am        |  4 +--
 bfd/Makefile.in        |  7 +++--
 bfd/archive.c          |  6 ----
 bfd/bfd-in.h           | 10 +++++--
 bfd/bfd-in2.h          | 10 +++++--
 bfd/configure          |  8 ++---
 bfd/configure.ac       |  8 ++---
 bfd/elflink.c          |  7 +----
 bfd/format.c           | 18 ++---------
 bfd/plugin.c           | 20 +++++++++----
 bfd/targets.c          |  3 +-
 bfd/xtensa-dynconfig.c | 62 +++++++++++++++++++-------------------
 binutils/ar.c          | 68 +++++++++++++++++-------------------------
 binutils/arsup.c       |  8 -----
 binutils/nm.c          | 31 +++++--------------
 binutils/objcopy.c     | 39 +++++-------------------
 ld/ldfile.c            |  8 -----
 ld/ldlang.c            | 28 ++---------------
 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 --
 28 files changed, 132 insertions(+), 264 deletions(-)

diff --git a/bfd/Makefile.am b/bfd/Makefile.am
index 3c3243269f1..b64d3cbb0b1 100644
--- a/bfd/Makefile.am
+++ b/bfd/Makefile.am
@@ -79,7 +79,7 @@ BFD32_LIBS = \
 	coff-bfd.lo compress.lo corefile.lo elf-properties.lo format.lo \
 	hash.lo libbfd.lo linker.lo merge.lo opncls.lo reloc.lo \
 	section.lo simple.lo stab-syms.lo stabs.lo syms.lo targets.lo \
-	binary.lo ihex.lo srec.lo tekhex.lo verilog.lo
+	binary.lo ihex.lo srec.lo tekhex.lo verilog.lo plugin.lo
 
 BFD64_LIBS = archive64.lo
 
@@ -88,7 +88,7 @@ BFD32_LIBS_CFILES = \
 	compress.c corefile.c elf-properties.c format.c hash.c \
 	libbfd.c linker.c merge.c opncls.c reloc.c \
 	section.c simple.c stab-syms.c stabs.c syms.c targets.c \
-	binary.c ihex.c srec.c tekhex.c verilog.c
+	binary.c ihex.c srec.c tekhex.c verilog.c plugin.c
 
 BFD64_LIBS_CFILES = archive64.c
 
diff --git a/bfd/Makefile.in b/bfd/Makefile.in
index 4c259682fd0..13f60cabf77 100644
--- a/bfd/Makefile.in
+++ b/bfd/Makefile.in
@@ -182,7 +182,8 @@ am__objects_1 = archive.lo archures.lo bfd.lo bfdio.lo cache.lo \
 	coff-bfd.lo compress.lo corefile.lo elf-properties.lo \
 	format.lo hash.lo libbfd.lo linker.lo merge.lo opncls.lo \
 	reloc.lo section.lo simple.lo stab-syms.lo stabs.lo syms.lo \
-	targets.lo binary.lo ihex.lo srec.lo tekhex.lo verilog.lo
+	targets.lo binary.lo ihex.lo srec.lo tekhex.lo verilog.lo \
+	plugin.lo
 am_libbfd_la_OBJECTS = $(am__objects_1)
 libbfd_la_OBJECTS = $(am_libbfd_la_OBJECTS)
 AM_V_lt = $(am__v_lt_@AM_V@)
@@ -545,7 +546,7 @@ BFD32_LIBS = \
 	coff-bfd.lo compress.lo corefile.lo elf-properties.lo format.lo \
 	hash.lo libbfd.lo linker.lo merge.lo opncls.lo reloc.lo \
 	section.lo simple.lo stab-syms.lo stabs.lo syms.lo targets.lo \
-	binary.lo ihex.lo srec.lo tekhex.lo verilog.lo
+	binary.lo ihex.lo srec.lo tekhex.lo verilog.lo plugin.lo
 
 BFD64_LIBS = archive64.lo
 BFD32_LIBS_CFILES = \
@@ -553,7 +554,7 @@ BFD32_LIBS_CFILES = \
 	compress.c corefile.c elf-properties.c format.c hash.c \
 	libbfd.c linker.c merge.c opncls.c reloc.c \
 	section.c simple.c stab-syms.c stabs.c syms.c targets.c \
-	binary.c ihex.c srec.c tekhex.c verilog.c
+	binary.c ihex.c srec.c tekhex.c verilog.c plugin.c
 
 BFD64_LIBS_CFILES = archive64.c
 
diff --git a/bfd/archive.c b/bfd/archive.c
index 52d31199fdd..1a5f19fc75e 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;
@@ -2346,9 +2344,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;
@@ -2406,9 +2402,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..a73515b8f20 100644
--- a/bfd/bfd-in.h
+++ b/bfd/bfd-in.h
@@ -60,8 +60,6 @@ extern "C" {
    is error prone, so using this macro is safer.  */
 #define STRING_COMMA_LEN(STR) (STR), (sizeof (STR) - 1)
 
-#define BFD_SUPPORTS_PLUGINS @supports_plugins@
-
 /* The word size used by BFD on the host.  This may be 64 with a 32
    bit target if the host is 64 bit, or if other 64 bit targets have
    been selected with --enable-targets, or if --enable-64-bit-bfd.  */
@@ -159,3 +157,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 @supports_plugins@;
+}
+
diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
index 12512a3962c..f29311f3487 100644
--- a/bfd/bfd-in2.h
+++ b/bfd/bfd-in2.h
@@ -67,8 +67,6 @@ extern "C" {
    is error prone, so using this macro is safer.  */
 #define STRING_COMMA_LEN(STR) (STR), (sizeof (STR) - 1)
 
-#define BFD_SUPPORTS_PLUGINS @supports_plugins@
-
 /* The word size used by BFD on the host.  This may be 64 with a 32
    bit target if the host is 64 bit, or if other 64 bit targets have
    been selected with --enable-targets, or if --enable-64-bit-bfd.  */
@@ -166,6 +164,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 @supports_plugins@;
+}
+
 /* Extracted from libbfd.c.  */
 void *bfd_alloc (bfd *abfd, bfd_size_type wanted);
 
diff --git a/bfd/configure b/bfd/configure
index 28ac5ccfbe5..9e2d642238c 100755
--- a/bfd/configure
+++ b/bfd/configure
@@ -15773,10 +15773,6 @@ do
     fi
 done
 
-if test "$plugins" = "yes"; then
-     tb="$tb plugin.lo"
-fi
-
 # Target architecture .o files.
 # A couple of CPUs use shorter file names to avoid problems on DOS
 # filesystems.
@@ -16846,9 +16842,9 @@ _ACEOF
 fi
 
 if test "$plugins" = "yes"; then
-  supports_plugins=1
+  supports_plugins=true
 else
-  supports_plugins=0
+  supports_plugins=false
 fi
 
 
diff --git a/bfd/configure.ac b/bfd/configure.ac
index 502c526b606..57926353855 100644
--- a/bfd/configure.ac
+++ b/bfd/configure.ac
@@ -697,10 +697,6 @@ do
     fi
 done
 
-if test "$plugins" = "yes"; then
-     tb="$tb plugin.lo"
-fi
-
 # Target architecture .o files.
 # A couple of CPUs use shorter file names to avoid problems on DOS
 # filesystems.
@@ -1000,9 +996,9 @@ if test -n "$TRAD_HEADER"; then
 fi
 
 if test "$plugins" = "yes"; then
-  supports_plugins=1
+  supports_plugins=true
 else
-  supports_plugins=0
+  supports_plugins=false
 fi
 AC_SUBST(supports_plugins)
 AC_SUBST(lt_cv_dlopen_libs)
diff --git a/bfd/elflink.c b/bfd/elflink.c
index cdd58b25fc8..93a98236705 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 fba8d2a3d37..dee3e8fd457 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
@@ -406,7 +403,6 @@ bfd_set_lto_type (bfd *abfd ATTRIBUTE_UNUSED)
 
       abfd->lto_type = type;
     }
-#endif
 }
 
 /*
@@ -500,11 +496,8 @@ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
   /* If the target type was explicitly specified, just check that target.  */
   fail_targ = NULL;
   if (!abfd->target_defaulted
-#if BFD_SUPPORTS_PLUGINS
       && !(abfd->plugin_format == bfd_plugin_no
-	   && bfd_plugin_target_p (save_targ))
-#endif
-      )
+	   && bfd_plugin_target_p (save_targ)))
     {
       if (bfd_seek (abfd, 0, SEEK_SET) != 0)	/* rewind! */
 	goto err_ret;
@@ -518,12 +511,10 @@ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
 	 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;
 
@@ -570,12 +561,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
diff --git a/bfd/plugin.c b/bfd/plugin.c
index 733e7f0f322..9da45ed7882 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>
@@ -151,7 +149,8 @@ static const char *plugin_program_name;
 void
 bfd_plugin_set_program_name (const char *program_name)
 {
-  plugin_program_name = program_name;
+  if (bfd_plugin_enabled ())
+    plugin_program_name = program_name;
 }
 
 static struct plugin_list_entry *plugin_list = NULL;
@@ -762,6 +761,9 @@ load_plugin (bfd *abfd)
 static bfd_cleanup
 bfd_plugin_object_p (bfd *abfd)
 {
+  if (!bfd_plugin_enabled ())
+    return NULL;
+
   /* Since ld_plugin_object_p is called only for linker command-line input
      objects, pass true to ld_plugin_object_p so that the same input IR
      file won't be included twice if the LDPT_REGISTER_CLAIM_FILE_HOOK_V2
@@ -775,6 +777,15 @@ bfd_plugin_object_p (bfd *abfd)
   return abfd->plugin_format == bfd_plugin_yes ? _bfd_no_cleanup : NULL;
 }
 
+static bfd_cleanup
+bfd_plugin_archive_p (bfd *abfd)
+{
+  if (bfd_plugin_enabled ())
+    return bfd_generic_archive_p (abfd);
+
+  return NULL;
+}
+
 /* Copy any private info we understand from the input bfd
    to the output bfd.  */
 
@@ -1002,7 +1013,7 @@ const bfd_target plugin_vec =
   {				/* bfd_check_format.  */
     _bfd_dummy_target,
     bfd_plugin_object_p,
-    bfd_generic_archive_p,
+    bfd_plugin_archive_p,
     _bfd_dummy_target
   },
   {				/* bfd_set_format.  */
@@ -1036,4 +1047,3 @@ const bfd_target plugin_vec =
 
   NULL				/* backend_data.  */
 };
-#endif /* BFD_SUPPORTS_PLUGINS */
diff --git a/bfd/targets.c b/bfd/targets.c
index c2ee9179f37..a6d8def9a1e 100644
--- a/bfd/targets.c
+++ b/bfd/targets.c
@@ -1382,9 +1382,8 @@ static const bfd_target * const _bfd_target_vector[] =
 /* Likewise for ihex.  */
 	&ihex_vec,
 
-#if BFD_SUPPORTS_PLUGINS
+/* Always include plugin.  */
 	&plugin_vec,
-#endif
 
 /* Add any required traditional-core-file-handler.  */
 
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 3cac3f3fb26..39d3d133c26 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.  */
@@ -148,12 +146,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
@@ -280,18 +272,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);
@@ -343,10 +335,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);
 
@@ -370,10 +363,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\
@@ -600,12 +592,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;
@@ -675,12 +664,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;
 	}
     }
@@ -731,9 +717,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);
 
@@ -888,7 +872,9 @@ 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 ((bfd_plugin_enabled ()
+				? "plugin" : NULL),
+			       libdeps_bfd) == NULL)
 	    fatal (_("Cannot reset libdeps record type."));
 
 	  /* Insert our libdeps record in 2nd slot of the list of files
@@ -980,8 +966,8 @@ open_inarch (const char *archive_filename, const char *file)
 
   bfd_set_error (bfd_error_no_error);
 
-  if (target == NULL)
-    target = plugin_target;
+  if (target == NULL && bfd_plugin_enabled ())
+    target = "plugin";
 
   if (stat (archive_filename, &sbuf) != 0)
     {
diff --git a/binutils/arsup.c b/binutils/arsup.c
index 67cbd5c2835..3051ca39d6e 100644
--- a/binutils/arsup.c
+++ b/binutils/arsup.c
@@ -180,11 +180,7 @@ ar_open (char *name, int t)
 	  bfd *element;
 	  bfd *ibfd;
 
-#if BFD_SUPPORTS_PLUGINS	  
 	  ibfd = bfd_openr (name, "plugin");
-#else
-	  ibfd = bfd_openr (name, NULL);
-#endif
 
 	  if (!ibfd)
 	    {
@@ -266,11 +262,7 @@ ar_addmod (struct list *list)
 	{
 	  bfd *abfd;
 
-#if BFD_SUPPORTS_PLUGINS	  
 	  abfd = bfd_openr (list->name, "plugin");
-#else
-	  abfd = bfd_openr (list->name, NULL);
-#endif
 	  if (!abfd)
 	    {
 	      fprintf (stderr, _("%s: can't open file %s\n"),
diff --git a/binutils/nm.c b/binutils/nm.c
index a7f0e9d9409..a6507edb4a6 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"),
@@ -1650,7 +1637,9 @@ 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 ? target : (bfd_plugin_enabled ()
+				       ? "plugin" : NULL));
   if (file == NULL)
     {
       bfd_nonfatal (filename);
@@ -1993,9 +1982,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);
 
@@ -2142,11 +2129,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 654d2b9b44a..bb5fe17e0f5 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.  */
@@ -168,12 +166,8 @@ static struct section_list *change_sections;
 /* TRUE if some sections are to be removed.  */
 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.  */
 static bool sections_copied;
@@ -770,10 +764,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)
@@ -3748,11 +3741,9 @@ copy_archive (bfd *ibfd, bfd *obfd, const char *output_target,
       l->obfd = NULL;
       list = l;
 
-#if BFD_SUPPORTS_PLUGINS
       /* Ignore plugin target if all LTO sections should be removed.  */
       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
@@ -3770,15 +3761,12 @@ copy_archive (bfd *ibfd, bfd *obfd, const char *output_target,
 	  goto cleanup_and_exit;
 	}
 
-#if BFD_SUPPORTS_PLUGINS
       /* Copy LTO IR file as unknown object.  */
       if ((!lto_sections_removed
 	   && this_element->lto_type == lto_slim_ir_object)
 	  || bfd_plugin_target_p (this_element->xvec))
 	ok_object = false;
-      else
-#endif
-      if (ok_object)
+      else if (ok_object)
 	{
 	  ok = copy_object (this_element, output_element, input_arch,
 			    target_defaulted);
@@ -3870,10 +3858,8 @@ copy_archive (bfd *ibfd, bfd *obfd, const char *output_target,
 }
 
 static bool
-check_format_object (bfd *ibfd, char ***obj_matching,
-		     bool no_plugins ATTRIBUTE_UNUSED)
+check_format_object (bfd *ibfd, char ***obj_matching, bool no_plugins)
 {
-#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.  */
@@ -3884,7 +3870,6 @@ check_format_object (bfd *ibfd, char ***obj_matching,
 	return true;
       ibfd->plugin_format = bfd_plugin_unknown;
     }
-#endif
   return bfd_check_format_matches (ibfd, bfd_object, obj_matching);
 }
 
@@ -3912,11 +3897,9 @@ copy_file (const char *input_filename, const char *output_filename, int ofd,
       return;
     }
 
-#if BFD_SUPPORTS_PLUGINS
   /* Enable LTO plugin in strip.  */
-  if (is_strip && !target)
+  if (is_strip && !target && bfd_plugin_enabled ())
     target = "plugin";
-#endif
 
   /* To allow us to do "strip *" without dying on the first
      non-object file, failures are nonfatal.  */
@@ -4041,7 +4024,6 @@ copy_file (const char *input_filename, const char *output_filename, int ofd,
  	  return;
  	}
 
-#if BFD_SUPPORTS_PLUGINS
       if (bfd_plugin_target_p (ibfd->xvec))
 	{
 	  /* Copy LTO IR file as unknown file.  */
@@ -4052,7 +4034,6 @@ copy_file (const char *input_filename, const char *output_filename, int ofd,
 	    status = 1;
 	}
       else
-#endif
 	{
 	  if (! copy_object (ibfd, obfd, input_arch, target_defaulted))
 	    status = 1;
@@ -4924,9 +4905,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)
@@ -5019,11 +4998,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.  */
@@ -5069,7 +5046,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.  LLVM IR
@@ -5084,7 +5060,6 @@ strip_main (int argc, char *argv[])
      debug sections.  */
   if (!lto_sections_removed)
     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 e642c7f6620..ae62c05c36c 100644
--- a/ld/ldfile.c
+++ b/ld/ldfile.c
@@ -35,9 +35,7 @@
 #include "libiberty.h"
 #include "filenames.h"
 #include <fnmatch.h>
-#if BFD_SUPPORTS_PLUGINS
 #include "plugin.h"
-#endif /* BFD_SUPPORTS_PLUGINS */
 
 bool ldfile_assumed_script = false;
 const char *ldfile_output_machine_name = "";
@@ -365,9 +363,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.  */
@@ -376,10 +372,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.
@@ -517,7 +511,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
@@ -533,7 +526,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..3d0cb03c22a 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;
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