|
From: Jeremy F. <je...@go...> - 2005-02-17 01:53:38
|
CVS commit by fitzhardinge:
If an address has multiple symbols, tend to prefer the shortest name,
since its likely the one most commonly used (ie, prefer "free" to "cfree",
or "__libc_GI_free_internal"). One exception to this rule is that we
prefer versioned symbols (@GLIBC_2.1) over non-versioned ones.
M +11 -57 vg_symtab2.c 1.102
--- valgrind/coregrind/vg_symtab2.c #1.101:1.102
@@ -409,70 +409,24 @@ static Int compare_RiSym(void *va, void
/* Two symbols have the same address. Which name do we prefer?
- In general we prefer the longer name, but if the choice is between
- __libc_X and X, then choose X (similarly with __GI__ and __
- prefixes).
+ The shortest. Always. Hm, well, prefer the ones with '@' symbol versioning in them.
+ If they're the same length, then alphabetical.
*/
static RiSym *prefersym(RiSym *a, RiSym *b)
{
- Int pfx;
Int lena, lenb;
- Int i;
- static const struct {
- const Char *prefix;
- Int len;
- } prefixes[] = {
-#define PFX(x) { x, sizeof(x)-1 }
- /* order from longest to shortest */
- PFX("__GI___libc_"),
- PFX("__GI___"),
- PFX("__libc_"),
- PFX("__GI__"),
- PFX("__GI_"),
- PFX("__"),
-#undef PFX
- };
+ Bool va = VG_(strchr)(a->name, '@') != NULL;
+ Bool vb = VG_(strchr)(b->name, '@') != NULL;
lena = VG_(strlen)(a->name);
lenb = VG_(strlen)(b->name);
-
- /* rearrange so that a is the long one */
- if (lena < lenb) {
- RiSym *t;
- Int lt;
-
- t = a;
- a = b;
- b = t;
-
- lt = lena;
- lena = lenb;
- lenb = lt;
- }
-
- /* Ugh. If we get a "free", always choose it. This is because
- normally, this function would choose "cfree" over free. cfree is
- an alias for free. If there's any more symbols like this, we may
- want to consider making this mechanism more generic.
- */
- if(VG_(strcmp)(a->name, "free") == 0)
+ if (va || lena < lenb)
return a;
-
- if(VG_(strcmp)(b->name, "free") == 0)
- return b;
-
- for(i = pfx = 0; i < sizeof(prefixes)/sizeof(*prefixes); i++) {
- Int pfxlen = prefixes[i].len;
-
- if (pfxlen < lena &&
- VG_(memcmp)(a->name, prefixes[i].prefix, pfxlen) == 0) {
- pfx = pfxlen;
- break;
- }
- }
-
- if (pfx != 0 && VG_(strcmp)(a->name + pfx, b->name) == 0)
+ else if (vb || lenb < lena)
return b;
+ if (VG_(strcmp)(a->name, b->name) < 0)
return a;
+ else
+ return b;
}
|