This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Fix pr13201, --as-needed with -flto
- From: Alan Modra <amodra at gmail dot com>
- To: binutils at sourceware dot org
- Date: Tue, 20 Sep 2011 14:29:20 +0930
- Subject: Fix pr13201, --as-needed with -flto
This fixes a problem with -flto and --as-needed libraries. LTO IR
symbols may not contain any references to symbols in an --as-needed
shared lib, causing the library to be omitted even when the LTO
translated output does contain references. (I believe it is correct
that LTO IR does *not* contain such references.)
PR ld/12301
* ldlang.h (lang_input_statement_type): Add "reload" bitfield.
Clarify comments.
* ldlang.c (new_afile): Init new field.
(load_symbols): Don't call ldlang_add_file when reloading.
(open_input_bfds): Reload as-needed libs during plugin rescan.
Index: ld/ldlang.h
===================================================================
RCS file: /cvs/src/src/ld/ldlang.h,v
retrieving revision 1.99
diff -u -p -r1.99 ldlang.h
--- ld/ldlang.h 16 Sep 2011 01:15:19 -0000 1.99
+++ ld/ldlang.h 20 Sep 2011 02:29:14 -0000
@@ -270,12 +270,13 @@ typedef struct lang_input_statement_stru
/* Whether to search for this entry as a dynamic archive. */
unsigned int dynamic : 1;
- /* Whether DT_NEEDED tags should be added for dynamic libraries in
- DT_NEEDED tags from this entry. */
+ /* Set if a DT_NEEDED tag should be added not just for the dynamic library
+ explicitly given by this entry but also for any dynamic libraries in
+ this entry's needed list. */
unsigned int add_DT_NEEDED_for_dynamic : 1;
- /* Whether this entry should cause a DT_NEEDED tag only when
- satisfying references from regular files, or always. */
+ /* Set if this entry should cause a DT_NEEDED tag only when some
+ regular file references its symbols (ie. --as-needed is in effect). */
unsigned int add_DT_NEEDED_for_regular : 1;
/* Whether to include the entire contents of an archive. */
@@ -295,6 +296,9 @@ typedef struct lang_input_statement_stru
/* Set if the file was claimed from an archive. */
unsigned int claim_archive : 1;
+
+ /* Set if reloading an --as-needed lib. */
+ unsigned int reload : 1;
#endif /* ENABLE_PLUGINS */
} lang_input_statement_type;
Index: ld/ldlang.c
===================================================================
RCS file: /cvs/src/src/ld/ldlang.c,v
retrieving revision 1.377
diff -u -p -r1.377 ldlang.c
--- ld/ldlang.c 16 Sep 2011 01:15:19 -0000 1.377
+++ ld/ldlang.c 20 Sep 2011 02:29:14 -0000
@@ -1133,6 +1133,7 @@ new_afile (const char *name,
#ifdef ENABLE_PLUGINS
p->claimed = FALSE;
p->claim_archive = FALSE;
+ p->reload = FALSE;
#endif /* ENABLE_PLUGINS */
lang_statement_append (&input_file_chain,
@@ -2780,7 +2781,10 @@ load_symbols (lang_input_statement_type
break;
case bfd_object:
- ldlang_add_file (entry);
+#ifdef ENABLE_PLUGINS
+ if (!entry->reload)
+#endif
+ ldlang_add_file (entry);
if (trace_files || trace_file_tries)
info_msg ("%I\n", entry);
break;
@@ -3272,6 +3276,18 @@ open_input_bfds (lang_statement_union_ty
&& bfd_check_format (s->input_statement.the_bfd,
bfd_archive))
s->input_statement.loaded = FALSE;
+#ifdef ENABLE_PLUGINS
+ /* When rescanning, reload --as-needed shared libs. */
+ else if ((mode & OPEN_BFD_RESCAN) != 0
+ && plugin_insert == NULL
+ && s->input_statement.loaded
+ && s->input_statement.add_DT_NEEDED_for_regular
+ && ((s->input_statement.the_bfd->flags) & DYNAMIC) != 0)
+ {
+ s->input_statement.loaded = FALSE;
+ s->input_statement.reload = TRUE;
+ }
+#endif
os_tail = lang_output_section_statement.tail;
lang_list_init (&add);
--
Alan Modra
Australia Development Lab, IBM