Add startswith function and use it instead of CONST_STRNEQ.
[deliverable/binutils-gdb.git] / bfd / plugin.c
index 9439366f4bf42249b31d718df86955033b9b3b69..d1767b013453d90aae31e6ea4fb78bf1e700c3d4 100644 (file)
@@ -1,5 +1,5 @@
 /* Plugin support for BFD.
-   Copyright (C) 2009-2020 Free Software Foundation, Inc.
+   Copyright (C) 2009-2021 Free Software Foundation, Inc.
 
    This file is part of BFD, the Binary File Descriptor library.
 
@@ -249,17 +249,18 @@ try_claim (bfd *abfd)
   return claimed;
 }
 
-static int
-try_load_plugin (const char *pname,
-                struct plugin_list_entry *plugin_list_iter,
-                bfd *abfd, bfd_boolean build_list_p)
+static bfd_boolean
+try_load_plugin (const char *                pname,
+                struct plugin_list_entry *  plugin_list_iter,
+                bfd *                       abfd,
+                bfd_boolean                 build_list_p)
 {
   void *plugin_handle;
   struct ld_plugin_tv tv[5];
   int i;
   ld_plugin_onload onload;
   enum ld_plugin_status status;
-  int result = 0;
+  bfd_boolean result = FALSE;
 
   /* NB: Each object is independent.  Reuse the previous plugin from
      the last run will lead to wrong result.  */
@@ -273,14 +274,20 @@ try_load_plugin (const char *pname,
   plugin_handle = dlopen (pname, RTLD_NOW);
   if (!plugin_handle)
     {
-      _bfd_error_handler ("%s\n", dlerror ());
-      return 0;
+      /* If we are building a list of viable plugins, then
+        we do not bother the user with the details of any
+        plugins that cannot be loaded.  */
+      if (! build_list_p)
+       _bfd_error_handler ("Failed to load plugin '%s', reason: %s\n",
+                           pname, dlerror ());
+      return FALSE;
     }
 
   if (plugin_list_iter == NULL)
     {
       size_t length_plugin_name = strlen (pname) + 1;
       char *plugin_name = bfd_malloc (length_plugin_name);
+
       if (plugin_name == NULL)
        goto short_circuit;
       plugin_list_iter = bfd_malloc (sizeof *plugin_list_iter);
@@ -341,7 +348,7 @@ try_load_plugin (const char *pname,
     goto short_circuit;
 
   abfd->plugin_format = bfd_plugin_yes;
-  result = 1;
+  result = TRUE;
 
  short_circuit:
   dlclose (plugin_handle);
@@ -445,7 +452,7 @@ build_plugin_list (bfd *abfd)
 
                  full_name = concat (plugin_dir, "/", ent->d_name, NULL);
                  if (stat (full_name, &st) == 0 && S_ISREG (st.st_mode))
-                   try_load_plugin (full_name, NULL, abfd, TRUE);
+                   (void) try_load_plugin (full_name, NULL, abfd, TRUE);
                  free (full_name);
                }
              closedir (d);
@@ -457,7 +464,7 @@ build_plugin_list (bfd *abfd)
   has_plugin_list = plugin_list != NULL;
 }
 
-static int
+static bfd_boolean
 load_plugin (bfd *abfd)
 {
   struct plugin_list_entry *plugin_list_iter;
@@ -466,17 +473,17 @@ load_plugin (bfd *abfd)
     return try_load_plugin (plugin_name, plugin_list, abfd, FALSE);
 
   if (plugin_program_name == NULL)
-    return 0;
+    return FALSE;
 
   build_plugin_list (abfd);
 
   for (plugin_list_iter = plugin_list;
        plugin_list_iter;
        plugin_list_iter = plugin_list_iter->next)
-    if (try_load_plugin (NULL, plugin_list_iter, abfd, FALSE))
-      return 1;
+    if (try_load_plugin (NULL, plugin_list_iter, abfd,FALSE))
+      return TRUE;
 
-  return 0;
+  return FALSE;
 }
 
 
@@ -633,6 +640,8 @@ bfd_plugin_canonicalize_symtab (bfd *abfd,
          if (current_plugin->has_symbol_type)
            switch (syms[i].symbol_type)
              {
+             default:
+               /* FIXME: Should we issue an error here ?  */
              case LDST_UNKNOWN:
                /* What is the best fake section for LDST_UNKNOWN?  */
              case LDST_FUNCTION:
@@ -710,6 +719,7 @@ const bfd_target plugin_vec =
   '/',                         /* ar_pad_char.  */
   15,                          /* ar_max_namelen.  */
   255,                         /* match priority.  */
+  TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols.  */
 
   bfd_getl64, bfd_getl_signed_64, bfd_putl64,
   bfd_getl32, bfd_getl_signed_32, bfd_putl32,
@@ -755,4 +765,4 @@ const bfd_target plugin_vec =
 
   NULL                         /* backend_data.  */
 };
-#endif /* BFD_SUPPORTS_PLUGIN */
+#endif /* BFD_SUPPORTS_PLUGINS */
This page took 0.025871 seconds and 4 git commands to generate.