]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
bfd/
authorDaniel Jacobowitz <drow@false.org>
Fri, 3 Nov 2006 00:58:10 +0000 (00:58 +0000)
committerDaniel Jacobowitz <drow@false.org>
Fri, 3 Nov 2006 00:58:10 +0000 (00:58 +0000)
* 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.
ld/testsuite/
* ld-discard/zero-rel.d, ld-discard/zero-rel.s: New files.

21 files changed:
bfd/ChangeLog
bfd/elf32-arm.c
bfd/elf32-d10v.c
bfd/elf32-hppa.c
bfd/elf32-i386.c
bfd/elf32-ppc.c
bfd/elf32-s390.c
bfd/elf32-sh.c
bfd/elf32-xtensa.c
bfd/elf64-ppc.c
bfd/elf64-s390.c
bfd/elf64-x86-64.c
bfd/elfxx-ia64.c
bfd/elfxx-mips.c
bfd/elfxx-sparc.c
bfd/libbfd-in.h
bfd/libbfd.h
bfd/reloc.c
ld/testsuite/ChangeLog
ld/testsuite/ld-discard/zero-rel.d [new file with mode: 0644]
ld/testsuite/ld-discard/zero-rel.s [new file with mode: 0644]

index 052a2d195c17e3a246b3eaaa07add8f91ed005ca..3b97d52c9af9bf6512c2da15c834e792fe8ed705 100644 (file)
@@ -1,3 +1,27 @@
+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-01  Thiemo Seufer  <ths@mips.com>
             David Ung  <davidu@mips.com>
 
index 2faac89db550ef7c0397dc62d5c3b9a2095ce81f..f8eff7089fcefe96d8dea4b08de2ba717c3c4deb 100644 (file)
@@ -3664,7 +3664,10 @@ elf32_arm_final_link_relocate (reloc_howto_type *           howto,
         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 e5d546a9e8cb899f3a2488d1d74f7b85cd05f51c..8d7cd944f7b76638135e04c67034eef02ccc5422 100644 (file)
@@ -469,6 +469,16 @@ elf32_d10v_relocate_section (bfd *output_bfd,
                                   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 db6e84212b1d383785ebbc49a41cc089e3abcde1..c448aac26f3b2d824ecf6a2185c0810883e22856 100644 (file)
@@ -3942,8 +3942,14 @@ elf32_hppa_relocate_section (bfd *output_bfd,
          /* 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 97054a5ae18ad904ce5a90a63063d4c3e8fc56e9..7a83c733af0f8f1e4fecdf1754c9a0567bdaa145 100644 (file)
@@ -2395,17 +2395,12 @@ elf_i386_relocate_section (bfd *output_bfd,
 
       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 59bac504bd51bca744c48f7488e6a8423f084d9f..281fab0155d64e6a58f5853064045474638ca3bc 100644 (file)
@@ -6180,7 +6180,10 @@ ppc_elf_relocate_section (bfd *output_bfd,
             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 83bf5e12c15dbca25fc59772d63a83901bf95523..01ee6a5a15962ab58b5bfe77a3248007aca4f204 100644 (file)
@@ -2543,8 +2543,13 @@ elf_s390_relocate_section (output_bfd, info, input_bfd, input_section,
          /* 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 85f3d8ff6d1818c82c8e75633cb46cbbed159d85..8e53056f332a79c9954736d694db72d5d5963b3d 100644 (file)
@@ -3557,6 +3557,15 @@ sh_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
        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 34f7f47fe0b11d9f30afc09b653e1df0a41472db..59ed4ba3221573b45520d4d87bef19acc7a4c7ff 100644 (file)
@@ -2270,6 +2270,16 @@ elf_xtensa_relocate_section (bfd *output_bfd,
          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 886f987d0a82c127a1fefd39acd4bd1e709e1f81..52b3e623fa515520cd8edb3cd4359eb72401916d 100644 (file)
@@ -10728,7 +10728,11 @@ ppc64_elf_relocate_section (bfd *output_bfd,
             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 1d8682046683c799917c86872b8111debff220f9..443f3254160baa288260d509ee6b9f62dce0a29a 100644 (file)
@@ -2522,8 +2522,13 @@ elf_s390_relocate_section (output_bfd, info, input_bfd, input_section,
          /* 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 2556fdce4f949a2e332e2fd4f0a2600d3ac8c878..b6c973f6dbc8bff6acabd1fc49b8cc4c6f9bd0c9 100644 (file)
@@ -2370,8 +2370,13 @@ elf64_x86_64_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
          /* 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 dbea35bd33e86afce30da67b9aacb984e7b29386..2fc555083f2a72c4f8f1e88550ba068d2db777d8 100644 (file)
@@ -4751,6 +4751,12 @@ elfNN_ia64_relocate_section (output_bfd, info, input_bfd, input_section,
        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 747c91cfe7ecfe2df3e07293099a1b0ba10a1eff..8f1fb6db6eeb834d28dceb304fe8af106d184cdd 100644 (file)
@@ -4323,6 +4323,11 @@ mips_elf_calculate_relocation (bfd *abfd, bfd *input_bfd,
                                                   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 77ffbfeeed8e22e25f1670ef6404b197d50213ea..3b64aca375b701c7058f6e622b093b96198d0c5d 100644 (file)
@@ -2755,8 +2755,13 @@ _bfd_sparc_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
          /* 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 a9c96db4e9fe05b82c106793ef3da1bd0eed1fc8..3de9ed410a1c1b5568747d9e1164cef3bfbdf2c2 100644 (file)
@@ -547,6 +547,10 @@ extern bfd_reloc_status_type _bfd_final_link_relocate
 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 92dfc151de411fbd806d13ea4f268802d9d16581..8c552643fb089a6517a52ed2bfb63e92114726f3 100644 (file)
@@ -552,6 +552,10 @@ extern bfd_reloc_status_type _bfd_final_link_relocate
 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 09b888f3d5568a6efa279159c47b96e2f54b42ae..1b8c8d75e762bfc6927e207c44cc757fc806e4eb 100644 (file)
@@ -1544,6 +1544,72 @@ _bfd_relocate_contents (reloc_howto_type *howto,
   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 42fd441dd176ea3e6fd6d8d080a32f8aa6b8fbcc..e22293315835626976e415a568310b5f31d73f43 100644 (file)
@@ -1,3 +1,7 @@
+2006-11-02  Daniel Jacobowitz  <dan@codesourcery.com>
+
+       * ld-discard/zero-rel.d, ld-discard/zero-rel.s: New files.
+
 2006-11-01  Thiemo Seufer  <ths@mips.com>
 
        * ld-mips-elf/mips16-intermix-1.s, ld-mips-elf/mips16-intermix-2.s,
diff --git a/ld/testsuite/ld-discard/zero-rel.d b/ld/testsuite/ld-discard/zero-rel.d
new file mode 100644 (file)
index 0000000..1f73775
--- /dev/null
@@ -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+)? +(\.+) .*
diff --git a/ld/testsuite/ld-discard/zero-rel.s b/ld/testsuite/ld-discard/zero-rel.s
new file mode 100644 (file)
index 0000000..f3f0b3c
--- /dev/null
@@ -0,0 +1,11 @@
+       .text
+       .globl _start
+_start:
+
+       .section        .debug_info
+       .long   .Ltext
+       .long   .Ltext + 2
+
+       .section        .text.exit,"ax"
+.Ltext:
+       .long   0