ELF: Support the section flag 'o' in .section directive
[deliverable/binutils-gdb.git] / bfd / elflink.c
index 5217528a79b2c61a33fecc0d32e07375f33a359a..30a572d32de8b501a7d7ba50ee69b2bab961958a 100644 (file)
@@ -13316,7 +13316,7 @@ _bfd_elf_gc_mark_debug_special_section_group (asection *grp)
 
 bfd_boolean
 _bfd_elf_gc_mark_extra_sections (struct bfd_link_info *info,
-                                elf_gc_mark_hook_fn mark_hook ATTRIBUTE_UNUSED)
+                                elf_gc_mark_hook_fn mark_hook)
 {
   bfd *ibfd;
 
@@ -13345,6 +13345,21 @@ _bfd_elf_gc_mark_extra_sections (struct bfd_link_info *info,
                   && (isec->flags & SEC_ALLOC) != 0
                   && elf_section_type (isec) != SHT_NOTE)
            some_kept = TRUE;
+         else
+           {
+             /* Since all sections, except for backend specific ones,
+                have been garbage collected, call mark_hook on this
+                section if any of its linked-to sections is marked.  */
+             asection *linked_to_sec = elf_linked_to_section (isec);
+             for (; linked_to_sec != NULL;
+                  linked_to_sec = elf_linked_to_section (linked_to_sec))
+               if (linked_to_sec->gc_mark)
+                 {
+                   if (!_bfd_elf_gc_mark (info, isec, mark_hook))
+                     return FALSE;
+                   break;
+                 }
+           }
 
          if (!debug_frag_seen
              && (isec->flags & SEC_DEBUGGING)
@@ -13359,14 +13374,16 @@ _bfd_elf_gc_mark_extra_sections (struct bfd_link_info *info,
 
       /* Keep debug and special sections like .comment when they are
         not part of a group.  Also keep section groups that contain
-        just debug sections or special sections.  */
+        just debug sections or special sections.  NB: Sections with
+        linked-to section has been handled above.  */
       for (isec = ibfd->sections; isec != NULL; isec = isec->next)
        {
          if ((isec->flags & SEC_GROUP) != 0)
            _bfd_elf_gc_mark_debug_special_section_group (isec);
          else if (((isec->flags & SEC_DEBUGGING) != 0
                    || (isec->flags & (SEC_ALLOC | SEC_LOAD | SEC_RELOC)) == 0)
-                  && elf_next_in_group (isec) == NULL)
+                  && elf_next_in_group (isec) == NULL
+                  && elf_linked_to_section (isec) == NULL)
            isec->gc_mark = 1;
          if (isec->gc_mark && (isec->flags & SEC_DEBUGGING) != 0)
            has_kept_debug_info = TRUE;
This page took 0.046564 seconds and 4 git commands to generate.