Fix the sorting algorithm for reloc entries
authorTomoaki Kawada <kawada@kmckk.co.jp>
Thu, 16 Jun 2022 09:54:30 +0000 (09:54 +0000)
committerAlan Modra <amodra@gmail.com>
Sat, 18 Jun 2022 10:41:23 +0000 (20:11 +0930)
commitfba1ac87dcb76e61f270d236f1e7c8aaec80f9c4
tree4122da4e90d8f5897cec0d8719132794548883de
parent3f52a09075e3c62f2150375bb7fca338e7db45e7
Fix the sorting algorithm for reloc entries

The optimized insertion sort algorithm in `elf_link_adjust_relocs`
incorrectly assembled "runs" from unsorted entries and inserted them to an
already-sorted prefix, breaking the loop invariants of insertion sort.
This commit updates the run assembly loop to break upon encountering a
non-monotonic change in the sort key.

PR 29259
bfd/
* elflink.c (elf_link_adjust_relocs): Ensure run being inserted
is sorted.
ld/
* testsuite/ld-elf/pr29259.d,
* testsuite/ld-elf/pr29259.s,
* testsuite/ld-elf/pr29259.t: New test.
bfd/elflink.c
ld/testsuite/ld-elf/pr29259.d [new file with mode: 0644]
ld/testsuite/ld-elf/pr29259.s [new file with mode: 0644]
ld/testsuite/ld-elf/pr29259.t [new file with mode: 0644]