diff --git a/bfd/ChangeLog b/bfd/ChangeLog index a174a4cfeb..8f2feae455 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,9 @@ +2018-01-11 H.J. Lu + + PR ld/22677 + * elflink.c (bfd_elf_gc_sections): Keep all PREINIT_ARRAY, + INIT_ARRAY as well as FINI_ARRAY sections for ld -r --gc-section. + 2017-09-27 Kuan-Lin Chen PR 22662 diff --git a/bfd/elflink.c b/bfd/elflink.c index 15d9c7e57b..4c92a048ce 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 ))) { diff --git a/ld/ChangeLog b/ld/ChangeLog index 83545d55aa..34fdb1f031 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,11 @@ +2018-01-11 H.J. Lu + + PR ld/22677 + * scripttempl/elf.sc (PREINIT_ARRAY): New. + Don't add .preinit_array for ld -r. + * testsuite/ld-elf/pr22677.d: New file. + * testsuite/ld-elf/pr22677.s: Likewise. + 2018-01-11 Andrew Burgess * ldexp.h (union etree_union): Remove defsym field. diff --git a/ld/scripttempl/elf.sc b/ld/scripttempl/elf.sc index 3de86b0fcf..139773dad0 100644 --- a/ld/scripttempl/elf.sc +++ b/ld/scripttempl/elf.sc @@ -245,6 +245,12 @@ test "${LARGE_SECTIONS}" = "yes" && LARGE_SECTIONS=" *(.ldata${RELOCATING+ .ldata.* .gnu.linkonce.l.*}) ${RELOCATING+. = ALIGN(. != 0 ? ${ALIGNMENT} : 1);} }" +PREINIT_ARRAY=".preinit_array ${RELOCATING-0} : + { + ${RELOCATING+${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__preinit_array_start = .);}} + KEEP (*(.preinit_array)) + ${RELOCATING+${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__preinit_array_end = .);}} + }" if test "${ENABLE_INITFINI_ARRAY}" = "yes"; then SORT_INIT_ARRAY="KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))" SORT_FINI_ARRAY="KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))" @@ -568,12 +574,7 @@ cat <