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]

PowerPC. Don't emit dynamic relocs for debug sections.


This patch removes dynamic debug relocs on PowerPC.  It's somewhat
controversial, for example, see
http://sources.redhat.com/ml/binutils/2002-09/msg00611.html and
http://sources.redhat.com/ml/binutils/2002-10/msg00020.html
but

o  Currently, nothing uses these relocs.
o  The only real use is for a gcc extension, which probably ought to
   describe the asm symbol mapping by some means other than relocs, ie.
   by some DWARF2 construct.
o  HJ Lu's binutils, used by most Linux distributions, doesn't emit them.

Since file bloat is a real concern to distributions, and I'd like to
encourage use of FSF binutils releases, I intend to apply this patch
on mainline and for the 2.16 release.  If gdb does start using dynamic
relocs on debug info sometime this decade, then this change can easily
be reverted.

	* elf32-ppc.c (ppc_elf_check_relocs): Don't bother with
	dynamic relocs in non-SEC_ALLOC sections.
	(ppc_elf_gc_sweep_hook): Likewise.
	(ppc_elf_relax_section): Likewise.
	(ppc_elf_relocate_section): Likewise.

	* ld-powerpc/reloc.d: Update to suit removal of non-alloc relocs.

Index: bfd/elf32-ppc.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-ppc.c,v
retrieving revision 1.147
diff -u -p -r1.147 elf32-ppc.c
--- bfd/elf32-ppc.c	23 Mar 2005 04:14:43 -0000	1.147
+++ bfd/elf32-ppc.c	1 Apr 2005 02:55:29 -0000
@@ -2581,6 +2581,15 @@ ppc_elf_check_relocs (bfd *abfd,
   if (info->relocatable)
     return TRUE;
 
+  /* Don't do anything special with non-loaded, non-alloced sections.
+     In particular, any relocs in such sections should not affect GOT
+     and PLT reference counting (ie. we don't allow them to create GOT
+     or PLT entries), there's no possibility or desire to optimize TLS
+     relocs, and there's not much point in propagating relocs to shared
+     libs that the dynamic linker won't relocate.  */
+  if ((sec->flags & SEC_ALLOC) == 0)
+    return TRUE;
+
 #ifdef DEBUG
   _bfd_error_handler ("ppc_elf_check_relocs called for section %A in %B",
 		      sec, abfd);
@@ -2902,7 +2911,6 @@ ppc_elf_check_relocs (bfd *abfd,
 			   || !h->def_regular))))
 	      || (ELIMINATE_COPY_RELOCS
 		  && !info->shared
-		  && (sec->flags & SEC_ALLOC) != 0
 		  && h != NULL
 		  && (h->root.type == bfd_link_hash_defweak
 		      || !h->def_regular)))
@@ -2941,9 +2949,8 @@ ppc_elf_check_relocs (bfd *abfd,
 
 		      sreloc = bfd_make_section (htab->elf.dynobj, name);
 		      flags = (SEC_HAS_CONTENTS | SEC_READONLY
-			       | SEC_IN_MEMORY | SEC_LINKER_CREATED);
-		      if ((sec->flags & SEC_ALLOC) != 0)
-			flags |= SEC_ALLOC | SEC_LOAD;
+			       | SEC_IN_MEMORY | SEC_LINKER_CREATED
+			       | SEC_ALLOC | SEC_LOAD);
 		      if (sreloc == NULL
 			  || ! bfd_set_section_flags (htab->elf.dynobj,
 						      sreloc, flags)
@@ -3147,6 +3154,9 @@ ppc_elf_gc_sweep_hook (bfd *abfd,
   bfd_signed_vma *local_got_refcounts;
   const Elf_Internal_Rela *rel, *relend;
 
+  if ((sec->flags & SEC_ALLOC) == 0)
+    return TRUE;
+
   elf_section_data (sec)->local_dynrel = NULL;
 
   htab = ppc_elf_hash_table (info);
@@ -4185,8 +4195,11 @@ ppc_elf_relax_section (bfd *abfd,
 
   *again = FALSE;
 
-  /* Nothing to do if there are no relocations.  */
-  if ((isec->flags & SEC_RELOC) == 0 || isec->reloc_count == 0)
+  /* Nothing to do if there are no relocations, and no need to do
+     anything with non-alloc sections.  */
+  if ((isec->flags & SEC_ALLOC) == 0
+      || (isec->flags & SEC_RELOC) == 0
+      || isec->reloc_count == 0)
     return TRUE;
 
   trampoff = (isec->size + 3) & (bfd_vma) -4;
@@ -5354,6 +5367,10 @@ ppc_elf_relocate_section (bfd *output_bf
 	    break;
 	  /* Fall thru.  */
 
+	  if ((input_section->flags & SEC_ALLOC) == 0)
+	    break;
+	  /* Fall thru.  */
+
 	  if ((info->shared
 	       && (h == NULL
 		   || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
@@ -5362,7 +5379,6 @@ ppc_elf_relocate_section (bfd *output_bf
 		   || !SYMBOL_CALLS_LOCAL (info, h)))
 	      || (ELIMINATE_COPY_RELOCS
 		  && !info->shared
-		  && (input_section->flags & SEC_ALLOC) != 0
 		  && h != NULL
 		  && h->dynindx != -1
 		  && !h->non_got_ref
Index: ld/testsuite/ld-powerpc/reloc.d
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-powerpc/reloc.d,v
retrieving revision 1.2
diff -u -p -r1.2 reloc.d
--- ld/testsuite/ld-powerpc/reloc.d	10 Oct 2002 02:53:17 -0000	1.2
+++ ld/testsuite/ld-powerpc/reloc.d	1 Apr 2005 04:51:51 -0000
@@ -1,6 +1,5 @@
 # Test that orphan reloc sections are placed before .rela.plt even when
-# .rela.plt is the only reloc section.  Also tests that orphan non-alloc
-# reloc sections go after alloc sections.
+# .rela.plt is the only reloc section.
 
 #source: reloc.s
 #ld: -shared -z nocombreloc
@@ -11,6 +10,4 @@
 .*\.relaplatypus.*
 #...
 .*\.rela\.plt.*
-#...
-.*\.relaechidna.*
 #pass

-- 
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]