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]

Re: ppc32 linker bug


Alan Modra <amodra@bigpond.net.au> writes:

> On Thu, May 01, 2003 at 04:45:48PM +0200, Andreas Jaeger wrote:
>> Is this something that should be done for all archs?  Can I enable it
>> for x86-64?  Is there a testcase I should look at?
>
> I considered doing it for all archs, but decided against it this
> close to a release.  A testcase is something like the following
> assembly linked against libc.
>
>  .rodata

.section .rodata

>  .quad timezone
>  .data
>  .quad environ

With my old binutils I get:
$ gcc t.o -o t
/usr/lib64/gcc-lib/x86_64-suse-linux/3.3/../../../../lib64/crt1.o(.text+0x21): In function `_start':
: undefined reference to `main'
/usr/lib64/gcc-lib/x86_64-suse-linux/3.3/../../../../x86_64-suse-linux/bin/ld: t.o(.data+0x0): unresolvable relocation against symbol `environ@@GLIBC_2.2.5'
collect2: ld returned 1 exit status

With my patched binutils:
/usr/lib64/gcc-lib/x86_64-suse-linux/3.3/../../../../lib64/crt1.o(.text+0x21): In function `_start':
: undefined reference to `main'

So, this looks fine to me.

Here's a patch.  I'll commit it later today to both branch and
mainline.  Could you give it a quick review?

The testsuite passed fine with this change.


Thanks,
Andreas

2003-05-02  Andreas Jaeger  <aj@suse.de>

	* elf64-x86-64.c (elf_x86_64_copy_indirect_symbol): Don't copy
	ELF_LINK_NON_GOT_REF for weakdefs when symbol already adjusted.
	(ELIMINATE_COPY_RELOCS): Define as one.  Use throughout.
	(elf_x86_64_adjust_dynamic_symbol): For weak symbols, copy
	ELF_LINK_NON_GOT_REF from weakdef.


============================================================
Index: bfd/elf64-x86-64.c
--- bfd/elf64-x86-64.c	19 Feb 2003 14:14:16 -0000	1.56
+++ bfd/elf64-x86-64.c	2 May 2003 06:29:45 -0000
@@ -324,6 +324,12 @@ elf64_x86_64_grok_psinfo (abfd, note)
 
 #define ELF_DYNAMIC_INTERPRETER "/lib/ld64.so.1"
 
+/* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
+   copying dynamic variables from a shared lib into an app's dynbss
+   section, and instead use a dynamic relocation to point into the
+   shared lib.  */
+#define ELIMINATE_COPY_RELOCS 1
+
 /* The size in bytes of an entry in the global offset table.  */
 
 #define GOT_ENTRY_SIZE 8
@@ -616,7 +622,18 @@ elf64_x86_64_copy_indirect_symbol (bed, 
       eind->tls_type = GOT_UNKNOWN;
     }
 
-  _bfd_elf_link_hash_copy_indirect (bed, dir, ind);
+  if (ELIMINATE_COPY_RELOCS
+      && ind->root.type != bfd_link_hash_indirect
+      && (dir->elf_link_hash_flags & ELF_LINK_HASH_DYNAMIC_ADJUSTED) != 0)
+    /* If called to transfer flags for a weakdef during processing
+       of elf_adjust_dynamic_symbol, don't copy ELF_LINK_NON_GOT_REF.
+       We clear it ourselves for ELIMINATE_COPY_RELOCS.  */
+    dir->elf_link_hash_flags |=
+      (ind->elf_link_hash_flags & (ELF_LINK_HASH_REF_DYNAMIC
+				   | ELF_LINK_HASH_REF_REGULAR
+				   | ELF_LINK_HASH_REF_REGULAR_NONWEAK));
+  else
+    _bfd_elf_link_hash_copy_indirect (bed, dir, ind);
 }
 
 static bfd_boolean
@@ -914,7 +931,8 @@ elf64_x86_64_check_relocs (abfd, info, s
 			   || h->root.type == bfd_link_hash_defweak
 			   || (h->elf_link_hash_flags
 			       & ELF_LINK_HASH_DEF_REGULAR) == 0))))
-	      || (!info->shared
+	      || (ELIMINATE_COPY_RELOCS
+		  && !info->shared
 		  && (sec->flags & SEC_ALLOC) != 0
 		  && h != NULL
 		  && (h->root.type == bfd_link_hash_defweak
@@ -1189,8 +1207,6 @@ elf64_x86_64_adjust_dynamic_symbol (info
      struct elf_link_hash_entry *h;
 {
   struct elf64_x86_64_link_hash_table *htab;
-  struct elf64_x86_64_link_hash_entry * eh;
-  struct elf64_x86_64_dyn_relocs *p;
   asection *s;
   unsigned int power_of_two;
 
@@ -1235,6 +1251,10 @@ elf64_x86_64_adjust_dynamic_symbol (info
 		  || h->weakdef->root.type == bfd_link_hash_defweak);
       h->root.u.def.section = h->weakdef->root.u.def.section;
       h->root.u.def.value = h->weakdef->root.u.def.value;
+      if (ELIMINATE_COPY_RELOCS || info->nocopyreloc)
+	h->elf_link_hash_flags
+	  = ((h->elf_link_hash_flags & ~ELF_LINK_NON_GOT_REF)
+	     | (h->weakdef->elf_link_hash_flags & ELF_LINK_NON_GOT_REF));
       return TRUE;
     }
 
@@ -1260,20 +1280,26 @@ elf64_x86_64_adjust_dynamic_symbol (info
       return TRUE;
     }
 
-  eh = (struct elf64_x86_64_link_hash_entry *) h;
-  for (p = eh->dyn_relocs; p != NULL; p = p->next)
+  if (ELIMINATE_COPY_RELOCS)
     {
-      s = p->sec->output_section;
-      if (s != NULL && (s->flags & SEC_READONLY) != 0)
-	break;
-    }
+      struct elf64_x86_64_link_hash_entry * eh;
+      struct elf64_x86_64_dyn_relocs *p;
 
-  /* If we didn't find any dynamic relocs in read-only sections, then
-     we'll be keeping the dynamic relocs and avoiding the copy reloc.  */
-  if (p == NULL)
-    {
-      h->elf_link_hash_flags &= ~ELF_LINK_NON_GOT_REF;
-      return TRUE;
+      eh = (struct elf64_x86_64_link_hash_entry *) h;
+      for (p = eh->dyn_relocs; p != NULL; p = p->next)
+	{
+	  s = p->sec->output_section;
+	  if (s != NULL && (s->flags & SEC_READONLY) != 0)
+	    break;
+	}
+
+      /* If we didn't find any dynamic relocs in read-only sections, then
+	 we'll be keeping the dynamic relocs and avoiding the copy reloc.  */
+      if (p == NULL)
+	{
+	  h->elf_link_hash_flags &= ~ELF_LINK_NON_GOT_REF;
+	  return TRUE;
+	}
     }
 
   /* We must allocate the symbol in our .dynbss section, which will
@@ -1487,7 +1513,7 @@ allocate_dynrelocs (h, inf)
 	    }
 	}
     }
-  else
+  else if (ELIMINATE_COPY_RELOCS)
     {
       /* For the non-shared case, discard space for relocs against
 	 symbols which turn out to need copy relocs or are not
@@ -2077,7 +2103,8 @@ elf64_x86_64_relocate_section (output_bf
 		       && (! info->symbolic
 			   || (h->elf_link_hash_flags
 			       & ELF_LINK_HASH_DEF_REGULAR) == 0))))
-	      || (!info->shared
+	      || (ELIMINATE_COPY_RELOCS
+		  && !info->shared
 		  && h != NULL
 		  && h->dynindx != -1
 		  && (h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0
@@ -2351,7 +2378,7 @@ elf64_x86_64_relocate_section (output_bf
 		{
 		  if (indx == 0)
 		    {
-	    	      BFD_ASSERT (! unresolved_reloc);
+		      BFD_ASSERT (! unresolved_reloc);
 		      bfd_put_64 (output_bfd,
 				  relocation - dtpoff_base (info),
 				  htab->sgot->contents + off + GOT_ENTRY_SIZE);

-- 
 Andreas Jaeger
  SuSE Labs aj@suse.de
   private aj@arthur.inka.de
    http://www.suse.de/~aj


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