diff options
author | Alan Modra <amodra@gmail.com> | 2011-06-14 02:45:12 +0000 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2011-06-14 02:45:12 +0000 |
commit | 7f6ab9f8b9a5164d34c5d0b85ad4bfb8d51d89fb (patch) | |
tree | a6bbfb3426ae13110d87c3a0b45b79498d0682ca /bfd/elflink.c | |
parent | c6431bc3708cda380b0bdc35d11827882e803f2d (diff) | |
download | gdb-7f6ab9f8b9a5164d34c5d0b85ad4bfb8d51d89fb.zip gdb-7f6ab9f8b9a5164d34c5d0b85ad4bfb8d51d89fb.tar.gz gdb-7f6ab9f8b9a5164d34c5d0b85ad4bfb8d51d89fb.tar.bz2 |
PR ld/12851
* elflink.c (_bfd_elf_gc_mark_extra_sections): New function.
(elf_gc_sweep): Don't treat debug and sections like .comment
specially here.
(bfd_elf_gc_sections): Treat note sections as gc roots only when
not part of a group. Always call gc_mark_extra_sections.
* elf-bfd.h (_bfd_elf_gc_mark_extra_sections): Declare.
* elfxx-target.h (elf_backend_gc_mark_extra_sections): Default to
_bfd_elf_gc_mark_extra_sections.
* elf32-arm.c (elf32_arm_gc_mark_extra_sections): Call
_bfd_elf_gc_mark_extra_sections.
* elf32-tic6x.c (elf32_tic6x_gc_mark_extra_sections): Likewise.
Diffstat (limited to 'bfd/elflink.c')
-rw-r--r-- | bfd/elflink.c | 69 |
1 files changed, 55 insertions, 14 deletions
diff --git a/bfd/elflink.c b/bfd/elflink.c index 9d2d68a..a4b7a7a 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -11633,6 +11633,49 @@ _bfd_elf_gc_mark (struct bfd_link_info *info, return ret; } +/* Keep debug and special sections. */ + +bfd_boolean +_bfd_elf_gc_mark_extra_sections (struct bfd_link_info *info, + elf_gc_mark_hook_fn mark_hook ATTRIBUTE_UNUSED) +{ + bfd *ibfd; + + for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) + { + asection *isec; + bfd_boolean some_kept; + + if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour) + continue; + + /* Ensure all linker created sections are kept, and see whether + any other section is already marked. */ + some_kept = FALSE; + for (isec = ibfd->sections; isec != NULL; isec = isec->next) + { + if ((isec->flags & SEC_LINKER_CREATED) != 0) + isec->gc_mark = 1; + else if (isec->gc_mark) + some_kept = TRUE; + } + + /* If no section in this file will be kept, then we can + toss out debug sections. */ + if (!some_kept) + continue; + + /* Keep debug and special sections like .comment when they are + not part of a group. */ + for (isec = ibfd->sections; isec != NULL; isec = isec->next) + if (elf_next_in_group (isec) == NULL + && ((isec->flags & SEC_DEBUGGING) != 0 + || (isec->flags & (SEC_ALLOC | SEC_LOAD | SEC_RELOC)) == 0)) + isec->gc_mark = 1; + } + return TRUE; +} + /* Sweep symbols in swept sections. Called via elf_link_hash_traverse. */ struct elf_gc_sweep_symbol_info @@ -11690,12 +11733,6 @@ elf_gc_sweep (bfd *abfd, struct bfd_link_info *info) asection *first = elf_next_in_group (o); o->gc_mark = first->gc_mark; } - else if ((o->flags & (SEC_DEBUGGING | SEC_LINKER_CREATED)) != 0 - || (o->flags & (SEC_ALLOC | SEC_LOAD | SEC_RELOC)) == 0) - { - /* Keep debug and special sections. */ - o->gc_mark = 1; - } if (o->gc_mark) continue; @@ -11966,19 +12003,23 @@ bfd_elf_gc_sections (bfd *abfd, struct bfd_link_info *info) if (bfd_get_flavour (sub) != bfd_target_elf_flavour) continue; - /* Also keep SHT_NOTE sections. */ + /* Start at sections marked with SEC_KEEP (ref _bfd_elf_gc_keep). + Also treat note sections as a root, if the section is not part + of a group. */ for (o = sub->sections; o != NULL; o = o->next) - if ((o->flags & SEC_EXCLUDE) == 0 + if (!o->gc_mark + && (o->flags & SEC_EXCLUDE) == 0 && ((o->flags & SEC_KEEP) != 0 - || elf_section_data (o)->this_hdr.sh_type == SHT_NOTE) - && !o->gc_mark) - if (!_bfd_elf_gc_mark (info, o, gc_mark_hook)) - return FALSE; + || (elf_section_data (o)->this_hdr.sh_type == SHT_NOTE + && elf_next_in_group (o) == NULL ))) + { + if (!_bfd_elf_gc_mark (info, o, gc_mark_hook)) + return FALSE; + } } /* Allow the backend to mark additional target specific sections. */ - if (bed->gc_mark_extra_sections) - bed->gc_mark_extra_sections (info, gc_mark_hook); + bed->gc_mark_extra_sections (info, gc_mark_hook); /* ... and mark SEC_EXCLUDE for those that go. */ return elf_gc_sweep (abfd, info); |