]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Limit BFD_SUPPORTS_PLUGINS check to plugin.h and targets.c
authorH.J. Lu <hjl.tools@gmail.com>
Mon, 18 Aug 2025 13:07:39 +0000 (06:07 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Tue, 19 Aug 2025 00:05:43 +0000 (17:05 -0700)
Minimize the BFD_SUPPORTS_PLUGINS check to make code more readable and
maintainable by:

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

bfd/

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

ar/

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

ld/

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

Co-Authored-By: Alan Modra <amodra@gmail.com>
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
23 files changed:
bfd/archive.c
bfd/bfd-in.h
bfd/bfd-in2.h
bfd/elflink.c
bfd/format.c
bfd/plugin.c
bfd/plugin.h
bfd/xtensa-dynconfig.c
binutils/ar.c
binutils/nm.c
binutils/objcopy.c
ld/ldfile.c
ld/ldlang.c
ld/ldlang.h
ld/ldlex.h
ld/ldmain.c
ld/lexsup.c
ld/libdep_plugin.c
ld/plugin.c
ld/testplug.c
ld/testplug2.c
ld/testplug3.c
ld/testplug4.c

index 16b725b9958456cd6bc7865c2822ec5d349be2cb..d2a9fd171a7e76c9a063e1d805bd950fb3f370dc 100644 (file)
@@ -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;
index df5568e9639cfadd0a30bb4eda6deea032bf9e69..ea2d2cb0010a720eb7a4d76210e8d5bf26955596 100644 (file)
@@ -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;
+}
+
index b013ef954da34a0b3c5a826e057691b0873efe25..5e7c6ddf1eef4a9e012bd2c016ec9c1fe25e00fa 100644 (file)
@@ -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);
 
index 7b0375406ac5d9105df630b4e346f2d6ee738264..f6c0c04e82e0c190fb9a8cf18b42f4895ab46733 100644 (file)
@@ -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.  */
index 81e8f1c411f02db1ece2d44be8d151efa4b0b2bc..81f29c5f54f266e8f2ab6de6efc0076bf7f2b6a2 100644 (file)
@@ -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
 }
 
 /*
@@ -520,19 +516,17 @@ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
      have target_defaulted false.  Failing that, bfd_find_target will
      have chosen a default target, and target_defaulted will be true.  */
   fail_targ = NULL;
-#if BFD_SUPPORTS_PLUGINS
-  if (abfd->format == bfd_object
+  if (bfd_plugin_enabled ()
+      && abfd->format == bfd_object
       && abfd->target_defaulted
       && !abfd->is_linker_input
       && abfd->plugin_format != bfd_plugin_no)
     {
-      extern const bfd_target plugin_vec;
-
       if (bfd_seek (abfd, 0, SEEK_SET) != 0)
        goto err_ret;
 
-      BFD_ASSERT (save_targ != &plugin_vec);
-      abfd->xvec = &plugin_vec;
+      BFD_ASSERT (save_targ != bfd_plugin_vec ());
+      abfd->xvec = bfd_plugin_vec ();
       bfd_set_error (bfd_error_no_error);
       cleanup = BFD_SEND_FMT (abfd, _bfd_check_format, (abfd));
       if (cleanup)
@@ -548,7 +542,6 @@ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
      The test can be removed if desired.  */
   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;
@@ -604,12 +597,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
index 2be384d8ef556f5ccdb871daa2f5ce7d0f3efc12..5e5a0b70a04174d143869dc6c72136ae25f23b58 100644 (file)
@@ -658,16 +658,6 @@ bfd_link_plugin_object_p (bfd *abfd)
   return false;
 }
 
-extern const bfd_target plugin_vec;
-
-/* Return TRUE if TARGET is a pointer to plugin_vec.  */
-
-bool
-bfd_plugin_target_p (const bfd_target *target)
-{
-  return target == &plugin_vec;
-}
-
 /* Register OBJECT_P to be used by bfd_plugin_object_p.  */
 
 void
index d981c51799628d4eb0fffa1c57ec3e099675d639..f16c45c8fa01b7541906ce2667028440cd3e0a04 100644 (file)
 
 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 *);
-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);
 
+static inline const bfd_target *
+bfd_plugin_vec (void)
+{
+  extern const bfd_target plugin_vec;
+  return &plugin_vec;
+}
+
+static inline bool
+bfd_plugin_target_p (const bfd_target *target)
+{
+  return target == bfd_plugin_vec ();
+}
+#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_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)
+{
+}
+
+static inline const bfd_target *
+bfd_plugin_vec (void)
+{
+  return NULL;
+}
+
+static inline bool
+bfd_plugin_target_p (const bfd_target *target ATTRIBUTE_UNUSED)
+{
+  return false;
+}
+#endif
+
 #endif
index 89053f7976a406f041c5c87f2418cb7e33a7e42c..eb04b9d7e88facca8b6c38bb1ec5cd5b218cd679 100644 (file)
@@ -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;
index a159ac10ce5a0ec89580bcaf94321961ce2cb7cf..afe86330b6d205c94b377745be3c2a2d18246a0f 100644 (file)
@@ -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.  */
@@ -270,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);
@@ -333,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);
 
@@ -360,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\
@@ -590,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;
@@ -665,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;
        }
     }
@@ -721,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);
 
index 8098ed31e7326b4727ee3e76b02a12f5e66b9aca..dce9207f44fac9d416e0206dc67c6e42d0f7f190 100644 (file)
@@ -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)
@@ -339,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, _("\
@@ -798,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;
@@ -1484,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"),
@@ -1988,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);
 
@@ -2137,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:
index d8648ebbe91b7c9a1279979b7c399c77bb3257b3..51d87d6d359915612f5bb8a0e5e3c24bd729b778 100644 (file)
@@ -30,9 +30,7 @@
 #include "coff/internal.h"
 #include "libcoff.h"
 #include "safe-ctype.h"
-#if BFD_SUPPORTS_PLUGINS
 #include "plugin.h"
-#endif
 
 /* FIXME: See bfd/peXXigen.c for why we include an architecture specific
    header in generic PE code.  */
@@ -763,10 +761,9 @@ strip_usage (FILE *stream, int exit_status)
      --info                        List object formats & architectures supported\n\
   -o <file>                        Place stripped output into <file>\n\
 "));
-#if BFD_SUPPORTS_PLUGINS
-  fprintf (stream, _("\
+  if (bfd_plugin_enabled ())
+    fprintf (stream, _("\
       --plugin NAME                Load the specified plugin\n"));
-#endif
 
   list_supported_targets (program_name, stream);
   if (REPORT_BUGS_TO[0] && exit_status == 0)
@@ -3757,11 +3754,9 @@ copy_archive (bfd *ibfd, bfd *obfd, const char *output_target,
          goto cleanup_and_exit;
        }
 
-#if BFD_SUPPORTS_PLUGINS
       /* Copy slim LTO IR file as unknown object.  */
       if (this_element->lto_type == lto_slim_ir_object)
        ok_object = false;
-#endif
       if (ok_object)
        {
          ok = copy_object (this_element, output_element, input_arch,
@@ -3991,8 +3986,7 @@ copy_file (const char *input_filename, const char *output_filename, int ofd,
            free (obj_matching);
          obj_error = bfd_error_no_error;
        }
-#if BFD_SUPPORTS_PLUGINS
-      else
+      else if (bfd_plugin_enabled ())
        {
          /* This is for LLVM bytecode files, which are not ELF objects.
             Since objcopy/strip does nothing with these files except
@@ -4001,7 +3995,6 @@ copy_file (const char *input_filename, const char *output_filename, int ofd,
          ibfd->plugin_format = bfd_plugin_unknown;
          ok_plugin = bfd_check_format (ibfd, bfd_object);
        }
-#endif
     }
 
   if (obj_error == bfd_error_file_ambiguously_recognized)
@@ -4051,11 +4044,9 @@ copy_file (const char *input_filename, const char *output_filename, int ofd,
          return;
        }
 
-#if BFD_SUPPORTS_PLUGINS
       /* Copy slim LTO IR file as unknown file.  */
       if (ibfd->lto_type == lto_slim_ir_object)
        ok_object = false;
-#endif
       if (ok_object
          ? !copy_object (ibfd, obfd, input_arch, target_defaulted)
          : !copy_unknown_file (ibfd, obfd,
@@ -4900,9 +4891,7 @@ strip_main (int argc, char *argv[])
   char *output_file = NULL;
   bool merge_notes_set = false;
 
-#if BFD_SUPPORTS_PLUGINS
   bfd_plugin_set_program_name (argv[0]);
-#endif
 
   while ((c = getopt_long (argc, argv, "I:O:F:K:MN:R:o:sSpdgxXHhVvwDU",
                           strip_options, (int *) 0)) != EOF)
@@ -4995,11 +4984,9 @@ strip_main (int argc, char *argv[])
          keep_section_symbols = true;
          break;
        case OPTION_PLUGIN:     /* --plugin */
-#if BFD_SUPPORTS_PLUGINS
+         if (!bfd_plugin_enabled ())
+           fatal (_("sorry - this program has been built without plugin support\n"));
          bfd_plugin_set_plugin (optarg);
-#else
-         fatal (_("sorry - this program has been built without plugin support\n"));
-#endif
          break;
        case 0:
          /* We've been given a long option.  */
@@ -5045,7 +5032,6 @@ strip_main (int argc, char *argv[])
   if (output_target == NULL)
     output_target = input_target;
 
-#if BFD_SUPPORTS_PLUGINS
   /* Check if all GCC LTO sections should be removed, assuming all LTO
      sections will be removed with -R .gnu.lto_.*.  Remove .gnu.lto_.*
      sections will also remove .gnu.debuglto_.* sections.
@@ -5055,7 +5041,6 @@ strip_main (int argc, char *argv[])
      debug sections.  */
   if (!find_section_list (".gnu.lto_.*", false, SECTION_CONTEXT_REMOVE))
     find_section_list (".gnu.debuglto_*", true, SECTION_CONTEXT_KEEP);
-#endif
 
   i = optind;
   if (i == argc
index ce81fdc266f873f92bdc73ed9d09a21e4b4d8815..bed04fbf9eb9b395dcef02460c98dd3c6241388c 100644 (file)
@@ -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.  */
index 048c8480786954dea3409f7088b58be9267a6c63..8ba95b04e2306b79b3105df25f588ff8812d6aff 100644 (file)
@@ -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))
@@ -3629,10 +3627,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,
@@ -3666,9 +3662,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
@@ -3678,22 +3672,17 @@ 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,
                                 nested_group_count_p);
              }
            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));
 
            --*nested_group_count_p;
          }
@@ -3720,10 +3709,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
@@ -3767,12 +3754,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)
@@ -7358,11 +7343,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,
@@ -7889,10 +7872,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)
@@ -8036,7 +8017,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
@@ -8164,7 +8144,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
@@ -8343,7 +8322,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;
@@ -8456,9 +8434,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;
index 8d905f047423260df46744b294ef6fb48af5603b..a9607bef765324e9b498d6d643ec0852f96b949e 100644 (file)
@@ -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;
index 815da76a4c0ee4879db2b9ab45c63c296158a32d..d0c2e5d6db80221aca04d9e3dc55cb9628cbeceb 100644 (file)
@@ -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,
index 13b8e3dce9d6438b1343639dddcb66f8528eb5af..157f205671efa1715f5eb119de0e3d24512fc4a0 100644 (file)
@@ -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)
index bde20465835a09c03af0d43023e6c96b5c7ca42e..5cb77992733a1a2fd241ae3f52cabda881f220f2 100644 (file)
@@ -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"));
index 605d5976aa3b08cea05c5372f973cba523568e96..e1dbf1895b2cc2b9f582535c10889700b71f7a95 100644 (file)
@@ -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 */
index dedd1a08b30d3f4671b563681b054f9c1fdbf088..08d827c1ec7849f581dd21fcb68edec221cd8328 100644 (file)
@@ -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 */
index ffb7787e969eff080be6f0426d303ef60619b21a..e5c3ec2055b6821bf172b042fdd11d287f661558 100644 (file)
@@ -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 */
index f79238319422c14450b101940176ef1d123ec0a1..788d1930e3a2c5da81c1e45cb5434be0aee00fc0 100644 (file)
@@ -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 */
index 03735340af7bddfadcfbf0d4a6ca7bfc340a69a7..91a9661e8be1f5664a30c8e0a889cde6a1ce65f6 100644 (file)
@@ -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 */
index 71eaf593ad30f88be86d87ed32f3d77d2ec5988b..21a2cd119d3a96774c467d3ba490151f0e8b712e 100644 (file)
@@ -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 */