Can I link a.out .o with ELF?

Alan Modra alan@linuxcare.com.au
Mon Jun 5 07:28:00 GMT 2000


On Sun, 4 Jun 2000, H . J . Lu wrote:

> On Sun, Jun 04, 2000 at 09:31:30PM -0700, H . J . Lu wrote:
> > 
> > It seems that ELF_LINK_NON_ELF doesn't work too well with symbol
> > versioning. As the result, when a verioned symbol is referenced
> > in an a.out .o file, the ELF_LINK_NON_ELF bit on the default symbol
> > is not set. I am not sure what else is not working right.
> > 
> 
> I have a patch to stop ld from dumping core. But it still doesn't
> work right. On Linux/ia32/glibc 2.1 or glibc 2.2:

This patch seems to cure your testcase.  Warning: I have no idea whether
it's the ideal solution, or even correct.  Ian may be able to give a
better solution.

Regards, Alan Modra.
--
Linuxcare.  Support for the Revolution.


	* elflink.h (elf_link_add_object_symbols): Set hash flags for
	NON_ELF short name references of versioned symbols.
	(elf_fix_symbol_flags): Follow the link for indirect symbols.


Index: elflink.h
===================================================================
RCS file: /cvs/src/src/bfd/elflink.h,v
retrieving revision 1.58
diff -u -p -r1.58 elflink.h
--- elflink.h	2000/05/30 20:51:36	1.58
+++ elflink.h	2000/06/05 14:23:33
@@ -1741,6 +1741,20 @@ elf_link_add_object_symbols (abfd, info)
 		      ht = (struct elf_link_hash_entry *) hi->root.u.i.link;
 		      (*bed->elf_backend_copy_indirect_symbol) (ht, hi);
 
+		      if ((hi->elf_link_hash_flags & ELF_LINK_NON_ELF) != 0)
+			{
+			  if (dynamic)
+			    hi->elf_link_hash_flags |=
+			      ELF_LINK_HASH_DEF_DYNAMIC;
+			  else
+			    hi->elf_link_hash_flags |=
+			      ELF_LINK_HASH_DEF_REGULAR;
+
+			  ht->elf_link_hash_flags |=
+			    (ELF_LINK_HASH_REF_REGULAR
+			     | ELF_LINK_HASH_REF_REGULAR_NONWEAK);
+			}
+
 		      /* See if the new flags lead us to realize that
 			 the symbol must be dynamic.  */
 		      if (! dynsym)
@@ -3283,11 +3297,15 @@ elf_fix_symbol_flags (h, eif)
      struct elf_link_hash_entry *h;
      struct elf_info_failed *eif;
 {
+  struct elf_link_hash_entry *ho = h;
+  while (h->root.type == bfd_link_hash_indirect)
+    h = (struct elf_link_hash_entry *) h->root.u.i.link;
+
   /* If this symbol was mentioned in a non-ELF file, try to set
      DEF_REGULAR and REF_REGULAR correctly.  This is the only way to
      permit a non-ELF file to correctly refer to a symbol defined in
      an ELF dynamic object.  */
-  if ((h->elf_link_hash_flags & ELF_LINK_NON_ELF) != 0)
+  if ((ho->elf_link_hash_flags & ELF_LINK_NON_ELF) != 0)
     {
       if (h->root.type != bfd_link_hash_defined
 	  && h->root.type != bfd_link_hash_defweak)



More information about the Binutils mailing list