From 0672748ac053cc4f8159af0d21ca88ae8b3778e6 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Fri, 30 Apr 2010 18:27:32 +0000 Subject: Remove relocation against discarded sections for relocatable link. bfd/ 2010-04-30 H.J. Lu PR ld/11542 * elf-bfd.h (RELOC_AGAINST_DISCARDED_SECTION): New. * elf32-i386.c (elf_i386_relocate_section): Use it. * elf64-x86-64.c (elf64_x86_64_relocate_section): Likewise. ld/testsuite/ 2010-04-30 H.J. Lu PR ld/11542 * ld-elf/discard.ld: New. * ld-elf/discard1.d: Likewise. * ld-elf/discard1.s: Likewise. * ld-elf/discard2.d: Likewise. * ld-elf/discard2.s: Likewise. * ld-elf/discard3.d: Likewise. --- bfd/ChangeLog | 8 ++++++++ bfd/elf-bfd.h | 42 ++++++++++++++++++++++++++++++++++++++++++ bfd/elf32-i386.c | 11 ++--------- bfd/elf64-x86-64.c | 11 ++--------- 4 files changed, 54 insertions(+), 18 deletions(-) (limited to 'bfd') diff --git a/bfd/ChangeLog b/bfd/ChangeLog index e3a1e53f7ac..74dd28b22ba 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,11 @@ +2010-04-30 H.J. Lu + + PR ld/11542 + * elf-bfd.h (RELOC_AGAINST_DISCARDED_SECTION): New. + + * elf32-i386.c (elf_i386_relocate_section): Use it. + * elf64-x86-64.c (elf64_x86_64_relocate_section): Likewise. + 2010-04-30 Tristan Gingold * vms-lib.c (vms_read_block): New function. diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h index 0c975dcb518..226b95fe86a 100644 --- a/bfd/elf-bfd.h +++ b/bfd/elf-bfd.h @@ -2328,6 +2328,48 @@ extern asection _bfd_elf_large_com_section; } \ while (0) +/* This macro is to avoid lots of duplicated code in the body of the + loop over relocations in xxx_relocate_section() in the various + elfxx-xxxx.c files. + + Handle relocations against symbols from removed linkonce sections, + or sections discarded by a linker script. When doing a relocatable + link, we remove such relocations. Otherwise, we just want the + section contents zeroed and avoid any special processing. */ +#define RELOC_AGAINST_DISCARDED_SECTION(info, input_bfd, input_section, \ + rel, relend, howto, contents) \ + { \ + if (info->relocatable \ + && (input_section->flags & SEC_DEBUGGING)) \ + { \ + /* Only remove relocations in debug sections since other \ + sections may require relocations. */ \ + Elf_Internal_Shdr *rel_hdr; \ + \ + rel_hdr = &elf_section_data (input_section->output_section)->rel_hdr; \ + \ + /* Avoid empty output section. */ \ + if (rel_hdr->sh_size > rel_hdr->sh_entsize) \ + { \ + rel_hdr->sh_size -= rel_hdr->sh_entsize; \ + rel_hdr = &elf_section_data (input_section)->rel_hdr; \ + rel_hdr->sh_size -= rel_hdr->sh_entsize; \ + \ + memmove (rel, rel + 1, (relend - rel) * sizeof (*rel)); \ + \ + input_section->reloc_count--; \ + relend--; \ + rel--; \ + continue; \ + } \ + } \ + \ + _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset); \ + rel->r_info = 0; \ + rel->r_addend = 0; \ + continue; \ + } + /* Will a symbol be bound to the the definition within the shared library, if any. A unique symbol can never be bound locally. */ #define SYMBOLIC_BIND(INFO, H) \ diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c index 395a6bbef83..7964c4fd6e1 100644 --- a/bfd/elf32-i386.c +++ b/bfd/elf32-i386.c @@ -2955,15 +2955,8 @@ elf_i386_relocate_section (bfd *output_bfd, } if (sec != NULL && elf_discarded_section (sec)) - { - /* For relocs against symbols from removed linkonce sections, - or sections discarded by a linker script, we just want the - section contents zeroed. Avoid any special processing. */ - _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset); - rel->r_info = 0; - rel->r_addend = 0; - continue; - } + RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section, + rel, relend, howto, contents); if (info->relocatable) continue; diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c index 3a24ccae578..21524fa7495 100644 --- a/bfd/elf64-x86-64.c +++ b/bfd/elf64-x86-64.c @@ -2685,15 +2685,8 @@ elf64_x86_64_relocate_section (bfd *output_bfd, struct bfd_link_info *info, } if (sec != NULL && elf_discarded_section (sec)) - { - /* For relocs against symbols from removed linkonce sections, - or sections discarded by a linker script, we just want the - section contents zeroed. Avoid any special processing. */ - _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset); - rel->r_info = 0; - rel->r_addend = 0; - continue; - } + RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section, + rel, relend, howto, contents); if (info->relocatable) continue; -- cgit v1.2.1