Skip to content

Commit fe0e833

Browse files
committed
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 def97fb)
1 parent 00e280d commit fe0e833

File tree

4 files changed

+42
-15
lines changed

4 files changed

+42
-15
lines changed

bfd/ChangeLog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
2021-01-28 Alan Modra <amodra@gmail.com>
2+
3+
PR 27259
4+
* elflink.c (_bfd_elf_gc_mark_extra_sections): Use linker_mark to
5+
prevent endless looping of linked-to sections.
6+
17
2021-01-29 Alan Modra <amodra@gmail.com>
28

39
PR 27271

bfd/elflink.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13827,15 +13827,23 @@ _bfd_elf_gc_mark_extra_sections (struct bfd_link_info *info,
1382713827
/* Since all sections, except for backend specific ones,
1382813828
have been garbage collected, call mark_hook on this
1382913829
section if any of its linked-to sections is marked. */
13830-
asection *linked_to_sec = elf_linked_to_section (isec);
13831-
for (; linked_to_sec != NULL;
13830+
asection *linked_to_sec;
13831+
for (linked_to_sec = elf_linked_to_section (isec);
13832+
linked_to_sec != NULL && !linked_to_sec->linker_mark;
1383213833
linked_to_sec = elf_linked_to_section (linked_to_sec))
13833-
if (linked_to_sec->gc_mark)
13834-
{
13835-
if (!_bfd_elf_gc_mark (info, isec, mark_hook))
13836-
return FALSE;
13837-
break;
13838-
}
13834+
{
13835+
if (linked_to_sec->gc_mark)
13836+
{
13837+
if (!_bfd_elf_gc_mark (info, isec, mark_hook))
13838+
return FALSE;
13839+
break;
13840+
}
13841+
linked_to_sec->linker_mark = 1;
13842+
}
13843+
for (linked_to_sec = elf_linked_to_section (isec);
13844+
linked_to_sec != NULL && linked_to_sec->linker_mark;
13845+
linked_to_sec = elf_linked_to_section (linked_to_sec))
13846+
linked_to_sec->linker_mark = 0;
1383913847
}
1384013848

1384113849
if (!debug_frag_seen

ld/ChangeLog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
2021-01-28 Alan Modra <amodra@gmail.com>
2+
3+
PR 27259
4+
* ldelf.c (ldelf_before_place_orphans): Use linker_mark to
5+
prevent endless looping of linked-to sections.
6+
17
2021-01-29 Alan Modra <amodra@gmail.com>
28

39
* testsuite/ld-tic6x/tic6x.exp: Add pr27271 test.

ld/ldelf.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2188,14 +2188,21 @@ ldelf_before_place_orphans (void)
21882188
been discarded. */
21892189
asection *linked_to_sec;
21902190
for (linked_to_sec = elf_linked_to_section (isec);
2191-
linked_to_sec != NULL;
2191+
linked_to_sec != NULL && !linked_to_sec->linker_mark;
21922192
linked_to_sec = elf_linked_to_section (linked_to_sec))
2193-
if (discarded_section (linked_to_sec))
2194-
{
2195-
isec->output_section = bfd_abs_section_ptr;
2196-
isec->flags |= SEC_EXCLUDE;
2197-
break;
2198-
}
2193+
{
2194+
if (discarded_section (linked_to_sec))
2195+
{
2196+
isec->output_section = bfd_abs_section_ptr;
2197+
isec->flags |= SEC_EXCLUDE;
2198+
break;
2199+
}
2200+
linked_to_sec->linker_mark = 1;
2201+
}
2202+
for (linked_to_sec = elf_linked_to_section (isec);
2203+
linked_to_sec != NULL && linked_to_sec->linker_mark;
2204+
linked_to_sec = elf_linked_to_section (linked_to_sec))
2205+
linked_to_sec->linker_mark = 0;
21992206
}
22002207
}
22012208
}

0 commit comments

Comments
 (0)