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 broken with cvs head


On Thu, Mar 06, 2003 at 10:02:58PM +1030, Alan Modra wrote:
> On Wed, Mar 05, 2003 at 06:54:45PM +0100, Olaf Hering wrote:
> > unresolvable relocation against symbol `environ@@GLIBC_2.0'
> 
> A testcase for this is
> 
> cat > env.c <<EOF
> extern char *environ;
> int main (void) { return *environ; }
> EOF
> gcc -o env env.c -fPIC -O
> 
> The quick fix is to "#define ELIMINATE_COPY_RELOCS 0" at
> elf32-ppc.c:2458.  I'm afraid the ELIMINATE_COPY_RELOCS code is
> broken, and has been broken on x86 for a long time too.  In fact,
> it's quite surprising that no one has reported a bug in the x86
> code.  Maybe it's just harder to trigger there.

The fix was easy.  I've introduced an ELIMINATE_COPY_RELOCS define
for x86 too, mostly just to document the code.

	* elf32-ppc.c (ELIMINATE_COPY_RELOCS): Define as one.
	(ppc_elf_adjust_dynamic_symbol): For weak symbols, copy
	ELF_LINK_NON_GOT_REF from weakdef.
	* elf64-ppc.c (ELIMINATE_COPY_RELOCS): Define as one.
	(ppc64_elf_adjust_dynamic_symbol): For weak symbols, copy
	ELF_LINK_NON_GOT_REF from weakdef.
	* elf32-i386.c (ELIMINATE_COPY_RELOCS): Define as one.  Use throughout.
	(elf_i386_adjust_dynamic_symbol): For weak symbols, copy
	ELF_LINK_NON_GOT_REF from weakdef.

Index: bfd/elf32-ppc.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-ppc.c,v
retrieving revision 1.69
diff -u -p -r1.69 elf32-ppc.c
--- bfd/elf32-ppc.c	6 Mar 2003 11:32:43 -0000	1.69
+++ bfd/elf32-ppc.c	6 Mar 2003 23:15:56 -0000
@@ -2455,7 +2455,7 @@ ppc_elf_create_dynamic_sections (abfd, i
    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 0
+#define ELIMINATE_COPY_RELOCS 1
 
 /* Adjust a symbol defined by a dynamic object and referenced by a
    regular object.  The current definition is in some section of the
@@ -2525,6 +2525,10 @@ ppc_elf_adjust_dynamic_symbol (info, h)
 		  || 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)
+	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;
     }
 
Index: bfd/elf64-ppc.c
===================================================================
RCS file: /cvs/src/src/bfd/elf64-ppc.c,v
retrieving revision 1.90
diff -u -p -r1.90 elf64-ppc.c
--- bfd/elf64-ppc.c	6 Mar 2003 11:32:43 -0000	1.90
+++ bfd/elf64-ppc.c	6 Mar 2003 23:15:59 -0000
@@ -2545,7 +2545,7 @@ struct plt_entry
    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 0
+#define ELIMINATE_COPY_RELOCS 1
 
 /* Section name for stubs is the associated section name plus this
    string.  */
@@ -4518,6 +4518,10 @@ ppc64_elf_adjust_dynamic_symbol (info, h
 		  || 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)
+	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;
     }
 
Index: bfd/elf32-i386.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-i386.c,v
retrieving revision 1.95
diff -u -p -r1.95 elf32-i386.c
--- bfd/elf32-i386.c	19 Feb 2003 14:14:16 -0000	1.95
+++ bfd/elf32-i386.c	6 Mar 2003 23:15:52 -0000
@@ -506,6 +506,12 @@ elf_i386_grok_psinfo (abfd, note)
 
 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.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 procedure linkage table.  */
 
 #define PLT_ENTRY_SIZE 16
@@ -1106,7 +1112,8 @@ elf_i386_check_relocs (abfd, info, sec, 
 			   || 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
@@ -1372,8 +1379,6 @@ elf_i386_adjust_dynamic_symbol (info, h)
      struct elf_link_hash_entry *h;
 {
   struct elf_i386_link_hash_table *htab;
-  struct elf_i386_link_hash_entry * eh;
-  struct elf_i386_dyn_relocs *p;
   asection *s;
   unsigned int power_of_two;
 
@@ -1418,6 +1423,10 @@ elf_i386_adjust_dynamic_symbol (info, h)
 		  || 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;
     }
 
@@ -1443,20 +1452,26 @@ elf_i386_adjust_dynamic_symbol (info, h)
       return TRUE;
     }
 
-  eh = (struct elf_i386_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 elf_i386_link_hash_entry * eh;
+      struct elf_i386_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 elf_i386_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
@@ -1676,7 +1691,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
@@ -2412,7 +2427,8 @@ elf_i386_relocate_section (output_bfd, i
 		       && (! 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

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre


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