Linker does not detect unresolved symbol

H.J. Lu hjl.tools@gmail.com
Mon Jan 25 15:07:00 GMT 2010


On Mon, Jan 25, 2010 at 6:35 AM, Alan Modra <amodra@gmail.com> wrote:
> On Mon, Jan 25, 2010 at 12:10:29PM +0100, Stern, Eli wrote:
>> Is this a bug or a misuse of the tools?
>
> A bug.  The code that reports undefined symbols says this:
>
>      /* If we have an undefined symbol reference here then it must have
>         come from a shared library that is being linked in.  (Undefined
>         references in regular files have already been handled).  */
>
> and indeed does not report an error if the symbol is referred to in a
> regular file (! h->ref_regular check a little below the comment).
>
> However, because you are using --gc-sections and the section with the
> reference in the regular file is garbage collected, you don't get a
> report for the reference in the regular object file..
>
> This patch gives you an error, but doesn't report the right reference
> since ld only tracks the first file that references a symbol.

I think we should pass

h->ref_regular ? NULL : h->root.u.undef.abfd

to linker undefined_symbol calback. Otherwise, the linker error is
misleading.


H.J.
---
>        * elflink.c (elf_link_output_extsym): Do not ignore undefined
>        symbols with ref_regular set when gc_sections is active.
>
> Index: bfd/elflink.c
> ===================================================================
> RCS file: /cvs/src/src/bfd/elflink.c,v
> retrieving revision 1.366
> diff -u -p -r1.366 elflink.c
> --- bfd/elflink.c       21 Jan 2010 14:54:40 -0000      1.366
> +++ bfd/elflink.c       25 Jan 2010 14:11:45 -0000
> @@ -8590,7 +8590,7 @@ elf_link_output_extsym (struct elf_link_
>       /* If we are reporting errors for this situation then do so now.  */
>       if (ignore_undef == FALSE
>          && h->ref_dynamic
> -         && ! h->ref_regular
> +         && (!h->ref_regular || finfo->info->gc_sections)
>          && ! elf_link_check_versioned_symbol (finfo->info, bed, h)
>          && finfo->info->unresolved_syms_in_shared_libs != RM_IGNORE)
>        {
>
> --
> Alan Modra
> Australia Development Lab, IBM
>



-- 
H.J.



More information about the Binutils mailing list