This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: Linker does not detect unresolved symbol
- From: Alan Modra <amodra at gmail dot com>
- To: "Stern, Eli" <eli dot stern at ti dot com>
- Cc: "binutils at sourceware dot org" <binutils at sourceware dot org>
- Date: Tue, 26 Jan 2010 01:05:10 +1030
- Subject: Re: Linker does not detect unresolved symbol
- References: <AC090B9732AB2B4DB7FF476E907FE660E49E1225@dnce02.ent.ti.com>
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.
* 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