From: Alan Modra Date: Thu, 28 Jan 2021 00:00:36 +0000 (+1030) Subject: PR27259, SHF_LINK_ORDER self-link X-Git-Tag: binutils-2_35_2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7ed5ed075b9a166f74cf13be216b3e5cf04cd622;p=thirdparty%2Fbinutils-gdb.git PR27259, SHF_LINK_ORDER self-link This stops ld from endless looping on SHF_LINK_ORDER sh_link loops. bfd/ PR 27259 * elflink.c (_bfd_elf_gc_mark_extra_sections): Use linker_mark to prevent endless looping of linked-to sections. ld/ PR 27259 * ldelf.c (ldelf_before_place_orphans): Use linker_mark to prevent endless looping of linked-to sections. (cherry picked from commit def97fb945a98544938087eff3111e16ce58da6d) --- diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 2350c2f20f8..ceea15e4294 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,11 @@ +2021-01-30 Alan Modra + + Apply from master + 2021-01-28 Alan Modra + PR 27259 + * elflink.c (_bfd_elf_gc_mark_extra_sections): Use linker_mark to + prevent endless looping of linked-to sections. + 2021-01-28 Alan Modra Apply from master diff --git a/bfd/elflink.c b/bfd/elflink.c index 222a4573b00..28efeb91814 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -13499,15 +13499,23 @@ _bfd_elf_gc_mark_extra_sections (struct bfd_link_info *info, /* 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; + asection *linked_to_sec; + for (linked_to_sec = elf_linked_to_section (isec); + linked_to_sec != NULL && !linked_to_sec->linker_mark; 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 (linked_to_sec->gc_mark) + { + if (!_bfd_elf_gc_mark (info, isec, mark_hook)) + return FALSE; + break; + } + linked_to_sec->linker_mark = 1; + } + for (linked_to_sec = elf_linked_to_section (isec); + linked_to_sec != NULL && linked_to_sec->linker_mark; + linked_to_sec = elf_linked_to_section (linked_to_sec)) + linked_to_sec->linker_mark = 0; } if (!debug_frag_seen diff --git a/ld/ChangeLog b/ld/ChangeLog index e9374b46335..92275d72240 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,6 +1,11 @@ 2021-01-30 Alan Modra Apply from master + 2021-01-28 Alan Modra + PR 27259 + * ldelf.c (ldelf_before_place_orphans): Use linker_mark to + prevent endless looping of linked-to sections. + 2020-07-29 Alan Modra * ldelf.c (ldelf_before_place_orphans): Set SEC_EXCLUDE for discarded sections. diff --git a/ld/ldelf.c b/ld/ldelf.c index bcac331ff56..d5ddbeb0e83 100644 --- a/ld/ldelf.c +++ b/ld/ldelf.c @@ -2187,14 +2187,21 @@ ldelf_before_place_orphans (void) been discarded. */ asection *linked_to_sec; for (linked_to_sec = elf_linked_to_section (isec); - linked_to_sec != NULL; + linked_to_sec != NULL && !linked_to_sec->linker_mark; linked_to_sec = elf_linked_to_section (linked_to_sec)) - if (discarded_section (linked_to_sec)) - { - isec->output_section = bfd_abs_section_ptr; - isec->flags |= SEC_EXCLUDE; - break; - } + { + if (discarded_section (linked_to_sec)) + { + isec->output_section = bfd_abs_section_ptr; + isec->flags |= SEC_EXCLUDE; + break; + } + linked_to_sec->linker_mark = 1; + } + for (linked_to_sec = elf_linked_to_section (isec); + linked_to_sec != NULL && linked_to_sec->linker_mark; + linked_to_sec = elf_linked_to_section (linked_to_sec)) + linked_to_sec->linker_mark = 0; } } }