[v2,3/4] Don't check the plugin target twice

Message ID 20240905111452.2554-4-hjl.tools@gmail.com
State New
Headers
Series Add lto and none-lto input support for ld -r |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_binutils_check--master-aarch64 success Test passed
linaro-tcwg-bot/tcwg_binutils_check--master-arm success Test passed

Commit Message

H.J. Lu Sept. 5, 2024, 11:14 a.m. UTC
  If the plugin target is explicitly specified when a BFD file is opened,
don't check it twice.

	* format.c: Include "plugin-api.h" and "plugin.h" if
	BFD_SUPPORTS_PLUGINS is defined.
	(bfd_check_format_matches): Don't check the plugin target twice
	if the plugin target is explicitly specified.
---
 bfd/format.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
  

Patch

diff --git a/bfd/format.c b/bfd/format.c
index 59089fb818e..949fbd72000 100644
--- a/bfd/format.c
+++ b/bfd/format.c
@@ -46,6 +46,10 @@  SUBSECTION
 #include "sysdep.h"
 #include "bfd.h"
 #include "libbfd.h"
+#if BFD_SUPPORTS_PLUGINS
+#include "plugin-api.h"
+#include "plugin.h"
+#endif
 
 /* IMPORT from targets.c.  */
 extern const size_t _bfd_target_vector_entries;
@@ -406,9 +410,6 @@  bool
 bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
 {
   extern const bfd_target binary_vec;
-#if BFD_SUPPORTS_PLUGINS
-  extern const bfd_target plugin_vec;
-#endif
   const bfd_target * const *target;
   const bfd_target **matching_vector = NULL;
   const bfd_target *save_targ, *right_targ, *ar_right_targ, *match_targ;
@@ -512,11 +513,18 @@  bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
 	 check the default target twice.  */
       if (*target == &binary_vec
 #if BFD_SUPPORTS_PLUGINS
-	  || (match_count != 0 && *target == &plugin_vec)
+	  || (match_count != 0 && bfd_plugin_target_p (*target))
 #endif
 	  || (!abfd->target_defaulted && *target == save_targ))
 	continue;
 
+#if BFD_SUPPORTS_PLUGINS
+      /* If the plugin target is explicitly specified when a BFD file
+	 is opened, don't check it twice.  */
+      if (bfd_plugin_specified_p () && bfd_plugin_target_p (*target))
+	continue;
+#endif
+
       /* If we already tried a match, the bfd is modified and may
 	 have sections attached, which will confuse the next
 	 _bfd_check_format call.  */
@@ -545,7 +553,7 @@  bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
 	     lowest priority; objects both handled by a plugin and
 	     with an underlying object format will be claimed
 	     separately by the plugin.  */
-	  if (*target == &plugin_vec)
+	  if (bfd_plugin_target_p (*target))
 	    match_priority = (*target)->match_priority;
 #endif