|
|
242f5d |
commit f4abcc05fdba3f25890a9b30b71d511ccc906d46
|
|
|
242f5d |
Author: Mark Wielaard <mark@klomp.org>
|
|
|
242f5d |
Date: Mon Jul 27 22:43:28 2020 +0200
|
|
|
242f5d |
|
|
|
242f5d |
Incorrect call-graph tracking due to new _dl_runtime_resolve_xsave*
|
|
|
242f5d |
|
|
|
242f5d |
Newer glibc have alternate ld.so _ld_runtime_resolve functions.
|
|
|
242f5d |
Namely _dl_runtime_resolve_xsave and _dl_runtime_resolve_xsave'2
|
|
|
242f5d |
|
|
|
242f5d |
This patch recognizes the xsave, xsvec and fxsave variants and
|
|
|
242f5d |
changes callgrind so that any variant counts as _dl_runtime_resolve.
|
|
|
242f5d |
|
|
|
242f5d |
Original patch by paulo.cesar.pereira.de.andrade@gmail.com
|
|
|
242f5d |
https://bugs.kde.org/show_bug.cgi?id=415293
|
|
|
242f5d |
|
|
|
242f5d |
diff --git a/callgrind/fn.c b/callgrind/fn.c
|
|
|
242f5d |
index e9d8dd214..7cce1a0c7 100644
|
|
|
242f5d |
--- a/callgrind/fn.c
|
|
|
242f5d |
+++ b/callgrind/fn.c
|
|
|
242f5d |
@@ -30,8 +30,11 @@
|
|
|
242f5d |
|
|
|
242f5d |
static fn_array current_fn_active;
|
|
|
242f5d |
|
|
|
242f5d |
-static Addr runtime_resolve_addr = 0;
|
|
|
242f5d |
-static int runtime_resolve_length = 0;
|
|
|
242f5d |
+/* x86_64 defines 4 variants. */
|
|
|
242f5d |
+#define MAX_RESOLVE_ADDRS 4
|
|
|
242f5d |
+static int runtime_resolve_addrs = 0;
|
|
|
242f5d |
+static Addr runtime_resolve_addr[MAX_RESOLVE_ADDRS];
|
|
|
242f5d |
+static int runtime_resolve_length[MAX_RESOLVE_ADDRS];
|
|
|
242f5d |
|
|
|
242f5d |
// a code pattern is a list of tuples (start offset, length)
|
|
|
242f5d |
struct chunk_t { int start, len; };
|
|
|
242f5d |
@@ -56,6 +59,9 @@ static Bool check_code(obj_node* obj,
|
|
|
242f5d |
/* first chunk of pattern should always start at offset 0 and
|
|
|
242f5d |
* have at least 3 bytes */
|
|
|
242f5d |
CLG_ASSERT((pat->chunk[0].start == 0) && (pat->chunk[0].len >2));
|
|
|
242f5d |
+
|
|
|
242f5d |
+ /* and we cannot be called more than MAX_RESOLVE_ADDRS times */
|
|
|
242f5d |
+ CLG_ASSERT(runtime_resolve_addrs < MAX_RESOLVE_ADDRS);
|
|
|
242f5d |
|
|
|
242f5d |
CLG_DEBUG(1, "check_code: %s, pattern %s, check %d bytes of [%x %x %x...]\n",
|
|
|
242f5d |
obj->name, pat->name, pat->chunk[0].len, code[0], code[1], code[2]);
|
|
|
242f5d |
@@ -93,8 +99,9 @@ static Bool check_code(obj_node* obj,
|
|
|
242f5d |
pat->name, obj->name + obj->last_slash_pos,
|
|
|
242f5d |
addr - obj->start, addr, pat->len);
|
|
|
242f5d |
|
|
|
242f5d |
- runtime_resolve_addr = addr;
|
|
|
242f5d |
- runtime_resolve_length = pat->len;
|
|
|
242f5d |
+ runtime_resolve_addr[runtime_resolve_addrs] = addr;
|
|
|
242f5d |
+ runtime_resolve_length[runtime_resolve_addrs] = pat->len;
|
|
|
242f5d |
+ runtime_resolve_addrs++;
|
|
|
242f5d |
return True;
|
|
|
242f5d |
}
|
|
|
242f5d |
}
|
|
|
242f5d |
@@ -138,8 +145,9 @@ static Bool search_runtime_resolve(obj_node* obj)
|
|
|
242f5d |
"x86-glibc2.8", 30, {{ 0,12 }, { 16,14 }, { 30,0}} };
|
|
|
242f5d |
|
|
|
242f5d |
if (VG_(strncmp)(obj->name, "/lib/ld", 7) != 0) return False;
|
|
|
242f5d |
- if (check_code(obj, code, &pat)) return True;
|
|
|
242f5d |
- if (check_code(obj, code_28, &pat_28)) return True;
|
|
|
242f5d |
+ Bool pat_p = check_code(obj, code, &pat;;
|
|
|
242f5d |
+ Bool pat_28_p = check_code(obj, code_28, &pat_28);
|
|
|
242f5d |
+ if (pat_p || pat_28_p) return True;
|
|
|
242f5d |
return False;
|
|
|
242f5d |
#endif
|
|
|
242f5d |
|
|
|
242f5d |
@@ -186,9 +194,98 @@ static Bool search_runtime_resolve(obj_node* obj)
|
|
|
242f5d |
static struct pattern pat = {
|
|
|
242f5d |
"amd64-def", 110, {{ 0,62 }, { 66,44 }, { 110,0 }} };
|
|
|
242f5d |
|
|
|
242f5d |
+ static UChar code_xsavec[] = {
|
|
|
242f5d |
+ /* 0*/ 0x53, 0x48, 0x89, 0xe3, 0x48, 0x83, 0xe4, 0xc0,
|
|
|
242f5d |
+ /* 8*/ 0x48, 0x2b, 0x25, 0x00, 0x00, 0x00, 0x00, /* sub <i32>(%rip),%rsp */
|
|
|
242f5d |
+ /*15*/ 0x48,
|
|
|
242f5d |
+ /*16*/ 0x89, 0x04, 0x24, 0x48, 0x89, 0x4c, 0x24, 0x08,
|
|
|
242f5d |
+ /*24*/ 0x48, 0x89, 0x54, 0x24, 0x10, 0x48, 0x89, 0x74,
|
|
|
242f5d |
+ /*32*/ 0x24, 0x18, 0x48, 0x89, 0x7c, 0x24, 0x20, 0x4c,
|
|
|
242f5d |
+ /*40*/ 0x89, 0x44, 0x24, 0x28, 0x4c, 0x89, 0x4c, 0x24,
|
|
|
242f5d |
+ /*48*/ 0x30, 0xb8, 0xee, 0x00, 0x00, 0x00, 0x31, 0xd2,
|
|
|
242f5d |
+ /*56*/ 0x48, 0x89, 0x94, 0x24, 0x50, 0x02, 0x00, 0x00,
|
|
|
242f5d |
+ /*64*/ 0x48, 0x89, 0x94, 0x24, 0x58, 0x02, 0x00, 0x00,
|
|
|
242f5d |
+ /*72*/ 0x48, 0x89, 0x94, 0x24, 0x60, 0x02, 0x00, 0x00,
|
|
|
242f5d |
+ /*80*/ 0x48, 0x89, 0x94, 0x24, 0x68, 0x02, 0x00, 0x00,
|
|
|
242f5d |
+ /*88*/ 0x48, 0x89, 0x94, 0x24, 0x70, 0x02, 0x00, 0x00,
|
|
|
242f5d |
+ /*96*/ 0x48, 0x89, 0x94, 0x24, 0x78, 0x02, 0x00, 0x00,
|
|
|
242f5d |
+ /*04*/ 0x0f, 0xc7, 0x64, 0x24, 0x40, 0x48, 0x8b, 0x73,
|
|
|
242f5d |
+ /*112*/0x10, 0x48, 0x8b, 0x7b, 0x08,
|
|
|
242f5d |
+ /*117*/0xe8, 0x00, 0x00, 0x00, 0x00, /* callq <_dl_fixup> */
|
|
|
242f5d |
+ /*122*/0x49, 0x89, 0xc3, 0xb8, 0xee, 0x00,
|
|
|
242f5d |
+ /*128*/0x00, 0x00, 0x31, 0xd2, 0x0f, 0xae, 0x6c, 0x24,
|
|
|
242f5d |
+ /*136*/0x40, 0x4c, 0x8b, 0x4c, 0x24, 0x30, 0x4c, 0x8b,
|
|
|
242f5d |
+ /*144*/0x44, 0x24, 0x28, 0x48, 0x8b, 0x7c, 0x24, 0x20,
|
|
|
242f5d |
+ /*152*/0x48, 0x8b, 0x74, 0x24, 0x18, 0x48, 0x8b, 0x54,
|
|
|
242f5d |
+ /*160*/0x24, 0x10, 0x48, 0x8b, 0x4c, 0x24, 0x08, 0x48,
|
|
|
242f5d |
+ /*168*/0x8b, 0x04, 0x24, 0x48, 0x89, 0xdc, 0x48, 0x8b,
|
|
|
242f5d |
+ /*176*/0x1c, 0x24, 0x48, 0x83, 0xc4, 0x18, 0xf2, 0x41,
|
|
|
242f5d |
+ /*184*/0xff, 0xe3 };
|
|
|
242f5d |
+ static struct pattern pat_xsavec = {
|
|
|
242f5d |
+ "amd64-xsavec", 186, {{ 0,11 }, { 15,103 }, {122,64}, { 186,0 }} };
|
|
|
242f5d |
+
|
|
|
242f5d |
+ static UChar code_xsave[] = {
|
|
|
242f5d |
+ /* 0*/ 0x53, 0x48, 0x89, 0xe3, 0x48, 0x83, 0xe4, 0xc0,
|
|
|
242f5d |
+ /* 8*/ 0x48, 0x2b, 0x25, 0x00, 0x00, 0x00, 0x00, /* sub <i32>(%rip),%rsp */
|
|
|
242f5d |
+ /*15*/ 0x48,
|
|
|
242f5d |
+ /*16*/ 0x89, 0x04, 0x24, 0x48, 0x89, 0x4c, 0x24, 0x08,
|
|
|
242f5d |
+ /*24*/ 0x48, 0x89, 0x54, 0x24, 0x10, 0x48, 0x89, 0x74,
|
|
|
242f5d |
+ /*32*/ 0x24, 0x18, 0x48, 0x89, 0x7c, 0x24, 0x20, 0x4c,
|
|
|
242f5d |
+ /*40*/ 0x89, 0x44, 0x24, 0x28, 0x4c, 0x89, 0x4c, 0x24,
|
|
|
242f5d |
+ /*48*/ 0x30, 0xb8, 0xee, 0x00, 0x00, 0x00, 0x31, 0xd2,
|
|
|
242f5d |
+ /*56*/ 0x48, 0x89, 0x94, 0x24, 0x40, 0x02, 0x00, 0x00,
|
|
|
242f5d |
+ /*64*/ 0x48, 0x89, 0x94, 0x24, 0x48, 0x02, 0x00, 0x00,
|
|
|
242f5d |
+ /*72*/ 0x48, 0x89, 0x94, 0x24, 0x50, 0x02, 0x00, 0x00,
|
|
|
242f5d |
+ /*80*/ 0x48, 0x89, 0x94, 0x24, 0x58, 0x02, 0x00, 0x00,
|
|
|
242f5d |
+ /*88*/ 0x48, 0x89, 0x94, 0x24, 0x60, 0x02, 0x00, 0x00,
|
|
|
242f5d |
+ /*96*/ 0x48, 0x89, 0x94, 0x24, 0x68, 0x02, 0x00, 0x00,
|
|
|
242f5d |
+ /*104*/0x48, 0x89, 0x94, 0x24, 0x70, 0x02, 0x00, 0x00,
|
|
|
242f5d |
+ /*112*/0x48, 0x89, 0x94, 0x24, 0x78, 0x02, 0x00, 0x00,
|
|
|
242f5d |
+ /*120*/0x0f, 0xae, 0x64, 0x24, 0x40, 0x48, 0x8b, 0x73,
|
|
|
242f5d |
+ /*128*/0x10, 0x48, 0x8b, 0x7b, 0x08,
|
|
|
242f5d |
+ /*133*/0xe8, 0x00, 0x00, 0x00, 0x00, /* callq <_dl_fixup> */
|
|
|
242f5d |
+ /*138*/0x49, 0x89, 0xc3, 0xb8, 0xee, 0x00,
|
|
|
242f5d |
+ /*144*/0x00, 0x00, 0x31, 0xd2, 0x0f, 0xae, 0x6c, 0x24,
|
|
|
242f5d |
+ /*152*/0x40, 0x4c, 0x8b, 0x4c, 0x24, 0x30, 0x4c, 0x8b,
|
|
|
242f5d |
+ /*160*/0x44, 0x24, 0x28, 0x48, 0x8b, 0x7c, 0x24, 0x20,
|
|
|
242f5d |
+ /*168*/0x48, 0x8b, 0x74, 0x24, 0x18, 0x48, 0x8b, 0x54,
|
|
|
242f5d |
+ /*176*/0x24, 0x10, 0x48, 0x8b, 0x4c, 0x24, 0x08, 0x48,
|
|
|
242f5d |
+ /*184*/0x8b, 0x04, 0x24, 0x48, 0x89, 0xdc, 0x48, 0x8b,
|
|
|
242f5d |
+ /*192*/0x1c, 0x24, 0x48, 0x83, 0xc4, 0x18, 0xf2, 0x41,
|
|
|
242f5d |
+ /*200*/0xff, 0xe3 };
|
|
|
242f5d |
+ static struct pattern pat_xsave = {
|
|
|
242f5d |
+ "amd64-xsave", 202, {{ 0,11 }, { 15,119 }, {138,64}, { 202,0 }} };
|
|
|
242f5d |
+
|
|
|
242f5d |
+ static UChar code_fxsave[] = {
|
|
|
242f5d |
+ /* 0*/ 0x53, 0x48, 0x89, 0xe3, 0x48, 0x83, 0xe4, 0xf0,
|
|
|
242f5d |
+ /* 8*/ 0x48, 0x81, 0xec, 0x40, 0x02, 0x00, 0x00, 0x48,
|
|
|
242f5d |
+ /*16*/ 0x89, 0x04, 0x24, 0x48, 0x89, 0x4c, 0x24, 0x08,
|
|
|
242f5d |
+ /*24*/ 0x48, 0x89, 0x54, 0x24, 0x10, 0x48, 0x89, 0x74,
|
|
|
242f5d |
+ /*32*/ 0x24, 0x18, 0x48, 0x89, 0x7c, 0x24, 0x20, 0x4c,
|
|
|
242f5d |
+ /*40*/ 0x89, 0x44, 0x24, 0x28, 0x4c, 0x89, 0x4c, 0x24,
|
|
|
242f5d |
+ /*48*/ 0x30, 0x0f, 0xae, 0x44, 0x24, 0x40, 0x48, 0x8b,
|
|
|
242f5d |
+ /*56*/ 0x73, 0x10, 0x48, 0x8b, 0x7b, 0x08,
|
|
|
242f5d |
+ /*62*/ 0xe8, 0x00, 0x00, 0x00, 0x00, /* callq <_dl_fixup> */
|
|
|
242f5d |
+ /*67*/ 0x49, 0x89, 0xc3, 0x0f, 0xae,
|
|
|
242f5d |
+ /*72*/ 0x4c, 0x24, 0x40, 0x4c, 0x8b, 0x4c, 0x24, 0x30,
|
|
|
242f5d |
+ /*80*/ 0x4c, 0x8b, 0x44, 0x24, 0x28, 0x48, 0x8b, 0x7c,
|
|
|
242f5d |
+ /*88*/ 0x24, 0x20, 0x48, 0x8b, 0x74, 0x24, 0x18, 0x48,
|
|
|
242f5d |
+ /*96*/ 0x8b, 0x54, 0x24, 0x10, 0x48, 0x8b, 0x4c, 0x24,
|
|
|
242f5d |
+ /*104*/0x08, 0x48, 0x8b, 0x04, 0x24, 0x48, 0x89, 0xdc,
|
|
|
242f5d |
+ /*112*/0x48, 0x8b, 0x1c, 0x24, 0x48, 0x83, 0xc4, 0x18,
|
|
|
242f5d |
+ /*120*/0xf2, 0x41, 0xff, 0xe3 };
|
|
|
242f5d |
+ static struct pattern pat_fxsave = {
|
|
|
242f5d |
+ "amd64-fxsave", 124, {{ 0,63 }, { 67,57 }, { 124,0 }} };
|
|
|
242f5d |
+
|
|
|
242f5d |
if ((VG_(strncmp)(obj->name, "/lib/ld", 7) != 0) &&
|
|
|
242f5d |
- (VG_(strncmp)(obj->name, "/lib64/ld", 9) != 0)) return False;
|
|
|
242f5d |
- return check_code(obj, code, &pat;;
|
|
|
242f5d |
+ (VG_(strncmp)(obj->name, "/lib64/ld", 9) != 0) &&
|
|
|
242f5d |
+ (VG_(strncmp)(obj->name, "/usr/lib/ld", 11) != 0) &&
|
|
|
242f5d |
+ (VG_(strncmp)(obj->name, "/usr/lib64/ld", 13) != 0)) return False;
|
|
|
242f5d |
+ Bool pat_p = check_code(obj, code, &pat;;
|
|
|
242f5d |
+ Bool pat_xsavec_p = check_code(obj, code_xsavec, &pat_xsavec);
|
|
|
242f5d |
+ Bool pat_xsave_p = check_code(obj, code_xsave, &pat_xsave);
|
|
|
242f5d |
+ Bool pat_fxsave_p = check_code(obj, code_fxsave, &pat_fxsave);
|
|
|
242f5d |
+ if (pat_p || pat_xsavec_p || pat_xsave_p || pat_fxsave_p) return True;
|
|
|
242f5d |
#endif
|
|
|
242f5d |
|
|
|
242f5d |
/* For other platforms, no patterns known */
|
|
|
242f5d |
@@ -254,7 +351,7 @@ obj_node* new_obj_node(DebugInfo* di, obj_node* next)
|
|
|
242f5d |
i++;
|
|
|
242f5d |
}
|
|
|
242f5d |
|
|
|
242f5d |
- if (runtime_resolve_addr == 0) search_runtime_resolve(obj);
|
|
|
242f5d |
+ if (runtime_resolve_addrs == 0) search_runtime_resolve(obj);
|
|
|
242f5d |
|
|
|
242f5d |
return obj;
|
|
|
242f5d |
}
|
|
|
242f5d |
@@ -490,6 +587,7 @@ fn_node* CLG_(get_fn_node)(BB* bb)
|
|
|
242f5d |
DebugInfo* di;
|
|
|
242f5d |
UInt line_num;
|
|
|
242f5d |
fn_node* fn;
|
|
|
242f5d |
+ Int i;
|
|
|
242f5d |
|
|
|
242f5d |
/* fn from debug info is idempotent for a BB */
|
|
|
242f5d |
if (bb->fn) return bb->fn;
|
|
|
242f5d |
@@ -538,12 +636,14 @@ fn_node* CLG_(get_fn_node)(BB* bb)
|
|
|
242f5d |
}
|
|
|
242f5d |
if (0 == VG_(strcmp)(fnname, "_exit") && !exit_bb)
|
|
|
242f5d |
exit_bb = bb;
|
|
|
242f5d |
-
|
|
|
242f5d |
- if (runtime_resolve_addr &&
|
|
|
242f5d |
- (bb_addr(bb) >= runtime_resolve_addr) &&
|
|
|
242f5d |
- (bb_addr(bb) < runtime_resolve_addr + runtime_resolve_length)) {
|
|
|
242f5d |
- /* BB in runtime_resolve found by code check; use this name */
|
|
|
242f5d |
- fnname = "_dl_runtime_resolve";
|
|
|
242f5d |
+
|
|
|
242f5d |
+ for (i = 0; i < runtime_resolve_addrs; i++) {
|
|
|
242f5d |
+ if ((bb_addr(bb) >= runtime_resolve_addr[i]) &&
|
|
|
242f5d |
+ (bb_addr(bb) < runtime_resolve_addr[i] + runtime_resolve_length[i])) {
|
|
|
242f5d |
+ /* BB in runtime_resolve found by code check; use this name */
|
|
|
242f5d |
+ fnname = "_dl_runtime_resolve";
|
|
|
242f5d |
+ break;
|
|
|
242f5d |
+ }
|
|
|
242f5d |
}
|
|
|
242f5d |
|
|
|
242f5d |
/* get fn_node struct for this function */
|