This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
RFC: Improve error message for unresolved symbols because of --no-add-needed
- From: Nick Clifton <nickc at redhat dot com>
- To: binutils at sourceware dot org
- Date: Thu, 29 Oct 2009 12:30:55 +0000
- Subject: RFC: Improve error message for unresolved symbols because of --no-add-needed
Hi Guys,
As a follow up to my previous post about changing --add-needed to
-copy-dt-needed-entries, here is a second patch that addresses
another problem with the --no-add-needed option.
The problem in this case is that if an unresolved symbol is defined
in a dynamic library which would have been included via following a
DT_NEEDED link, but which is denied because the user has specified
--no-add-needed on the command line, then a rather unhelpful error
message is generated:
% gcc -Wl,--no-add-needed -o foo1 foo1.o foo2.so -Wl,--rpath-link=.
ld: ./foo3.so: invalid DSO for symbol `foo' definition
Note in this case foo3.so is the dynamic library defining 'foo' and
that it would have been included via a DT_NEEDED entry in foo2.so.
The attached patch changes the error message to this:
ld: foo1.o: undefined reference to symbol 'foo'
ld: note: 'foo' is defined in DSO ./foo3.so so try adding it to the linker command line
Which identifies the object containing the unresolved reference as
well as providing the user with a hint as to how they can resolve
the problem.
What do you think ? Any objections to this change ?
Cheers
Nick
bfd/ChangeLog
2009-10-29 Nick Clifton <nickc@redhat.com>
* elflink.c (elf_link_add_object_symbols): Improve error
message generated when a symbol is left unresolved because a
--no-add-needed command line option has prevented the
inclusion of the DSO defining it.
Index: bfd/elflink.c
===================================================================
RCS file: /cvs/src/src/bfd/elflink.c,v
retrieving revision 1.357
diff -c -3 -p -r1.357 elflink.c
*** bfd/elflink.c 13 Oct 2009 04:06:20 -0000 1.357
--- bfd/elflink.c 29 Oct 2009 12:17:48 -0000
*************** error_free_dyn:
*** 3877,3882 ****
--- 3877,3883 ----
bfd_boolean common;
unsigned int old_alignment;
bfd *old_bfd;
+ bfd * undef_bfd = NULL;
override = FALSE;
*************** error_free_dyn:
*** 4108,4113 ****
--- 4109,4128 ----
name = newname;
}
+ /* If this is a definition of a previously undefined symbol
+ make a note of the bfd that contained the reference in
+ case we need to refer to it later on in error messages. */
+ if (! bfd_is_und_section (sec))
+ {
+ h = elf_link_hash_lookup (elf_hash_table (info), name, FALSE, FALSE, FALSE);
+
+ if (h != NULL
+ && (h->root.type == bfd_link_hash_undefined
+ || h->root.type == bfd_link_hash_undefweak)
+ && h->root.u.undef.abfd)
+ undef_bfd = h->root.u.undef.abfd;
+ }
+
if (!_bfd_elf_merge_symbol (abfd, info, name, isym, &sec,
&value, &old_alignment,
sym_hash, &skip, &override,
*************** error_free_dyn:
*** 4448,4456 ****
if ((elf_dyn_lib_class (abfd) & DYN_NO_NEEDED) != 0)
{
(*_bfd_error_handler)
! (_("%B: invalid DSO for symbol `%s' definition"),
abfd, name);
! bfd_set_error (bfd_error_bad_value);
goto error_free_vers;
}
--- 4463,4474 ----
if ((elf_dyn_lib_class (abfd) & DYN_NO_NEEDED) != 0)
{
(*_bfd_error_handler)
! (_("%B: undefined reference to symbol '%s'"),
! undef_bfd == NULL ? info->output_bfd : undef_bfd, name);
! (*_bfd_error_handler)
! (_("note: '%s' is defined in DSO %B so try adding it to the linker command line"),
abfd, name);
! bfd_set_error (bfd_error_invalid_operation);
goto error_free_vers;
}