--- binutils.orig/bfd/elf64-ppc.c 2017-04-26 18:13:33.128533528 +0100
+++ binutils-2.25.1/bfd/elf64-ppc.c 2017-04-27 08:25:36.008300396 +0100
@@ -12087,6 +12087,13 @@ ppc64_elf_size_stubs (struct bfd_link_in
group_sections (htab, stub_group_size, stubs_always_before_branch);
+#define STUB_SHRINK_ITER 20
+ /* Loop until no stubs added. After iteration 20 of this loop we may
+ exit on a stub section shrinking. This is to break out of a
+ pathological case where adding stubs on one iteration decreases
+ section gaps (perhaps due to alignment), which then requires
+ fewer or smaller stubs on the next iteration. */
+
while (1)
{
bfd *input_bfd;
@@ -12404,7 +12411,10 @@ ppc64_elf_size_stubs (struct bfd_link_in
stub_sec = stub_sec->next)
if ((stub_sec->flags & SEC_LINKER_CREATED) == 0)
{
- stub_sec->rawsize = stub_sec->size;
+ if (htab->stub_iteration <= STUB_SHRINK_ITER
+ || stub_sec->rawsize < stub_sec->size)
+ /* Past STUB_SHRINK_ITER, rawsize is the max size seen. */
+ stub_sec->rawsize = stub_sec->size;
stub_sec->size = 0;
stub_sec->reloc_count = 0;
stub_sec->flags &= ~SEC_RELOC;
@@ -12461,7 +12471,9 @@ ppc64_elf_size_stubs (struct bfd_link_in
stub_sec != NULL;
stub_sec = stub_sec->next)
if ((stub_sec->flags & SEC_LINKER_CREATED) == 0
- && stub_sec->rawsize != stub_sec->size)
+ && stub_sec->rawsize != stub_sec->size
+ && (htab->stub_iteration <= STUB_SHRINK_ITER
+ || stub_sec->rawsize < stub_sec->size))
break;
/* Exit from this loop when no stubs have been added, and no stubs
@@ -12939,7 +12951,9 @@ ppc64_elf_build_stubs (struct bfd_link_i
if ((stub_sec->flags & SEC_LINKER_CREATED) == 0)
{
stub_sec_count += 1;
- if (stub_sec->rawsize != stub_sec->size)
+ if (stub_sec->rawsize != stub_sec->size
+ && (htab->stub_iteration <= STUB_SHRINK_ITER
+ || stub_sec->rawsize < stub_sec->size))
break;
}