This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [PATCH] Fix DT_NEEDED search with --as-needed libraries (PR ld/2721)
On Fri, Jun 02, 2006 at 11:38:00PM +0930, Alan Modra wrote:
> So.. On to the patch itself. Firstly, I don't see any need for version
> checking a library specified on the command line, so reloading an
> as-needed lib doesn't need to happen inside the "force" loop. Secondly,
> some small changes to the way these functions work will avoid
> Yet Another Variable disease. Something like the following looks
> better to me. Please check that I haven't made some stupid mistake, and
> that this version works on real-world situations!
Yeah, surely looks better.
> @@ -229,12 +229,14 @@ gld${EMULATION_NAME}_stat_needed (lang_i
> const char *suffix;
> const char *soname;
>
> - if (global_found)
> + if (global_found != NULL)
> return;
> if (s->the_bfd == NULL)
> return;
> - if (s->as_needed
> - && (bfd_elf_get_dyn_lib_class (s->the_bfd) & DYN_AS_NEEDED) != 0)
> +
> + /* If this input file was an as-needed entry, and wasn't found to be
> + needed at the stage it was linked, then don't say we have loaded it. */
> + if ((bfd_elf_get_dyn_lib_class (s->the_bfd) & DYN_AS_NEEDED) != 0)
> return;
Does (bfd_elf_get_dyn_lib_class (s->the_bfd) & DYN_AS_NEEDED) != 0 imply
s->as_needed?
> @@ -809,14 +811,11 @@ cat >>e${EMULATION_NAME}.c <<EOF
> static void
> gld${EMULATION_NAME}_check_needed (lang_input_statement_type *s)
> {
> - if (global_found)
> - return;
> -
> - /* If this input file was an as-needed entry, and wasn't found to be
> - needed at the stage it was linked, then don't say we have loaded it. */
> - if (s->as_needed
> - && (s->the_bfd == NULL
> - || (bfd_elf_get_dyn_lib_class (s->the_bfd) & DYN_AS_NEEDED) != 0))
> + /* Stop looking if we've found a loaded lib. */
> + if (global_found != NULL
> + && global_found->the_bfd != NULL
> + && (bfd_elf_get_dyn_lib_class (global_found->the_bfd)
> + & DYN_AS_NEEDED) == 0)
> return;
>
> if (s->filename != NULL)
Can we rely on at most one DYN_AS_NEEDED library matching? Otherwise
it changes from first as needed library wins to last as needed library wins.
Also, if there is some ->the_bfd == NULL library, we'll keep searching, no
matter if it is global_found->as_needed or not.
> @@ -904,9 +903,12 @@ gld${EMULATION_NAME}_after_open (void)
>
> /* See if this file was included in the link explicitly. */
> global_needed = l;
> - global_found = FALSE;
> + global_found = NULL;
> lang_for_each_input_file (gld${EMULATION_NAME}_check_needed);
> - if (global_found)
> + if (global_found != NULL
> + && global_found->the_bfd != NULL
> + && (bfd_elf_get_dyn_lib_class (global_found->the_bfd)
> + & DYN_AS_NEEDED) == 0)
> continue;
Similarly.
> @@ -915,6 +917,13 @@ gld${EMULATION_NAME}_after_open (void)
> if (trace_file_tries)
> info_msg (_("%s needed by %B\n"), l->name, l->by);
>
> + if (global_found != NULL)
> + {
> + nn.name = global_found->filename;
> + if (gld${EMULATION_NAME}_try_needed (&nn, TRUE))
> + continue;
> + }
Can we rely on global_found->filename != NULL?
Jakub