summaryrefslogtreecommitdiff
path: root/ld/ldelfgen.c
diff options
context:
space:
mode:
authorSandra Loosemore <sandra@codesourcery.com>2021-12-15 16:05:41 -0700
committerAlan Modra <amodra@gmail.com>2021-12-16 17:25:55 +1030
commit6628ac006d166a7e373846538a6097a3150946e9 (patch)
tree8d0083348d233804bbe39811fe6099b88098ab0f /ld/ldelfgen.c
parent05f62e0c9a0b14e211c6b2b6234095b50794b20b (diff)
downloadbinutils-gdb-6628ac006d166a7e373846538a6097a3150946e9.tar.gz
Adjust compare_link_order for unstable qsort
In a cross toolchain for nios2-elf target and x86_64-w64-mingw32 host using binutils 2.37, we observed a failure that didn't show up on x86_64-linux-gnu host: testcase pr25490-5.s was failing with C:\path\to\nios2-elf-ld.exe: looping in map_segments FAIL: __patchable_function_entries section 5 * ldelfgen.c (compare_link_order): Don't use section id in sorting. Keep original ordering instead. Update comments.
Diffstat (limited to 'ld/ldelfgen.c')
-rw-r--r--ld/ldelfgen.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/ld/ldelfgen.c b/ld/ldelfgen.c
index c456d4751e1..d86515a4892 100644
--- a/ld/ldelfgen.c
+++ b/ld/ldelfgen.c
@@ -173,8 +173,9 @@ compare_link_order (const void *a, const void *b)
if (! bfd_link_relocatable (&link_info))
{
- /* The only way we should get matching LMAs is when
- the first of the two sections has zero size. */
+ /* The only way we should get matching LMAs is when the first of
+ the two sections has zero size, or asec and bsec are the
+ same section. */
if (asec->size < bsec->size)
return -1;
else if (asec->size > bsec->size)
@@ -183,7 +184,7 @@ compare_link_order (const void *a, const void *b)
/* If they are both zero size then they almost certainly have the same
VMA and thus are not ordered with respect to each other. Test VMA
- anyway, and fall back to id to make the result reproducible across
+ anyway, and fall back to idx to make the result reproducible across
qsort implementations. */
apos = asec->output_section->vma + asec->output_offset;
bpos = bsec->output_section->vma + bsec->output_offset;
@@ -191,8 +192,8 @@ compare_link_order (const void *a, const void *b)
return -1;
else if (apos > bpos)
return 1;
-
- return asec->id - bsec->id;
+ else
+ return ai->idx - bi->idx;
}
/* Rearrange sections with SHF_LINK_ORDER into the same order as their