qsort: syms.c stab sorting
authorAlan Modra <amodra@gmail.com>
Mon, 14 Oct 2019 03:23:40 +0000 (13:53 +1030)
committerAlan Modra <amodra@gmail.com>
Mon, 14 Oct 2019 06:17:13 +0000 (16:47 +1030)
* syms.c (struct indexentry): Add idx field.
(cmpindexentry): Final sort on idx.
(_bfd_stab_section_find_nearest_line): Set idx.

bfd/ChangeLog
bfd/syms.c

index 3593fa815a938f0ee0a08782a79200a809c4645e..a1eaef95d8d904ea72b4655679ff2704dddf9eb9 100644 (file)
@@ -1,3 +1,9 @@
+2019-10-14  Alan Modra  <amodra@gmail.com>
+
+       * syms.c (struct indexentry): Add idx field.
+       (cmpindexentry): Final sort on idx.
+       (_bfd_stab_section_find_nearest_line): Set idx.
+
 2019-10-14  Alan Modra  <amodra@gmail.com>
 
        * dwarf2.c (struct lookup_funcinfo): Add idx field.
index 9a2754ebe69e674c4c958b95f2251e1dc2dcf727..146f674a1304c38b8dedda178995cad8f922a6f1 100644 (file)
@@ -884,6 +884,7 @@ struct indexentry
   char *directory_name;
   char *file_name;
   char *function_name;
+  int idx;
 };
 
 /* Compare two indexentry structures.  This is called via qsort.  */
@@ -896,10 +897,9 @@ cmpindexentry (const void *a, const void *b)
 
   if (contestantA->val < contestantB->val)
     return -1;
-  else if (contestantA->val > contestantB->val)
+  if (contestantA->val > contestantB->val)
     return 1;
-  else
-    return 0;
+  return contestantA->idx - contestantB->idx;
 }
 
 /* A pointer to this structure is stored in *pinfo.  */
@@ -1198,6 +1198,7 @@ _bfd_stab_section_find_nearest_line (bfd *abfd,
                  info->indextable[i].directory_name = directory_name;
                  info->indextable[i].file_name = file_name;
                  info->indextable[i].function_name = NULL;
+                 info->indextable[i].idx = i;
                  ++i;
                }
 
@@ -1257,6 +1258,7 @@ _bfd_stab_section_find_nearest_line (bfd *abfd,
              info->indextable[i].directory_name = directory_name;
              info->indextable[i].file_name = file_name;
              info->indextable[i].function_name = function_name;
+             info->indextable[i].idx = i;
              ++i;
              break;
            }
@@ -1270,6 +1272,7 @@ _bfd_stab_section_find_nearest_line (bfd *abfd,
          info->indextable[i].directory_name = directory_name;
          info->indextable[i].file_name = file_name;
          info->indextable[i].function_name = NULL;
+         info->indextable[i].idx = i;
          ++i;
        }
 
@@ -1279,6 +1282,7 @@ _bfd_stab_section_find_nearest_line (bfd *abfd,
       info->indextable[i].directory_name = NULL;
       info->indextable[i].file_name = NULL;
       info->indextable[i].function_name = NULL;
+      info->indextable[i].idx = i;
       ++i;
 
       info->indextablesize = i;