summaryrefslogtreecommitdiff
path: root/bfd/reloc.c
diff options
context:
space:
mode:
authorDaniel Jacobowitz <dan@debian.org>2006-11-03 00:58:10 +0000
committerDaniel Jacobowitz <dan@debian.org>2006-11-03 00:58:10 +0000
commit4cafd9ff8e8fc7d7154f39b4d36a9f0b9de53ca6 (patch)
tree2f50d79012023ea870d5e9f7628e684b9d6ab605 /bfd/reloc.c
parent7ae0857aca81d00b2a980dc6a6114f2652e1cab5 (diff)
downloadbinutils-redhat-4cafd9ff8e8fc7d7154f39b4d36a9f0b9de53ca6.tar.gz
bfd/
* 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.
Diffstat (limited to 'bfd/reloc.c')
-rw-r--r--bfd/reloc.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/bfd/reloc.c b/bfd/reloc.c
index 09b888f3d5..1b8c8d75e7 100644
--- a/bfd/reloc.c
+++ b/bfd/reloc.c
@@ -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