aboutsummaryrefslogtreecommitdiff
path: root/bfd/elflink.c
diff options
context:
space:
mode:
Diffstat (limited to 'bfd/elflink.c')
-rw-r--r--bfd/elflink.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/bfd/elflink.c b/bfd/elflink.c
index 15d9c7e..4c92a04 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -13428,11 +13428,19 @@ bfd_elf_gc_sections (bfd *abfd, struct bfd_link_info *info)
/* 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. */
+ of a group. We must keep all PREINIT_ARRAY, INIT_ARRAY as
+ well as FINI_ARRAY sections for ld -r. */
for (o = sub->sections; o != NULL; o = o->next)
if (!o->gc_mark
&& (o->flags & SEC_EXCLUDE) == 0
&& ((o->flags & SEC_KEEP) != 0
+ || (bfd_link_relocatable (info)
+ && ((elf_section_data (o)->this_hdr.sh_type
+ == SHT_PREINIT_ARRAY)
+ || (elf_section_data (o)->this_hdr.sh_type
+ == SHT_INIT_ARRAY)
+ || (elf_section_data (o)->this_hdr.sh_type
+ == SHT_FINI_ARRAY)))
|| (elf_section_data (o)->this_hdr.sh_type == SHT_NOTE
&& elf_next_in_group (o) == NULL )))
{