aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2025-08-18 06:07:39 -0700
committerH.J. Lu <hjl.tools@gmail.com>2025-08-18 17:05:43 -0700
commit7e432e93f8aaa14368476cf5eae9d55c18a266fb (patch)
treeb08b57e1ec6d5ef19b2bc7af29913dac29b810df
parent74201a32082c061a3b966fa3189e97eefbd87c2b (diff)
downloadbinutils-7e432e93f8aaa14368476cf5eae9d55c18a266fb.zip
binutils-7e432e93f8aaa14368476cf5eae9d55c18a266fb.tar.gz
binutils-7e432e93f8aaa14368476cf5eae9d55c18a266fb.tar.bz2
Limit BFD_SUPPORTS_PLUGINS check to plugin.h and targets.cHEADmaster
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>
-rw-r--r--bfd/archive.c6
-rw-r--r--bfd/bfd-in.h8
-rw-r--r--bfd/bfd-in2.h8
-rw-r--r--bfd/elflink.c7
-rw-r--r--bfd/format.c22
-rw-r--r--bfd/plugin.c10
-rw-r--r--bfd/plugin.h63
-rw-r--r--bfd/xtensa-dynconfig.c62
-rw-r--r--binutils/ar.c54
-rw-r--r--binutils/nm.c22
-rw-r--r--binutils/objcopy.c25
-rw-r--r--ld/ldfile.c8
-rw-r--r--ld/ldlang.c28
-rw-r--r--ld/ldlang.h2
-rw-r--r--ld/ldlex.h2
-rw-r--r--ld/ldmain.c8
-rw-r--r--ld/lexsup.c27
-rw-r--r--ld/libdep_plugin.c2
-rw-r--r--ld/plugin.c2
-rw-r--r--ld/testplug.c2
-rw-r--r--ld/testplug2.c2
-rw-r--r--ld/testplug3.c2
-rw-r--r--ld/testplug4.c2
23 files changed, 161 insertions, 213 deletions
diff --git a/bfd/archive.c b/bfd/archive.c
index 16b725b..d2a9fd1 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 df5568e..ea2d2cb 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 b013ef9..5e7c6dd 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 7b03754..f6c0c04 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 81e8f1c..81f29c5 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
}
/*
@@ -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
diff --git a/bfd/plugin.c b/bfd/plugin.c
index 2be384d..5e5a0b7 100644
--- a/bfd/plugin.c
+++ b/bfd/plugin.c
@@ -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
diff --git a/bfd/plugin.h b/bfd/plugin.h
index d981c51..f16c45c 100644
--- a/bfd/plugin.h
+++ b/bfd/plugin.h
@@ -23,12 +23,73 @@
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
diff --git a/bfd/xtensa-dynconfig.c b/bfd/xtensa-dynconfig.c
index 89053f7..eb04b9d 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 a159ac1..afe8633 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. */
@@ -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);
diff --git a/binutils/nm.c b/binutils/nm.c
index 8098ed3..dce9207 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)
@@ -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:
diff --git a/binutils/objcopy.c b/binutils/objcopy.c
index d8648eb..51d87d6 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,
@@ -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
diff --git a/ld/ldfile.c b/ld/ldfile.c
index ce81fdc..bed04fb 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 048c848..8ba95b0 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))
@@ -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;
diff --git a/ld/ldlang.h b/ld/ldlang.h
index 8d905f0..a9607be 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 815da76..d0c2e5d 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 13b8e3d..157f205 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 bde2046..5cb7799 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 605d597..e1dbf18 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 dedd1a0..08d827c 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 ffb7787..e5c3ec2 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 f792383..788d193 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 0373534..91a9661 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 71eaf59..21a2cd1 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 */