pointer comparison breaks Solaris' qsort
Alexandre Oliva
aoliva@redhat.com
Tue Jun 8 09:53:00 GMT 2004
This patch fixes a linker crash caused by inconsistent results being
returned by the function passed to qsort(). In certain cases, when it
returns the same value when comparing both a with b and b with a, the
qsort function may end up being called with a pointer that's not
within the bounds of the array passed to qsort().
The inconsistent results were caused by computing the difference
between two pointers to objects that were not part of the same array,
which invokes undefined behavior. In the common failing cases, the
pointers to section do not differ by a multiple of 160 (the section
size), so when we perform an optimized divide of the byte difference
by the size, we get something that looks like garbage, and that
doesn't satisfy the property that compare (a, b) == - compare (b, a).
Anyway, comparing pointers is always a bad idea, since it means we may
get different results depending on the build machine.
I'm tempted to install it as obvious, but I'll ask... Ok to install?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bfd-elf-sort-symbol-solaris-crash.patch
Type: text/x-patch
Size: 722 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20040608/2fd6a133/attachment.bin>
-------------- next part --------------
--
Alexandre Oliva http://www.ic.unicamp.br/~oliva/
Red Hat Compiler Engineer aoliva@{redhat.com, gcc.gnu.org}
Free Software Evangelist oliva@{lsd.ic.unicamp.br, gnu.org}
More information about the Binutils
mailing list