]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
[gdb] Partially stabilize sort in compare_{symbols,msymbols}
authorTom de Vries <tdevries@suse.de>
Mon, 26 May 2025 13:15:31 +0000 (15:15 +0200)
committerTom de Vries <tdevries@suse.de>
Mon, 26 May 2025 13:15:31 +0000 (15:15 +0200)
commit511aa7976d6e9acffd3cb974b431dbef06ec93cc
tree13504c6add0e44f2ae80f882fb29272655e3d22d
parent6b4f72a01e60c854654a46f4faa555e258fa98b0
[gdb] Partially stabilize sort in compare_{symbols,msymbols}

In compare_symbols in gdb/linespec.c:
...
  uia = (uintptr_t) a.symbol->symtab ()->compunit ()->objfile ()->pspace ();
  uib = (uintptr_t) b.symbol->symtab ()->compunit ()->objfile ()->pspace ();

  if (uia < uib)
    return true;
  if (uia > uib)
     return false;
...
we compare pointers to struct program_space, which gives unstable sorting
results.

The assumption is that this doesn't matter, but as PR32202 demonstrates,
sometimes it does.

While PR32202 is fixed elsewhere, it seems like a good idea to stabilize this
comparison, because it comes at a small cost and possibly prevents
hard-to-reproduce user-visible ordering issues.

Fix this by comparing the program space IDs instead of the pointers.

Likewise in compare_msymbols.

Tested on x86_64-linux.

Reviewed-By: Guinevere Larsen <guinevere@redhat.com>
Approved-By: Andrew Burgess <aburgess@redhat.com>
gdb/linespec.c