[PATCH] libbfd: Always compile plugin.c into libbfd

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


On Thu, Aug 7, 2025 at 6:42 PM Alan Modra <amodra@gmail.com> wrote:
>
> On Thu, Aug 07, 2025 at 06:10:38PM -0700, H.J. Lu wrote:
> > On Thu, Aug 7, 2025 at 4:29 PM Alan Modra <amodra@gmail.com> wrote:
> > >
> > > On Thu, Aug 07, 2025 at 06:47:18AM -0700, H.J. Lu wrote:
> > > > On Thu, Aug 7, 2025 at 6:37 AM H.J. Lu <hjl.tools@gmail.com> wrote:
> > > > Checking BFD_SUPPORTS_PLUGINS all over the place only benefits
> > > > very small percentage of binutils users while everyone else pays the price.
> > >
> > > Your patch silently breaks ar compatibility for aix, hpux and vms.
> > > Problems like that are why I think we are better off making it
> > > possible to conditionally compile in plugin support.
> > >
> >
> > My patch shouldn't change binutils behavior at all.  It only changes
> > the BFD_SUPPORTS_PLUGINS check from build time to run time.
> > If --disable-plugins is used, plugin is disabled at run time.  Probably
> > I should replace
> >
> > #define BFD_SUPPORTS_PLUGINS @supports_plugins@
> >
> > with
> >
> > static inline bool
> > bfd_plugin_enabled (void)
> > {
> >   return @supports_plugins@;
> > }
> >
> > My patch won't change aix, hpux and vms.
>
> But it did.  I checked.  x86_64 host --target=rs6000-aix7.2 build.
>

I sent out the v2 patch with the following changes:

diff --git a/bfd/plugin.c b/bfd/plugin.c
index fea5529780b..9da45ed7882 100644
--- a/bfd/plugin.c
+++ b/bfd/plugin.c
@@ -777,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.  */

@@ -1004,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.  */
diff --git a/binutils/ar.c b/binutils/ar.c
index 9d2ace54d7f..39d3d133c26 100644
--- a/binutils/ar.c
+++ b/binutils/ar.c
@@ -146,8 +146,6 @@ static int show_version = 0;

 static int show_help = 0;

-static const char *plugin_target = "plugin";
-
 static const char *target = NULL;

 enum long_option_numbers
@@ -874,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
@@ -966,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/nm.c b/binutils/nm.c
index 9b585929a97..a6507edb4a6 100644
--- a/binutils/nm.c
+++ b/binutils/nm.c
@@ -220,7 +220,6 @@ static char other_format[] = "%02x";
 static char desc_format[] = "%04x";

 static char *target = NULL;
-static const char *plugin_target = "plugin";

 typedef enum unicode_display_type
 {
@@ -1638,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);
diff --git a/binutils/objcopy.c b/binutils/objcopy.c
index fcd2dd418db..bb5fe17e0f5 100644
--- a/binutils/objcopy.c
+++ b/binutils/objcopy.c
@@ -3898,7 +3898,7 @@ copy_file (const char *input_filename, const
char *output_filename, int ofd,
     }

   /* Enable LTO plugin in strip.  */
-  if (is_strip && !target)
+  if (is_strip && !target && bfd_plugin_enabled ())
     target = "plugin";

   /* To allow us to do "strip *" without dying on the first


-- 
H.J.


More information about the Binutils mailing list