perf symbols: Switch dso__synthesize_plt_symbols() to use symsrc
[deliverable/linux.git] / tools / perf / util / symbol.h
CommitLineData
8b40f521
JK
1#ifndef __PERF_SYMBOL
2#define __PERF_SYMBOL 1
a2928c42
ACM
3
4#include <linux/types.h>
e4204992 5#include <stdbool.h>
5aab621b
ACM
6#include <stdint.h>
7#include "map.h"
b5387528 8#include "../perf.h"
5da50258 9#include <linux/list.h>
43cbcd8a 10#include <linux/rbtree.h>
5aab621b 11#include <stdio.h>
8db4841f 12#include <byteswap.h>
a2928c42 13
b68e2f91
CS
14#ifndef NO_LIBELF_SUPPORT
15#include <libelf.h>
16#include <gelf.h>
17#include <elf.h>
18#endif
19
247648e3
ACM
20#ifdef HAVE_CPLUS_DEMANGLE
21extern char *cplus_demangle(const char *, int);
22
23static inline char *bfd_demangle(void __used *v, const char *c, int i)
24{
25 return cplus_demangle(c, i);
26}
27#else
28#ifdef NO_DEMANGLE
29static inline char *bfd_demangle(void __used *v, const char __used *c,
30 int __used i)
31{
32 return NULL;
33}
34#else
35#include <bfd.h>
36#endif
37#endif
38
5aab621b
ACM
39int hex2u64(const char *ptr, u64 *val);
40char *strxfrchar(char *s, char from, char to);
41
84087126
MR
42/*
43 * libelf 0.8.x and earlier do not support ELF_C_READ_MMAP;
44 * for newer versions we can use mmap to reduce memory usage:
45 */
46#ifdef LIBELF_NO_MMAP
47# define PERF_ELF_C_READ_MMAP ELF_C_READ
48#else
49# define PERF_ELF_C_READ_MMAP ELF_C_READ_MMAP
50#endif
51
247648e3
ACM
52#ifndef DMGL_PARAMS
53#define DMGL_PARAMS (1 << 0) /* Include function args */
54#define DMGL_ANSI (1 << 1) /* Include const, volatile, etc */
55#endif
56
5aab621b
ACM
57#define BUILD_ID_SIZE 20
58
171b3be9
ACM
59/** struct symbol - symtab entry
60 *
61 * @ignore - resolvable but tools ignore it (e.g. idle routines)
62 */
a2928c42
ACM
63struct symbol {
64 struct rb_node rb_node;
9cffa8d5
PM
65 u64 start;
66 u64 end;
fefb0b94 67 u16 namelen;
c408fedf 68 u8 binding;
171b3be9 69 bool ignore;
a2928c42
ACM
70 char name[0];
71};
72
aeafcbaf 73void symbol__delete(struct symbol *sym);
628ada0c 74
1b2e2df4
ACM
75static inline size_t symbol__size(const struct symbol *sym)
76{
77 return sym->end - sym->start + 1;
78}
79
655000e7
ACM
80struct strlist;
81
b32d133a
ACM
82struct symbol_conf {
83 unsigned short priv_size;
d04b35f8 84 unsigned short nr_events;
b32d133a 85 bool try_vmlinux_path,
0bc8d205 86 show_kernel_path,
79406cd7 87 use_modules,
d599db3f
ACM
88 sort_by_name,
89 show_nr_samples,
3f2728bd 90 show_total_period,
d599db3f 91 use_callchain,
f7d87444 92 exclude_other,
85e00b55 93 show_cpu_utilization,
ec80fde7 94 initialized,
3e6a2a7f
SE
95 kptr_restrict,
96 annotate_asm_raw,
97 annotate_src;
c410a338 98 const char *vmlinux_name,
b226a5a7 99 *kallsyms_name,
9ed7e1b8 100 *source_prefix,
c410a338 101 *field_sep;
a1645ce1
ZY
102 const char *default_guest_vmlinux_name,
103 *default_guest_kallsyms,
104 *default_guest_modules;
105 const char *guestmount;
edb7c60e 106 const char *dso_list_str,
655000e7
ACM
107 *comm_list_str,
108 *sym_list_str,
109 *col_width_list_str;
110 struct strlist *dso_list,
111 *comm_list,
a68c2c58
SE
112 *sym_list,
113 *dso_from_list,
114 *dso_to_list,
115 *sym_from_list,
116 *sym_to_list;
ec5761ea 117 const char *symfs;
b32d133a
ACM
118};
119
75be6cf4 120extern struct symbol_conf symbol_conf;
00a192b3 121
aeafcbaf 122static inline void *symbol__priv(struct symbol *sym)
00a192b3 123{
aeafcbaf 124 return ((void *)sym) - symbol_conf.priv_size;
00a192b3
ACM
125}
126
9de89fe7
ACM
127struct ref_reloc_sym {
128 const char *name;
129 u64 addr;
130 u64 unrelocated_addr;
131};
132
59fd5306
ACM
133struct map_symbol {
134 struct map *map;
135 struct symbol *sym;
0f0cbf7a
ACM
136 bool unfolded;
137 bool has_children;
59fd5306
ACM
138};
139
b5387528
RAV
140struct addr_map_symbol {
141 struct map *map;
142 struct symbol *sym;
143 u64 addr;
a68c2c58 144 u64 al_addr;
b5387528
RAV
145};
146
147struct branch_info {
148 struct addr_map_symbol from;
149 struct addr_map_symbol to;
150 struct branch_flags flags;
151};
152
1ed091c4
ACM
153struct addr_location {
154 struct thread *thread;
155 struct map *map;
156 struct symbol *sym;
157 u64 addr;
158 char level;
c410a338 159 bool filtered;
f60f3593
AS
160 u8 cpumode;
161 s32 cpu;
a1645ce1
ZY
162};
163
44f24cb3
JO
164enum dso_binary_type {
165 DSO_BINARY_TYPE__KALLSYMS = 0,
166 DSO_BINARY_TYPE__GUEST_KALLSYMS,
21ea4539
CS
167 DSO_BINARY_TYPE__VMLINUX,
168 DSO_BINARY_TYPE__GUEST_VMLINUX,
44f24cb3
JO
169 DSO_BINARY_TYPE__JAVA_JIT,
170 DSO_BINARY_TYPE__DEBUGLINK,
171 DSO_BINARY_TYPE__BUILD_ID_CACHE,
172 DSO_BINARY_TYPE__FEDORA_DEBUGINFO,
173 DSO_BINARY_TYPE__UBUNTU_DEBUGINFO,
174 DSO_BINARY_TYPE__BUILDID_DEBUGINFO,
175 DSO_BINARY_TYPE__SYSTEM_PATH_DSO,
176 DSO_BINARY_TYPE__GUEST_KMODULE,
177 DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE,
178 DSO_BINARY_TYPE__NOT_FOUND,
179};
180
a1645ce1
ZY
181enum dso_kernel_type {
182 DSO_TYPE_USER = 0,
183 DSO_TYPE_KERNEL,
184 DSO_TYPE_GUEST_KERNEL
1ed091c4
ACM
185};
186
8db4841f
JO
187enum dso_swap_type {
188 DSO_SWAP__UNSET,
189 DSO_SWAP__NO,
190 DSO_SWAP__YES,
191};
192
4dff624a
JO
193#define DSO__DATA_CACHE_SIZE 4096
194#define DSO__DATA_CACHE_MASK ~(DSO__DATA_CACHE_SIZE - 1)
195
196struct dso_cache {
197 struct rb_node rb_node;
198 u64 offset;
199 u64 size;
200 char data[0];
201};
202
a2928c42
ACM
203struct dso {
204 struct list_head node;
6a4694a4 205 struct rb_root symbols[MAP__NR_TYPES];
79406cd7 206 struct rb_root symbol_names[MAP__NR_TYPES];
4dff624a 207 struct rb_root cache;
6e406257 208 enum dso_kernel_type kernel;
8db4841f 209 enum dso_swap_type needs_swap;
44f24cb3 210 enum dso_binary_type symtab_type;
949d160b 211 enum dso_binary_type data_type;
8d06367f 212 u8 adjust_symbols:1;
8d06367f 213 u8 has_build_id:1;
88d3d9b7 214 u8 hit:1;
d06d92b7 215 u8 annotate_warned:1;
6e406257
ACM
216 u8 sname_alloc:1;
217 u8 lname_alloc:1;
79406cd7 218 u8 sorted_by_name;
3610583c 219 u8 loaded;
8d06367f 220 u8 build_id[BUILD_ID_SIZE];
439d473b
ACM
221 const char *short_name;
222 char *long_name;
b63be8d7
ACM
223 u16 long_name_len;
224 u16 short_name_len;
a2928c42
ACM
225 char name[0];
226};
227
b68e2f91
CS
228struct symsrc {
229 char *name;
230 int fd;
231 enum dso_binary_type type;
232
233#ifndef NO_LIBELF_SUPPORT
234 Elf *elf;
235 GElf_Ehdr ehdr;
236
237 Elf_Scn *opdsec;
238 size_t opdidx;
239 GElf_Shdr opdshdr;
240
241 Elf_Scn *symtab;
242 GElf_Shdr symshdr;
243
244 Elf_Scn *dynsym;
245 size_t dynsym_idx;
246 GElf_Shdr dynshdr;
247
248 bool adjust_symbols;
249#endif
250};
251
252void symsrc__destroy(struct symsrc *ss);
253int symsrc__init(struct symsrc *ss, struct dso *dso, const char *name,
254 enum dso_binary_type type);
255
8db4841f
JO
256#define DSO__SWAP(dso, type, val) \
257({ \
258 type ____r = val; \
259 BUG_ON(dso->needs_swap == DSO_SWAP__UNSET); \
260 if (dso->needs_swap == DSO_SWAP__YES) { \
261 switch (sizeof(____r)) { \
262 case 2: \
263 ____r = bswap_16(val); \
264 break; \
265 case 4: \
266 ____r = bswap_32(val); \
267 break; \
268 case 8: \
269 ____r = bswap_64(val); \
270 break; \
271 default: \
272 BUG_ON(1); \
273 } \
274 } \
275 ____r; \
276})
277
00a192b3 278struct dso *dso__new(const char *name);
aeafcbaf 279void dso__delete(struct dso *dso);
a2928c42 280
aeafcbaf 281int dso__name_len(const struct dso *dso);
8a6c5b26 282
aeafcbaf
ACM
283bool dso__loaded(const struct dso *dso, enum map_type type);
284bool dso__sorted_by_name(const struct dso *dso, enum map_type type);
79406cd7 285
aeafcbaf 286static inline void dso__set_loaded(struct dso *dso, enum map_type type)
8d92c02a 287{
aeafcbaf 288 dso->loaded |= (1 << type);
8d92c02a
ACM
289}
290
aeafcbaf 291void dso__sort_by_name(struct dso *dso, enum map_type type);
3610583c 292
e5a1845f 293void dsos__add(struct list_head *head, struct dso *dso);
a89e5abe
ACM
294struct dso *__dsos__findnew(struct list_head *head, const char *name);
295
aeafcbaf
ACM
296int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter);
297int dso__load_vmlinux(struct dso *dso, struct map *map,
fd930ff9 298 const char *vmlinux, symbol_filter_t filter);
aeafcbaf 299int dso__load_vmlinux_path(struct dso *dso, struct map *map,
9de89fe7 300 symbol_filter_t filter);
aeafcbaf 301int dso__load_kallsyms(struct dso *dso, const char *filename, struct map *map,
9de89fe7 302 symbol_filter_t filter);
aeafcbaf 303int machine__load_kallsyms(struct machine *machine, const char *filename,
5c0541d5 304 enum map_type type, symbol_filter_t filter);
aeafcbaf 305int machine__load_vmlinux_path(struct machine *machine, enum map_type type,
5c0541d5
ACM
306 symbol_filter_t filter);
307
1f626bc3
ACM
308size_t __dsos__fprintf(struct list_head *head, FILE *fp);
309
aeafcbaf
ACM
310size_t machine__fprintf_dsos_buildid(struct machine *machine,
311 FILE *fp, bool with_hits);
312size_t machines__fprintf_dsos(struct rb_root *machines, FILE *fp);
313size_t machines__fprintf_dsos_buildid(struct rb_root *machines,
314 FILE *fp, bool with_hits);
315size_t dso__fprintf_buildid(struct dso *dso, FILE *fp);
316size_t dso__fprintf_symbols_by_name(struct dso *dso,
317 enum map_type type, FILE *fp);
318size_t dso__fprintf(struct dso *dso, enum map_type type, FILE *fp);
b0a9ab62 319
aeafcbaf
ACM
320char dso__symtab_origin(const struct dso *dso);
321void dso__set_long_name(struct dso *dso, char *name);
322void dso__set_build_id(struct dso *dso, void *build_id);
e5a1845f 323bool dso__build_id_equal(const struct dso *dso, u8 *build_id);
aeafcbaf
ACM
324void dso__read_running_kernel_build_id(struct dso *dso,
325 struct machine *machine);
225466f1 326struct map *dso__new_map(const char *name);
aeafcbaf
ACM
327struct symbol *dso__find_symbol(struct dso *dso, enum map_type type,
328 u64 addr);
329struct symbol *dso__find_symbol_by_name(struct dso *dso, enum map_type type,
79406cd7 330 const char *name);
a2928c42 331
2643ce11 332int filename__read_build_id(const char *filename, void *bf, size_t size);
f1617b40 333int sysfs__read_build_id(const char *filename, void *bf, size_t size);
a1645ce1 334bool __dsos__read_build_ids(struct list_head *head, bool with_hits);
aeafcbaf 335int build_id__sprintf(const u8 *build_id, int len, char *bf);
9e201442
ACM
336int kallsyms__parse(const char *filename, void *arg,
337 int (*process_symbol)(void *arg, const char *name,
82151520 338 char type, u64 start));
e5a1845f
NK
339int filename__read_debuglink(const char *filename, char *debuglink,
340 size_t size);
2643ce11 341
aeafcbaf
ACM
342void machine__destroy_kernel_maps(struct machine *machine);
343int __machine__create_kernel_maps(struct machine *machine, struct dso *kernel);
344int machine__create_kernel_maps(struct machine *machine);
5c0541d5 345
aeafcbaf
ACM
346int machines__create_kernel_maps(struct rb_root *machines, pid_t pid);
347int machines__create_guest_kernel_maps(struct rb_root *machines);
348void machines__destroy_guest_kernel_maps(struct rb_root *machines);
a1645ce1 349
75be6cf4 350int symbol__init(void);
d65a458b 351void symbol__exit(void);
166ccc9c 352void symbol__elf_init(void);
e5a1845f 353struct symbol *symbol__new(u64 start, u64 len, u8 binding, const char *name);
a978f2ab
AN
354size_t symbol__fprintf_symname_offs(const struct symbol *sym,
355 const struct addr_location *al, FILE *fp);
547a92e0 356size_t symbol__fprintf_symname(const struct symbol *sym, FILE *fp);
36a3e646
ACM
357bool symbol_type__is_a(char symbol_type, enum map_type map_type);
358
aeafcbaf 359size_t machine__fprintf_vmlinux_path(struct machine *machine, FILE *fp);
b0a9ab62 360
44f24cb3
JO
361int dso__binary_type_file(struct dso *dso, enum dso_binary_type type,
362 char *root_dir, char *file, size_t size);
949d160b
JO
363
364int dso__data_fd(struct dso *dso, struct machine *machine);
365ssize_t dso__data_read_offset(struct dso *dso, struct machine *machine,
366 u64 offset, u8 *data, ssize_t size);
367ssize_t dso__data_read_addr(struct dso *dso, struct map *map,
368 struct machine *machine, u64 addr,
369 u8 *data, ssize_t size);
f7add556 370int dso__test_data(void);
b68e2f91 371int dso__load_sym(struct dso *dso, struct map *map, struct symsrc *ss,
e5a1845f 372 symbol_filter_t filter, int kmodule, int want_symtab);
a44f605b
CS
373int dso__synthesize_plt_symbols(struct dso *dso, struct symsrc *ss,
374 struct map *map, symbol_filter_t filter);
e5a1845f
NK
375
376void symbols__insert(struct rb_root *symbols, struct symbol *sym);
377void symbols__fixup_duplicate(struct rb_root *symbols);
378void symbols__fixup_end(struct rb_root *symbols);
379void __map_groups__fixup_end(struct map_groups *mg, enum map_type type);
380
8b40f521 381#endif /* __PERF_SYMBOL */
This page took 0.209994 seconds and 5 git commands to generate.