[PATCH] Elf: Adjust compare_link_order for unstable qsort.
Sandra Loosemore
sandra@codesourcery.com
Wed Dec 15 23:05:41 GMT 2021
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
I tracked this down to the SHF_LINK_ORDER sorting added in commit
b209b5a6b8a4433be961a0f016439f381de65bfc. Having run into similar
problems before, I know that the qsort implementation provided by
Windows host is not a stable sort, and sure enough, that was what was
going wrong here too. So I made the comparison function work harder to
avoid returning 0; it's already falling back to using the idx field
comparison at an earlier point in the function and I think that is
exactly what we want to prevent the unstable qsort from flipping the
order of entries that otherwise compare as equal.
OK for trunk? Besides testing this in the aforementioned nios2
cross-toolchain, I also checked that it worked OK on a native
x86_64-linux-gnu trunk build.
-Sandra
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pr25490.patch
Type: text/x-patch
Size: 1001 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20211215/9035a8db/attachment-0001.bin>
More information about the Binutils
mailing list