This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PATCH: ELF linker is broken


On Mon, Jan 31, 2005 at 01:22:03PM -0800, H. J. Lu wrote:
> On Mon, Jan 31, 2005 at 05:43:08PM +1030, Alan Modra wrote:
> > On Mon, Jan 31, 2005 at 10:32:27AM +1030, Alan Modra wrote:
> > > On Sun, Jan 30, 2005 at 11:22:49AM -0800, H. J. Lu wrote:
> > > > /usr/lib/crt1.o:(.dynamic+0x0): multiple definition of `_DYNAMIC'
> > > [snip]
> > > > The 2005-01-24 binutils is OK. It may have something to do with
> > > > 
> > > > http://sources.redhat.com/ml/binutils/2005-01/msg00405.html
> > > 
> > > Possible, I suppose.  An as-needed shared lib will define syms whether
> > > or not the lib is actually linked.  It will be linked if any symbol it
> > > defines satisfies an undefined reference, and conversely it isn't linked
> > > then there are no references to its symbols.  That should make it safe
> > > to leave its symbols in the symbol table, so long as we properly treat
> > > them in _bfd_elf_merge_symbol.  If there is a problem, it's likely to be
> > > in _bfd_elf_merge_symbol.
> > 
> > I'm testing the following on powerpc and x86 to ensure I haven't made
> > any silly mistakes.  It's a big hammer approach but cleaner than what we
> > had before, I think.  Rather than tweaking _bfd_elf_merge_symbol and
> > other places to specially handle symbols defined in unused --as-needed
> > libs, I've munged all such symbols back to their new state.  Hopefully
> > this won't break too many back-end elf_link_hash_traverse functions..
> > 
> > Would you please test this on ia64?  I don't have access to ia64
> > hardware, so testing this isn't so easy.
> 
> I am enclosing a testcase here. I saw the same problem on ia32, ia64
> and x86_64:
> 

This patch works for me.

H.J.
----
2005-01-31  H.J. Lu  <hongjiu.lu@intel.com>

	* elflink.c (_bfd_elf_link_create_dynamic_sections): Discard
	previous "_DYNAMIC" before creating the new one.

--- bfd/elflink.c.dynamic	2005-01-31 12:19:55.000000000 -0800
+++ bfd/elflink.c	2005-01-31 13:59:00.463355292 -0800
@@ -216,7 +216,19 @@ _bfd_elf_link_create_dynamic_sections (b
      linker script, but we only want to define it if we are, in fact,
      creating a .dynamic section.  We don't want to define it if there
      is no .dynamic section, since on some ELF platforms the start up
-     code examines it to decide how to initialize the process.  */
+     code examines it to decide how to initialize the process. 
+   
+     _DYNAMIC is a special symbol. We used to create it before reading
+     symbol tables from shared libraries. But now it is delayed. We
+     discard any previous definition from shared library before we
+     create this one.  */
+  h = elf_link_hash_lookup (elf_hash_table (info), "_DYNAMIC", FALSE,
+			    FALSE, FALSE);
+  if (h)
+    {
+      h->root.type = bfd_link_hash_undefined;
+      h->root.u.undef.abfd = abfd;
+    }
   bh = NULL;
   if (! (_bfd_generic_link_add_one_symbol
 	 (info, abfd, "_DYNAMIC", BSF_GLOBAL, s, 0, NULL, FALSE,


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]