]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gprofng: Remove duplicate symbols
authorClaudiu Zissulescu <claudiu.zissulescu-ianculescu@oracle.com>
Mon, 31 Mar 2025 11:17:17 +0000 (14:17 +0300)
committerVladimir Mezentsev <vladimir.mezentsev@oracle.com>
Mon, 7 Apr 2025 01:23:56 +0000 (18:23 -0700)
Remove all duplicate symbols which can be in SymLst.  The duplication
is due to processing of both static and dynamic symbols.  The
Stabs::removeDupSyms function is called before computing symbol
aliases.

Introduce a new vector function (i.e., truncate()), that truncates a
vector lenght to the given new count.  This functionis used by
removeDupSyms function.

Signed-off-by: Claudiu Zissulescu <claudiu.zissulescu-ianculescu@oracle.com>
gprofng/src/Stabs.cc
gprofng/src/Stabs.h
gprofng/src/vec.h

index 2f64810b25f2fa83152f513b3159c786dea8089a..b98ac2838873d4c339696efe3119860ee9904e1c 100644 (file)
@@ -241,6 +241,40 @@ RelValueCmp (const void *a, const void *b)
          (item1->value == item2->value) ? 0 : -1;
 }
 
+/* Remove all duplicate symbols which can be in SymLst.  The
+   duplication is due to processing of both static and dynamic
+   symbols.  This function is called before computing symbol
+   aliases.  */
+
+void
+Stabs::removeDupSyms ()
+{
+  long ind, i, last;
+  Symbol *symA, *symB;
+  SymLst->sort (SymImgOffsetCmp);
+  dump ();
+
+  last = 0;
+  ind = SymLst->size ();
+  for (i = 0; i < ind; i++)
+    {
+      symA = SymLst->fetch (i);
+      if (symA->img_offset == 0) // Ignore this bad symbol
+       continue;
+
+      SymLst->put (last++, symA);
+      for (long k = i + 1; k < ind; k++, i++)
+       {
+         symB = SymLst->fetch (k);
+         if (symA->img_offset != symB->img_offset)
+           break;
+         if (strcmp (symA->name, symB->name) != 0)
+           break;
+       }
+    }
+  SymLst->truncate (last);
+}
+
 Stabs *
 Stabs::NewStabs (char *_path, char *lo_name)
 {
@@ -1801,6 +1835,7 @@ Stabs::readSymSec (Elf *elf, bool is_dynamic)
          }
        }
     }
+  removeDupSyms ();
   fixSymtabAlias ();
   SymLst->sort (SymValueCmp);
   get_save_addr (elf->need_swap_endian);
index a6a572d938c923712fa173c00a0e79f033adc63d..d34741f8f914acbbafd801cdef4ebc352104fe9b 100644 (file)
@@ -148,6 +148,7 @@ class Stabs {
     bool       st_check_symtab;
     Function   *createFunction(LoadObject *lo, Module *module, Symbol *sym);
     void        fixSymtabAlias();
+    void       removeDupSyms ();
 
     // Interface with dwarf
     Dwarf       *openDwarf();
index 04cce4eba7f9f52641b744ac0ac362aae6468ad2..a768a02b9e8c400c5b09e6ff6236ef32a1ea76c0 100644 (file)
@@ -112,6 +112,13 @@ public:
     return data[index];
   }
 
+  void
+  truncate (long ncount)
+  {
+    if (count > ncount && ncount >= 0)
+      count = ncount;
+  }
+
   // Return the first index in "this" that equals "item".
   // Return -1 if "item" is not found.
   long find (const ITEM item);