aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudiu Zissulescu <claudiu.zissulescu-ianculescu@oracle.com>2025-03-31 14:17:17 +0300
committerVladimir Mezentsev <vladimir.mezentsev@oracle.com>2025-04-06 18:23:56 -0700
commit50491ef1d395badbffabe192433d2c6010bc2f15 (patch)
tree0a13066d044dbeed0e6469e62a774df17a6f34ff
parent13f614be23ab6ef1018ddf9c133175e806e68ed8 (diff)
downloadgdb-50491ef1d395badbffabe192433d2c6010bc2f15.zip
gdb-50491ef1d395badbffabe192433d2c6010bc2f15.tar.gz
gdb-50491ef1d395badbffabe192433d2c6010bc2f15.tar.bz2
gprofng: Remove duplicate symbols
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>
-rw-r--r--gprofng/src/Stabs.cc35
-rw-r--r--gprofng/src/Stabs.h1
-rw-r--r--gprofng/src/vec.h7
3 files changed, 43 insertions, 0 deletions
diff --git a/gprofng/src/Stabs.cc b/gprofng/src/Stabs.cc
index 2f64810..b98ac28 100644
--- a/gprofng/src/Stabs.cc
+++ b/gprofng/src/Stabs.cc
@@ -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);
diff --git a/gprofng/src/Stabs.h b/gprofng/src/Stabs.h
index a6a572d..d34741f 100644
--- a/gprofng/src/Stabs.h
+++ b/gprofng/src/Stabs.h
@@ -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();
diff --git a/gprofng/src/vec.h b/gprofng/src/vec.h
index 04cce4e..a768a02 100644
--- a/gprofng/src/vec.h
+++ b/gprofng/src/vec.h
@@ -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);