diff --git a/bfd/elflink.c b/bfd/elflink.c index e768634..bddfbe2 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -11982,13 +11982,19 @@ _bfd_elf_gc_mark_extra_sections (struct bfd_link_info *info, if (!some_kept) continue; - /* Keep debug and special sections like .comment when they are - not part of a group, or when we have single-member groups. */ + /* Keep special sections like .comment when they are not part of + a group, or when we have single-member groups. + Keep all kinds of debug sections. Debug section could exist + as an individual section or a member of a section group. + It is also possible that we have relocations from one debug + section to another debug section. Selective elimination of + debug section can cause incorrect resolution of relocations + and break tools like gdb that consume them. */ for (isec = ibfd->sections; isec != NULL; isec = isec->next) - if ((elf_next_in_group (isec) == NULL - || elf_next_in_group (isec) == isec) - && ((isec->flags & SEC_DEBUGGING) != 0 - || (isec->flags & (SEC_ALLOC | SEC_LOAD | SEC_RELOC)) == 0)) + if ((isec->flags & SEC_DEBUGGING) != 0 + || ((elf_next_in_group (isec) == NULL + || elf_next_in_group (isec) == isec) + && (isec->flags & (SEC_ALLOC | SEC_LOAD | SEC_RELOC)) == 0)) isec->gc_mark = 1; if (! debug_frag_seen)