aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/perf_counter/util/symbol.c
diff options
context:
space:
mode:
Diffstat (limited to 'Documentation/perf_counter/util/symbol.c')
-rw-r--r--Documentation/perf_counter/util/symbol.c26
1 files changed, 17 insertions, 9 deletions
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