This is the mail archive of the binutils@sourceware.org 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: RFC: Mark discarded debug info more thoroughly


On Thu, Oct 26, 2006 at 01:37:03PM -0400, Daniel Jacobowitz wrote:
> On Thu, Oct 26, 2006 at 11:54:06AM -0400, Daniel Jacobowitz wrote:
> > Here is a version of the patch which adjusts all ELF targets that I
> > could readily find the right place to change (a couple done by hand,
> > plus searches for r_symndx == 0).  I've built it with
> > --enable-targets=all, and tested a few of the changed targets, but not
> > all.
> > 
> > There's also a testcase.  I expect that it is going to fail on a bunch
> > of more obscure targets that I haven't tested.  Should I build and test
> > all ELF targets?  If so, does anyone have a current list of target
> > tuples to test, and if so, should it be in CVS somewhere?
> 
> Questions stand; here's a revised version that also fixes SH.

I dredged a list of 38 ELF targets out of an old posting of Nick's; I
probably missed one or two added since then, but this was quite enough
for now.  My patch covered all of them except for d10v and xtensa,
added in the attached version, which I've checked in.

-- 
Daniel Jacobowitz
CodeSourcery

2006-11-02  Daniel Jacobowitz  <dan@codesourcery.com>

	* libbfd-in.h (_bfd_clear_contents): New prototype.
	* reloc.c (_bfd_clear_contents): New.
	* libbfd.h: Regenerated.

	* elf32-arm.c (elf32_arm_final_link_relocate): Use
	_bfd_clear_contents.
	* elf32-d10v.c (elf32_d10v_relocate_section): Likewise.
	* elf32-hppa.c (elf32_hppa_relocate_section): Likewise.
	* elf32-i386.c (elf_i386_relocate_section): Likewise.
	* elf32-ppc.c (ppc_elf_relocate_section): Likewise.
	* elf32-s390.c (elf_s390_relocate_section): Likewise.
	* elf32-sh.c (sh_elf_relocate_section): Likewise.
	* elf32-xtensa.c (elf_xtensa_relocate_section): Likewise.
	* elf64-ppc.c (ppc64_elf_relocate_section): Likewise.
	* elf64-s390.c (elf_s390_relocate_section): Likewise.
	* elf64-x86-64.c (elf64_x86_64_relocate_section): Likewise.
	* elfxx-sparc.c (_bfd_sparc_elf_relocate_section): Likewise.

	* elfxx-ia64.c (elfNN_ia64_relocate_section): Set value to
	zero for discarded symbols.
	* elfxx-mips.c (mips_elf_calculate_relocation): Likewise.

2006-11-02  Daniel Jacobowitz  <dan@codesourcery.com>

	* ld-discard/zero-rel.d, ld-discard/zero-rel.s: New files.

Index: bfd/elf32-arm.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-arm.c,v
retrieving revision 1.98
diff -u -p -r1.98 elf32-arm.c
--- bfd/elf32-arm.c	1 Nov 2006 20:00:25 -0000	1.98
+++ bfd/elf32-arm.c	2 Nov 2006 21:48:15 -0000
@@ -3664,7 +3664,10 @@ elf32_arm_final_link_relocate (reloc_how
 	 from removed linkonce sections, or sections discarded by
 	 a linker script.  */
       if (r_symndx == 0)
-	return bfd_reloc_ok;
+	{
+	  _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
+	  return bfd_reloc_ok;
+	}
 
       /* Handle relocations which should use the PLT entry.  ABS32/REL32
 	 will use the symbol's value, which may point to a PLT entry, but we
Index: bfd/elf32-d10v.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-d10v.c,v
retrieving revision 1.31
diff -u -p -r1.31 elf32-d10v.c
--- bfd/elf32-d10v.c	28 Sep 2006 13:27:33 -0000	1.31
+++ bfd/elf32-d10v.c	2 Nov 2006 21:48:15 -0000
@@ -469,6 +469,16 @@ elf32_d10v_relocate_section (bfd *output
 				   unresolved_reloc, warned);
 	}
 
+      if (r_symndx == 0)
+	{
+	  /* r_symndx will be zero only for relocs against symbols from
+	     removed linkonce sections, or sections discarded by a linker
+	     script.  For these relocs, we just want the section contents
+	     zeroed.  Avoid any special processing.  */
+	  _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
+	  continue;
+	}
+
       if (h != NULL)
 	name = h->root.root.string;
       else
Index: bfd/elf32-hppa.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-hppa.c,v
retrieving revision 1.148
diff -u -p -r1.148 elf32-hppa.c
--- bfd/elf32-hppa.c	17 Oct 2006 13:41:47 -0000	1.148
+++ bfd/elf32-hppa.c	2 Nov 2006 21:48:16 -0000
@@ -3942,8 +3942,14 @@ elf32_hppa_relocate_section (bfd *output
 	  /* r_symndx will be zero only for relocs against symbols
 	     from removed linkonce sections, or sections discarded by
 	     a linker script.  */
-	  if (r_symndx == 0
-	      || (input_section->flags & SEC_ALLOC) == 0)
+	  if (r_symndx == 0)
+	    {
+	      _bfd_clear_contents (elf_hppa_howto_table + r_type, input_bfd,
+				   contents + rela->r_offset);
+	      break;
+	    }
+
+	  if ((input_section->flags & SEC_ALLOC) == 0)
 	    break;
 
 	  /* The reloc types handled here and this conditional
Index: bfd/elf32-i386.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-i386.c,v
retrieving revision 1.167
diff -u -p -r1.167 elf32-i386.c
--- bfd/elf32-i386.c	17 Oct 2006 13:41:46 -0000	1.167
+++ bfd/elf32-i386.c	2 Nov 2006 21:48:16 -0000
@@ -2395,17 +2395,12 @@ elf_i386_relocate_section (bfd *output_b
 
       if (r_symndx == 0)
 	{
-	/* r_symndx will be zero only for relocs against symbols from
-	   removed linkonce sections, or sections discarded by a linker
-	   script.  For these relocs, we just want the section contents
-	   zeroed.  Avoid any special processing in the switch below.  */
-	  r_type = R_386_NONE;
-
-	  relocation = 0;
-	  if (howto->pc_relative)
-	    relocation = (input_section->output_section->vma
-			  + input_section->output_offset
-			  + rel->r_offset);
+	  /* r_symndx will be zero only for relocs against symbols from
+	     removed linkonce sections, or sections discarded by a linker
+	     script.  For these relocs, we just want the section contents
+	     zeroed.  Avoid any special processing.  */
+	  _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
+	  continue;
 	}
 
       switch (r_type)
Index: bfd/elf32-ppc.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-ppc.c,v
retrieving revision 1.205
diff -u -p -r1.205 elf32-ppc.c
--- bfd/elf32-ppc.c	17 Oct 2006 13:41:47 -0000	1.205
+++ bfd/elf32-ppc.c	2 Nov 2006 21:48:16 -0000
@@ -6180,7 +6180,10 @@ ppc_elf_relocate_section (bfd *output_bf
 	     a linker script.  */
 	dodyn:
 	  if (r_symndx == 0)
-	    break;
+	    {
+	      _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
+	      break;
+	    }
 	  /* Fall thru.  */
 
 	  if ((input_section->flags & SEC_ALLOC) == 0)
Index: bfd/elf32-s390.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-s390.c,v
retrieving revision 1.88
diff -u -p -r1.88 elf32-s390.c
--- bfd/elf32-s390.c	17 Oct 2006 13:41:47 -0000	1.88
+++ bfd/elf32-s390.c	2 Nov 2006 21:48:17 -0000
@@ -2543,8 +2543,13 @@ elf_s390_relocate_section (output_bfd, i
 	  /* r_symndx will be zero only for relocs against symbols
 	     from removed linkonce sections, or sections discarded by
 	     a linker script.  */
-	  if (r_symndx == 0
-	      || (input_section->flags & SEC_ALLOC) == 0)
+	  if (r_symndx == 0)
+	    {
+	      _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
+	      break;
+	    }
+
+	  if ((input_section->flags & SEC_ALLOC) == 0)
 	    break;
 
 	  if ((info->shared
Index: bfd/elf32-sh.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-sh.c,v
retrieving revision 1.144
diff -u -p -r1.144 elf32-sh.c
--- bfd/elf32-sh.c	17 Oct 2006 13:41:47 -0000	1.144
+++ bfd/elf32-sh.c	2 Nov 2006 21:48:17 -0000
@@ -3557,6 +3557,15 @@ sh_elf_relocate_section (bfd *output_bfd
 	case R_SH_IMM_MEDHI16_PCREL:
 	case R_SH_IMM_HI16_PCREL:
 #endif
+	  /* r_symndx will be zero only for relocs against symbols
+	     from removed linkonce sections, or sections discarded by
+	     a linker script.  */
+	  if (r_symndx == 0)
+	    {
+	      _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
+	      continue;
+	    }
+
 	  if (info->shared
 	      && (h == NULL
 		  || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
Index: bfd/elf32-xtensa.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-xtensa.c,v
retrieving revision 1.74
diff -u -p -r1.74 elf32-xtensa.c
--- bfd/elf32-xtensa.c	17 Oct 2006 13:41:47 -0000	1.74
+++ bfd/elf32-xtensa.c	2 Nov 2006 21:48:18 -0000
@@ -2270,6 +2270,16 @@ elf_xtensa_relocate_section (bfd *output
 	  return FALSE;
 	}
 
+      if (r_symndx == 0)
+	{
+	  /* r_symndx will be zero only for relocs against symbols from
+	     removed linkonce sections, or sections discarded by a linker
+	     script.  For these relocs, we just want the section contents
+	     zeroed.  Avoid any special processing.  */
+	  _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
+	  continue;
+	}
+
       /* There's no point in calling bfd_perform_relocation here.
 	 Just go directly to our "special function".  */
       r = elf_xtensa_do_reloc (howto, input_bfd, input_section,
Index: bfd/elf64-ppc.c
===================================================================
RCS file: /cvs/src/src/bfd/elf64-ppc.c,v
retrieving revision 1.249
diff -u -p -r1.249 elf64-ppc.c
--- bfd/elf64-ppc.c	23 Oct 2006 03:20:56 -0000	1.249
+++ bfd/elf64-ppc.c	2 Nov 2006 21:48:19 -0000
@@ -10728,7 +10728,11 @@ ppc64_elf_relocate_section (bfd *output_
 	     a linker script.  */
 	dodyn:
 	  if (r_symndx == 0)
-	    break;
+	    {
+	      _bfd_clear_contents (ppc64_elf_howto_table[r_type], input_bfd,
+				   contents + rel->r_offset);
+	      break;
+	    }
 	  /* Fall thru.  */
 
 	dodyn2:
Index: bfd/elf64-s390.c
===================================================================
RCS file: /cvs/src/src/bfd/elf64-s390.c,v
retrieving revision 1.88
diff -u -p -r1.88 elf64-s390.c
--- bfd/elf64-s390.c	17 Oct 2006 13:41:47 -0000	1.88
+++ bfd/elf64-s390.c	2 Nov 2006 21:48:19 -0000
@@ -2522,8 +2522,13 @@ elf_s390_relocate_section (output_bfd, i
 	  /* r_symndx will be zero only for relocs against symbols
 	     from removed linkonce sections, or sections discarded by
 	     a linker script.  */
-	  if (r_symndx == 0
-	      || (input_section->flags & SEC_ALLOC) == 0)
+	  if (r_symndx == 0)
+	    {
+	      _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
+	      break;
+	    }
+
+	  if ((input_section->flags & SEC_ALLOC) == 0)
 	    break;
 
 	  if ((info->shared
Index: bfd/elf64-x86-64.c
===================================================================
RCS file: /cvs/src/src/bfd/elf64-x86-64.c,v
retrieving revision 1.127
diff -u -p -r1.127 elf64-x86-64.c
--- bfd/elf64-x86-64.c	17 Oct 2006 13:41:47 -0000	1.127
+++ bfd/elf64-x86-64.c	2 Nov 2006 21:48:20 -0000
@@ -2370,8 +2370,13 @@ elf64_x86_64_relocate_section (bfd *outp
 	  /* r_symndx will be zero only for relocs against symbols
 	     from removed linkonce sections, or sections discarded by
 	     a linker script.  */
-	  if (r_symndx == 0
-	      || (input_section->flags & SEC_ALLOC) == 0)
+	  if (r_symndx == 0)
+	    {
+	      _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
+	      break;
+	    }
+
+	  if ((input_section->flags & SEC_ALLOC) == 0)
 	    break;
 
 	  if ((info->shared
Index: bfd/elfxx-ia64.c
===================================================================
RCS file: /cvs/src/src/bfd/elfxx-ia64.c,v
retrieving revision 1.192
diff -u -p -r1.192 elfxx-ia64.c
--- bfd/elfxx-ia64.c	17 Oct 2006 13:41:47 -0000	1.192
+++ bfd/elfxx-ia64.c	2 Nov 2006 21:48:20 -0000
@@ -4751,6 +4751,12 @@ elfNN_ia64_relocate_section (output_bfd,
 	case R_IA64_LTV32LSB:
 	case R_IA64_LTV64MSB:
 	case R_IA64_LTV64LSB:
+	  /* r_symndx will be zero only for relocs against symbols
+	     from removed linkonce sections, or sections discarded by
+	     a linker script.  */
+	  if (r_symndx == 0)
+	    value = 0;
+
 	  r = elfNN_ia64_install_value (hit_addr, value, r_type);
 	  break;
 
Index: bfd/elfxx-mips.c
===================================================================
RCS file: /cvs/src/src/bfd/elfxx-mips.c,v
retrieving revision 1.190
diff -u -p -r1.190 elfxx-mips.c
--- bfd/elfxx-mips.c	1 Nov 2006 16:07:46 -0000	1.190
+++ bfd/elfxx-mips.c	2 Nov 2006 21:48:21 -0000
@@ -4311,6 +4311,11 @@ mips_elf_calculate_relocation (bfd *abfd
 						   input_section))
 	    return bfd_reloc_undefined;
 	}
+      else if (r_symndx == 0)
+	/* r_symndx will be zero only for relocs against symbols
+	   from removed linkonce sections, or sections discarded by
+	   a linker script.  */
+	value = 0;
       else
 	{
 	  if (r_type != R_MIPS_REL32)
Index: bfd/elfxx-sparc.c
===================================================================
RCS file: /cvs/src/src/bfd/elfxx-sparc.c,v
retrieving revision 1.27
diff -u -p -r1.27 elfxx-sparc.c
--- bfd/elfxx-sparc.c	17 Oct 2006 13:41:47 -0000	1.27
+++ bfd/elfxx-sparc.c	2 Nov 2006 21:48:22 -0000
@@ -2755,8 +2755,13 @@ _bfd_sparc_elf_relocate_section (bfd *ou
 	  /* r_symndx will be zero only for relocs against symbols
 	     from removed linkonce sections, or sections discarded by
 	     a linker script.  */
-	  if (r_symndx == 0
-	      || (input_section->flags & SEC_ALLOC) == 0)
+	  if (r_symndx == 0)
+	    {
+	      _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
+	      break;
+	    }
+
+	  if ((input_section->flags & SEC_ALLOC) == 0)
 	    break;
 
 	  if ((info->shared
Index: bfd/libbfd-in.h
===================================================================
RCS file: /cvs/src/src/bfd/libbfd-in.h,v
retrieving revision 1.67
diff -u -p -r1.67 libbfd-in.h
--- bfd/libbfd-in.h	30 Oct 2006 23:25:50 -0000	1.67
+++ bfd/libbfd-in.h	2 Nov 2006 21:48:22 -0000
@@ -547,6 +547,10 @@ extern bfd_reloc_status_type _bfd_final_
 extern bfd_reloc_status_type _bfd_relocate_contents
   (reloc_howto_type *, bfd *, bfd_vma, bfd_byte *);
 
+/* Clear a given location using a given howto.  */
+extern void _bfd_clear_contents (reloc_howto_type *howto, bfd *input_bfd,
+				 bfd_byte *location);
+
 /* Link stabs in sections in the first pass.  */
 
 extern bfd_boolean _bfd_link_section_stabs
Index: bfd/libbfd.h
===================================================================
RCS file: /cvs/src/src/bfd/libbfd.h,v
retrieving revision 1.188
diff -u -p -r1.188 libbfd.h
--- bfd/libbfd.h	30 Oct 2006 23:25:50 -0000	1.188
+++ bfd/libbfd.h	2 Nov 2006 21:48:22 -0000
@@ -552,6 +552,10 @@ extern bfd_reloc_status_type _bfd_final_
 extern bfd_reloc_status_type _bfd_relocate_contents
   (reloc_howto_type *, bfd *, bfd_vma, bfd_byte *);
 
+/* Clear a given location using a given howto.  */
+extern void _bfd_clear_contents (reloc_howto_type *howto, bfd *input_bfd,
+				 bfd_byte *location);
+
 /* Link stabs in sections in the first pass.  */
 
 extern bfd_boolean _bfd_link_section_stabs
Index: bfd/reloc.c
===================================================================
RCS file: /cvs/src/src/bfd/reloc.c,v
retrieving revision 1.159
diff -u -p -r1.159 reloc.c
--- bfd/reloc.c	26 Oct 2006 00:22:52 -0000	1.159
+++ bfd/reloc.c	2 Nov 2006 21:48:22 -0000
@@ -1544,6 +1544,72 @@ _bfd_relocate_contents (reloc_howto_type
   return flag;
 }
 
+/* Clear a given location using a given howto, by applying a relocation value
+   of zero and discarding any in-place addend.  This is used for fixed-up
+   relocations against discarded symbols, to make ignorable debug or unwind
+   information more obvious.  */
+
+void
+_bfd_clear_contents (reloc_howto_type *howto,
+		     bfd *input_bfd,
+		     bfd_byte *location)
+{
+  int size;
+  bfd_vma x = 0;
+
+  /* Get the value we are going to relocate.  */
+  size = bfd_get_reloc_size (howto);
+  switch (size)
+    {
+    default:
+    case 0:
+      abort ();
+    case 1:
+      x = bfd_get_8 (input_bfd, location);
+      break;
+    case 2:
+      x = bfd_get_16 (input_bfd, location);
+      break;
+    case 4:
+      x = bfd_get_32 (input_bfd, location);
+      break;
+    case 8:
+#ifdef BFD64
+      x = bfd_get_64 (input_bfd, location);
+#else
+      abort ();
+#endif
+      break;
+    }
+
+  /* Zero out the unwanted bits of X.  */
+  x &= ~howto->dst_mask;
+
+  /* Put the relocated value back in the object file.  */
+  switch (size)
+    {
+    default:
+    case 0:
+      abort ();
+    case 1:
+      bfd_put_8 (input_bfd, x, location);
+      break;
+    case 2:
+      bfd_put_16 (input_bfd, x, location);
+      break;
+    case 4:
+      bfd_put_32 (input_bfd, x, location);
+      break;
+    case 8:
+#ifdef BFD64
+      bfd_put_64 (input_bfd, x, location);
+#else
+      abort ();
+#endif
+      break;
+    }
+}
+
 /*
 DOCDD
 INODE
Index: ld/testsuite/ld-discard/zero-rel.d
===================================================================
RCS file: ld/testsuite/ld-discard/zero-rel.d
diff -N ld/testsuite/ld-discard/zero-rel.d
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-discard/zero-rel.d	2 Nov 2006 21:48:23 -0000
@@ -0,0 +1,8 @@
+#source: zero-rel.s
+#ld: -T discard.ld
+#objdump: -s -j .debug_info
+
+.*:     file format .*elf.*
+
+Contents of section .debug_info:
+ 0000 0+( 0+)? +(\.+) .*
Index: ld/testsuite/ld-discard/zero-rel.s
===================================================================
RCS file: ld/testsuite/ld-discard/zero-rel.s
diff -N ld/testsuite/ld-discard/zero-rel.s
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-discard/zero-rel.s	2 Nov 2006 21:48:23 -0000
@@ -0,0 +1,11 @@
+	.text
+	.globl _start
+_start:
+
+	.section	.debug_info
+	.long	.Ltext
+	.long	.Ltext + 2
+
+	.section	.text.exit,"ax"
+.Ltext:
+	.long	0


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