[PATCH] ld: Call plugin hooks only if they are available

Howard Chu hyc@symas.com
Wed Dec 16 18:34:01 GMT 2020


H.J. Lu wrote:
> On Wed, Dec 16, 2020 at 3:16 AM Nick Clifton via Binutils
> <binutils@sourceware.org> wrote:
>>
>> Hi Howard,
>>
>>>> Why not just make the new plugin disable itself if the host tool
>>>> doesn't provide the all_symbols_read entry point?
>>>
>>> Yeah, that'd be fine too. Just noop/silently exit if entry points are missing.
>>> I can write that up if folks agree it's better.
>>
>> Please do.
>>
>> It turns out that my proposed fix breaks the LTO plugin, so it is a no-go. :-(
>>
> 
> I am going to check this in if there are no objections today.
> 
diff --git a/ld/libdep_plugin.c b/ld/libdep_plugin.c
index 2a7fdc4d0b..37ad7c7f97 100644
--- a/ld/libdep_plugin.c
+++ b/ld/libdep_plugin.c
@@ -346,20 +346,10 @@ onload (struct ld_plugin_tv *tv)
       return LDPS_ERR;
     }
   (*tv_register_claim_file) (onclaim_file);
-  if (!tv_register_all_symbols_read)
-    {
-      TV_MESSAGE (LDPL_FATAL, "No register_all_symbols_read hook");
-      fflush (NULL);
-      return LDPS_ERR;
-    }
-  (*tv_register_all_symbols_read) (onall_symbols_read);
-  if (!tv_register_cleanup)
-    {
-      TV_MESSAGE (LDPL_FATAL, "No register_cleanup hook");
-      fflush (NULL);
-      return LDPS_ERR;
-    }
-  (*tv_register_cleanup) (oncleanup);
+  if (tv_register_all_symbols_read)
+    (*tv_register_all_symbols_read) (onall_symbols_read);
+  if (tv_register_cleanup)
+    (*tv_register_cleanup) (oncleanup);
   fflush (NULL);
   return LDPS_OK;
 }

The plugin shouldn't register any hooks at all, if any of these aren't available.
There's no point in doing the register_claim_file, that will just be wasted work.

-- 
  -- Howard Chu
  CTO, Symas Corp.           http://www.symas.com
  Director, Highland Sun     http://highlandsun.com/hyc/
  Chief Architect, OpenLDAP  http://www.openldap.org/project/


More information about the Binutils mailing list