This is the mail archive of the
binutils@sourceware.cygnus.com
mailing list for the binutils project.
Re: Patch to recent ELF linker enhancement
- To: ian at zembu dot com
- Subject: Re: Patch to recent ELF linker enhancement
- From: Nick Clifton <nickc at cygnus dot com>
- Date: Mon, 13 Dec 1999 17:56:38 -0800
- CC: binutils at sourceware dot cygnus dot com
Hi Ian,
: 1999-12-13 Nick Clifton <nickc@cygnus.com>
:
: * elflink.h (elf_link_add_archive_symbols): Do not bother
: checking for defined commons if the element has already been
: linked in.
:
: I think this patch will force the linker to read in archive elements
: which it does not need to read in.
Err, presumably you mean the original patch, not my little bugfix
patch represneted by the ChangeLog entry above ?
: I also don't understand why it makes any difference. Why is the
: included array not being set correctly in this case? Why do we even
: reach the code that you are changing if the archive element has
: already been linked in? What is the test case?
The test case is as follows:
% cat foo1.c
extern void libcall ();
void _start (void) { libcall (); }
% cat foo2a.c
extern int var;
void libcall (void) { var = 1; }
% cat foo2b.c
int var;
void extra (void) { var = 2; }
% gcc -c foo1.c foo2a.c foo2b.c
% ar cr libfoo2.a foo2a.o foo2b.o
% ld foo1.o -L. -\( -lfoo2 -\)
./libfoo2.a: could not read symbols: Bad value
However, you are right about my patch being unnecessary - it is the
elf_link_is_defined_archive_sytmbol() itself that is wrong. I was
forgetting to check to see if the symbol was allocated to the common
section. The patch below fixes this and prevents the above test case
from generating an error.
Cheers
Nick
1999-12-13 Nick Clifton <nickc@cygnus.com>
* elflink.h (elf_link_is_defined_archive_symbol): Check to see
if the symbol is in the common section.
Index: elflink.h
===================================================================
RCS file: /cvs/binutils/binutils/bfd/elflink.h,v
retrieving revision 1.39
diff -p -r1.39 elflink.h
*** elflink.h 1999/12/10 20:17:28 1.39
--- elflink.h 1999/12/14 01:54:14
*************** elf_link_is_defined_archive_symbol (abfd
*** 161,167 ****
{
result =
(ELF_ST_BIND (sym.st_info) == STB_GLOBAL)
! && (sym.st_shndx != SHN_UNDEF);
break;
}
}
--- 161,169 ----
{
result =
(ELF_ST_BIND (sym.st_info) == STB_GLOBAL)
! && (sym.st_shndx != SHN_UNDEF)
! && (sym.st_shndx != SHN_COMMON)
! ;
break;
}
}