This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[pushed] Re: [RFA 1/6] Use std::vector in end_symtab_get_static_block


Tom Tromey wrote:
> >>>>> "Ulrich" == Ulrich Weigand <uweigand@de.ibm.com> writes:
> 
> Ulrich> Now, the reason why we re-sort pending_blocks here is to allow
> Ulrich> for object code reordering (hot/cold sections and the like).
> Ulrich> But this type of reordering never actually affects inline function
> Ulrich> relationships.  So it may be that just using stable_sort here is
> Ulrich> actually the *correct* fix ...
> 
> I tend to think so as well, for the reasons you mentioned.
> glibc doesn't claim that qsort is stable, but maybe it is in practice
> sometimes?

I just had a look at the glibc qsort implementation.  It actually uses
(in the common case) a *merge sort* into a temporary buffer, which is
always stable.  The GNU libstdc++ std::sort on the other hand seems to
use an in-place quicksort algorithm, which is generally not stable.
This would explain the difference.

I've now pushed the patch in the form below.

Thanks,
Ulrich

gdb/ChangeLog:
2017-10-24  Ulrich Weigand  <uweigand@de.ibm.com>

	* buildsym.c (end_symtab_get_static_block): Use std::stable_sort.

diff --git a/gdb/buildsym.c b/gdb/buildsym.c
index c556ac1..07bfbd5 100644
--- a/gdb/buildsym.c
+++ b/gdb/buildsym.c
@@ -1249,12 +1249,14 @@ end_symtab_get_static_block (CORE_ADDR end_addr, int expandable, int required)
       for (pb = pending_blocks; pb != NULL; pb = pb->next)
 	barray.push_back (pb->block);
 
-      std::sort (barray.begin (), barray.end (),
-		 [] (const block *a, const block *b)
-		 {
-		   /* Sort blocks in descending order.  */
-		   return BLOCK_START (a) > BLOCK_START (b);
-		 });
+      /* Sort blocks by start address in descending order.  Blocks with the
+	 same start address must remain in the original order to preserve
+	 inline function caller/callee relationships.  */
+      std::stable_sort (barray.begin (), barray.end (),
+			[] (const block *a, const block *b)
+			{
+			  return BLOCK_START (a) > BLOCK_START (b);
+			});
 
       int i = 0;
       for (pb = pending_blocks; pb != NULL; pb = pb->next)

-- 
  Dr. Ulrich Weigand
  GNU/Linux compilers and toolchain
  Ulrich.Weigand@de.ibm.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]