|
From: Jeremy F. <je...@go...> - 2003-12-15 23:32:51
|
CVS commit by fitzhardinge:
Make symbol prefix matching table driver, and be a bit more careful
about overrunning the ends of names.
M +34 -15 vg_symtab2.c 1.64
--- valgrind/coregrind/vg_symtab2.c #1.63:1.64
@@ -408,28 +408,47 @@ static RiSym *prefersym(RiSym *a, RiSym
{
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
+ };
+
+ lena = VG_(strlen)(a->name);
+ lenb = VG_(strlen)(b->name);
/* rearrange so that a is the long one */
- if (VG_(strlen)(a->name) < VG_(strlen)(b->name)) {
+ if (lena < lenb) {
RiSym *t;
+ Int lt;
t = a;
a = b;
b = t;
+
+ lt = lena;
+ lena = lenb;
+ lenb = lt;
}
- pfx = 0;
+ for(i = pfx = 0; i < sizeof(prefixes)/sizeof(*prefixes); i++) {
+ Int pfxlen = prefixes[i].len;
- if (VG_(memcmp)(a->name, "__GI___libc_", 12) == 0)
- pfx = 12;
- else if (VG_(memcmp)(a->name, "__libc_", 7) == 0)
- pfx = 7;
- else if (VG_(memcmp)(a->name, "__GI___", 7) == 0)
- pfx = 7;
- else if (VG_(memcmp)(a->name, "__GI__", 6) == 0)
- pfx = 6;
- else if (VG_(memcmp)(a->name, "__GI_", 5) == 0)
- pfx = 5;
- else if (VG_(memcmp)(a->name, "__", 2) == 0)
- pfx = 2;
+ 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)
|