aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/perf_counter/builtin-report.c4
-rw-r--r--Documentation/perf_counter/util/symbol.c26
-rw-r--r--Documentation/perf_counter/util/symbol.h8
3 files changed, 26 insertions, 12 deletions
diff --git a/Documentation/perf_counter/builtin-report.c b/Documentation/perf_counter/builtin-report.c
index 04fc7ec0c359..889067eb2b69 100644
--- a/Documentation/perf_counter/builtin-report.c
+++ b/Documentation/perf_counter/builtin-report.c
@@ -83,7 +83,7 @@ static struct dso *dsos__findnew(const char *name)
83 int nr; 83 int nr;
84 84
85 if (dso == NULL) { 85 if (dso == NULL) {
86 dso = dso__new(name); 86 dso = dso__new(name, 0);
87 if (!dso) 87 if (!dso)
88 goto out_delete_dso; 88 goto out_delete_dso;
89 89
@@ -120,7 +120,7 @@ static int load_kernel(void)
120{ 120{
121 int err = -1; 121 int err = -1;
122 122
123 kernel_dso = dso__new("[kernel]"); 123 kernel_dso = dso__new("[kernel]", 0);
124 if (!kernel_dso) 124 if (!kernel_dso)
125 return -1; 125 return -1;
126 126
diff --git a/Documentation/perf_counter/util/symbol.c b/Documentation/perf_counter/util/symbol.c
index d06de2cfcdc6..7088206244ac 100644
--- a/Documentation/perf_counter/util/symbol.c
+++ b/Documentation/perf_counter/util/symbol.c
@@ -7,22 +7,27 @@
7#include <elf.h> 7#include <elf.h>
8 8
9static struct symbol *symbol__new(uint64_t start, uint64_t len, 9static struct symbol *symbol__new(uint64_t start, uint64_t len,
10 const char *name) 10 const char *name, unsigned int priv_size)
11{ 11{
12 struct symbol *self = malloc(sizeof(*self) + strlen(name) + 1); 12 size_t namelen = strlen(name) + 1;
13 struct symbol *self = malloc(priv_size + sizeof(*self) + namelen);
13 14
14 if (self != NULL) { 15 if (self != NULL) {
16 if (priv_size) {
17 memset(self, 0, priv_size);
18 self = ((void *)self) + priv_size;
19 }
15 self->start = start; 20 self->start = start;
16 self->end = start + len; 21 self->end = start + len;
17 strcpy(self->name, name); 22 memcpy(self->name, name, namelen);
18 } 23 }
19 24
20 return self; 25 return self;
21} 26}
22 27
23static void symbol__delete(struct symbol *self) 28static void symbol__delete(struct symbol *self, unsigned int priv_size)
24{ 29{
25 free(self); 30 free(((void *)self) - priv_size);
26} 31}
27 32
28static size_t symbol__fprintf(struct symbol *self, FILE *fp) 33static size_t symbol__fprintf(struct symbol *self, FILE *fp)
@@ -31,13 +36,14 @@ static size_t symbol__fprintf(struct symbol *self, FILE *fp)
31 self->start, self->end, self->name); 36 self->start, self->end, self->name);
32} 37}
33 38
34struct dso *dso__new(const char *name) 39struct dso *dso__new(const char *name, unsigned int sym_priv_size)
35{ 40{
36 struct dso *self = malloc(sizeof(*self) + strlen(name) + 1); 41 struct dso *self = malloc(sizeof(*self) + strlen(name) + 1);
37 42
38 if (self != NULL) { 43 if (self != NULL) {
39 strcpy(self->name, name); 44 strcpy(self->name, name);
40 self->syms = RB_ROOT; 45 self->syms = RB_ROOT;
46 self->sym_priv_size = sym_priv_size;
41 } 47 }
42 48
43 return self; 49 return self;
@@ -51,7 +57,7 @@ static void dso__delete_symbols(struct dso *self)
51 while (next) { 57 while (next) {
52 pos = rb_entry(next, struct symbol, rb_node); 58 pos = rb_entry(next, struct symbol, rb_node);
53 next = rb_next(&pos->rb_node); 59 next = rb_next(&pos->rb_node);
54 symbol__delete(pos); 60 symbol__delete(pos, self->sym_priv_size);
55 } 61 }
56} 62}
57 63
@@ -189,7 +195,8 @@ int dso__load_kallsyms(struct dso *self)
189 /* 195 /*
190 * Well fix up the end later, when we have all sorted. 196 * Well fix up the end later, when we have all sorted.
191 */ 197 */
192 sym = symbol__new(start, 0xdead, line + len + 2); 198 sym = symbol__new(start, 0xdead, line + len + 2,
199 self->sym_priv_size);
193 200
194 if (sym == NULL) 201 if (sym == NULL)
195 goto out_delete_line; 202 goto out_delete_line;
@@ -340,7 +347,8 @@ static int dso__load_sym(struct dso *self, int fd, const char *name)
340 sym.st_value -= shdr.sh_addr - shdr.sh_offset; 347 sym.st_value -= shdr.sh_addr - shdr.sh_offset;
341 348
342 f = symbol__new(sym.st_value, sym.st_size, 349 f = symbol__new(sym.st_value, sym.st_size,
343 elf_sym__name(&sym, symstrs)); 350 elf_sym__name(&sym, symstrs),
351 self->sym_priv_size);
344 if (!f) 352 if (!f)
345 goto out_elf_end; 353 goto out_elf_end;
346 354
diff --git a/Documentation/perf_counter/util/symbol.h b/Documentation/perf_counter/util/symbol.h
index 6dffe76a28f0..9e120af9c71f 100644
--- a/Documentation/perf_counter/util/symbol.h
+++ b/Documentation/perf_counter/util/symbol.h
@@ -15,12 +15,18 @@ struct symbol {
15struct dso { 15struct dso {
16 struct list_head node; 16 struct list_head node;
17 struct rb_root syms; 17 struct rb_root syms;
18 unsigned int sym_priv_size;
18 char name[0]; 19 char name[0];
19}; 20};
20 21
21struct dso *dso__new(const char *name); 22struct dso *dso__new(const char *name, unsigned int sym_priv_size);
22void dso__delete(struct dso *self); 23void dso__delete(struct dso *self);
23 24
25static inline void *dso__sym_priv(struct dso *self, struct symbol *sym)
26{
27 return ((void *)sym) - self->sym_priv_size;
28}
29
24struct symbol *dso__find_symbol(struct dso *self, uint64_t ip); 30struct symbol *dso__find_symbol(struct dso *self, uint64_t ip);
25 31
26int dso__load_kallsyms(struct dso *self); 32int dso__load_kallsyms(struct dso *self);