gdb: Ensure that !(a < a) is true in sort_cmp on obj_section objects
After the switch to use std::sort, if GDB is compiled with the
-D_GLIBCXX_DEBUG=1 flag then we see an error when using sort_cmp (in
objfiles.c) to sort obj_section objects.
The problem is that std::sort checks that the condition !(a < a)
holds, and currently this is not true. GDB's sort_cmp is really
designed to sort lists in which no obj_section repeats, however, there
is some code in place to try and ensure we get a stable sort order if
there is a bug in GDB, unfortunately this code fails the above check.
By reordering some of the checks inside sort_cmp, it is pretty easy to
ensure that the !(a < a) condition holds.
I've not bothered to make this condition check optimal, like I said
this code is only in place to ensure that we get stable results if GDB
goes wrong, so I've made the smallest change needed to get the correct
behaviour.
After this commit I see no regressions when running GDB compiled with
-D_GLIBCXX_DEBUG=1.
gdb/ChangeLog:
* objfiles.c (sort_cmp): Ensure that !(a < a) holds true.
Change-Id: I4b1e3e1640865104c0896cbb6c3fdbbc04d9645b