The qsort() routine is noted to be unpredictable if 2 compared objects are considered equal. The 'compare_symbols' function in the bfd/elf64-ppc.c file compares attributes of various symbols up to a point. Where there can be a problem is if there are 2 symbols with different names, but identical attributes. In this case, the current definition of 'compare_symbols' just does a: return 0; at the end of the function. This, however, results in different behavior in the TLS opt 3 testcase of the linker when the test suite is run on different OSes. A standard was created for that test case on Linux. When this is run on a Windows system, however, the test fails: regexp_diff match failure regexp "^00000000100000e8 <\.__tls_get_addr>:$" line "00000000100000e8 <.__tls_get_addr_opt>:" regexp_diff match failure regexp "^.*: (4b ff ff ed|ed ff ff 4b) bl 100000e8 <\.__tls_get_addr>$" line " 100000fc: 4b ff ff ed bl 100000e8 <.__tls_get_addr_opt>" regexp_diff match failure regexp "^.*: (4b ff ff e1|e1 ff ff 4b) bl 100000e8 <\.__tls_get_addr>$" line " 10000108: 4b ff ff e1 bl 100000e8 <.__tls_get_addr_opt>" To get predictable results between Linux and Windows, the last line of 'compare_symbols' should be changed to be: return strcmp(a->name,b->name); With that change, if symbols have different attributes, then they continue to be handled as before. If, however, symbols are identical except for having different names (i.e., 2 symbols referring to the same location), then that will allow qsort() to produce identical output for different OSes.
Paul, You can try to add qsort.c (from glibc for instance) into libiberty to get the same behaviour on different OSes.
This one is easy to fix in elf64-ppc.c, because we are sorting an array of pointers. The value of the pointer can be the final key.
The master branch has been updated by Alan Modra <amodra@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=aaed6f5be3a41a88cc13c744e88af78f5a42dd5b commit aaed6f5be3a41a88cc13c744e88af78f5a42dd5b Author: Alan Modra <amodra@gmail.com> Date: Mon Mar 20 08:25:50 2017 +1030 PR 21266, unstable qsort in bfd/elf64-ppc.c PR 21266 * elf64-ppc.c (compare_symbols): Stabilize sort.
Fixed.