The new hook allows the linker plugin to distinguish calls to
claim_file_handler that know the object is being used by the linker
(from ldmain.c:add_archive_element), from calls that don't know it's
being used by the linker (from elf_link_is_defined_archive_symbol); in
the latter case, the plugin should avoid including the unused LTO archive
members in linker output.  To get the proper support for archives with
LTO common symbols, the linker fix for

https://sourceware.org/bugzilla/show_bug.cgi?id=32083

is required.

        PR lto/116361
        * lto-plugin.c (claim_file_handler_v2): Include the LTO object
        only if it is known to be used for link output.

Signed-off-by: H.J. Lu <hjl.to...@gmail.com>
---
 lto-plugin/lto-plugin.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/lto-plugin/lto-plugin.c b/lto-plugin/lto-plugin.c
index 152648338b9..453561daece 100644
--- a/lto-plugin/lto-plugin.c
+++ b/lto-plugin/lto-plugin.c
@@ -1286,13 +1286,17 @@ claim_file_handler_v2 (const struct 
ld_plugin_input_file *file, int *claimed,
                              lto_file.symtab.syms);
       check (status == LDPS_OK, LDPL_FATAL, "could not add symbols");
 
-      LOCK_SECTION;
-      num_claimed_files++;
-      claimed_files =
-       xrealloc (claimed_files,
-                 num_claimed_files * sizeof (struct plugin_file_info));
-      claimed_files[num_claimed_files - 1] = lto_file;
-      UNLOCK_SECTION;
+      /* Include it only if it is known to be used for link output.  */
+      if (known_used)
+       {
+         LOCK_SECTION;
+         num_claimed_files++;
+         claimed_files =
+           xrealloc (claimed_files,
+                     num_claimed_files * sizeof (struct plugin_file_info));
+         claimed_files[num_claimed_files - 1] = lto_file;
+         UNLOCK_SECTION;
+       }
 
       *claimed = 1;
     }
-- 
2.46.0

Reply via email to