]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - tools/perf/util/symbol.h
License cleanup: add SPDX GPL-2.0 license identifier to files with no license
[mirror_ubuntu-bionic-kernel.git] / tools / perf / util / symbol.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
8b40f521
JK
2#ifndef __PERF_SYMBOL
3#define __PERF_SYMBOL 1
a2928c42
ACM
4
5#include <linux/types.h>
e4204992 6#include <stdbool.h>
5aab621b
ACM
7#include <stdint.h>
8#include "map.h"
b5387528 9#include "../perf.h"
5da50258 10#include <linux/list.h>
43cbcd8a 11#include <linux/rbtree.h>
5aab621b 12#include <stdio.h>
8db4841f 13#include <byteswap.h>
b771a830 14#include <libgen.h>
4383db88 15#include "build-id.h"
0776eb59 16#include "event.h"
9a3993d4 17#include "path.h"
a2928c42 18
89fe808a 19#ifdef HAVE_LIBELF_SUPPORT
b68e2f91
CS
20#include <libelf.h>
21#include <gelf.h>
b68e2f91 22#endif
eec185ab 23#include <elf.h>
b68e2f91 24
cdd059d7
JO
25#include "dso.h"
26
84087126
MR
27/*
28 * libelf 0.8.x and earlier do not support ELF_C_READ_MMAP;
29 * for newer versions we can use mmap to reduce memory usage:
30 */
89fe808a 31#ifdef HAVE_LIBELF_MMAP_SUPPORT
84087126 32# define PERF_ELF_C_READ_MMAP ELF_C_READ_MMAP
29a0fc9b
NK
33#else
34# define PERF_ELF_C_READ_MMAP ELF_C_READ
84087126
MR
35#endif
36
99ca4233 37#ifdef HAVE_LIBELF_SUPPORT
3938bad4
ACM
38Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep,
39 GElf_Shdr *shp, const char *name, size_t *idx);
99ca4233
MH
40#endif
41
247648e3 42#ifndef DMGL_PARAMS
e71e7945 43#define DMGL_NO_OPTS 0 /* For readability... */
247648e3
ACM
44#define DMGL_PARAMS (1 << 0) /* Include function args */
45#define DMGL_ANSI (1 << 1) /* Include const, volatile, etc */
46#endif
47
0a77582f
MH
48#define DSO__NAME_KALLSYMS "[kernel.kallsyms]"
49#define DSO__NAME_KCORE "[kernel.kcore]"
50
171b3be9
ACM
51/** struct symbol - symtab entry
52 *
53 * @ignore - resolvable but tools ignore it (e.g. idle routines)
54 */
a2928c42
ACM
55struct symbol {
56 struct rb_node rb_node;
9cffa8d5
PM
57 u64 start;
58 u64 end;
fefb0b94 59 u16 namelen;
c408fedf 60 u8 binding;
b55cc4ed 61 u8 idle:1;
cdeb01bf 62 u8 ignore:1;
0b3c2264 63 u8 arch_sym;
a2928c42
ACM
64 char name[0];
65};
66
aeafcbaf 67void symbol__delete(struct symbol *sym);
cdd059d7 68void symbols__delete(struct rb_root *symbols);
628ada0c 69
eb948e50
MH
70/* symbols__for_each_entry - iterate over symbols (rb_root)
71 *
72 * @symbols: the rb_root of symbols
73 * @pos: the 'struct symbol *' to use as a loop cursor
74 * @nd: the 'struct rb_node *' to use as a temporary storage
75 */
76#define symbols__for_each_entry(symbols, pos, nd) \
77 for (nd = rb_first(symbols); \
78 nd && (pos = rb_entry(nd, struct symbol, rb_node)); \
79 nd = rb_next(nd))
80
1b2e2df4
ACM
81static inline size_t symbol__size(const struct symbol *sym)
82{
2c241bd3 83 return sym->end - sym->start;
1b2e2df4
ACM
84}
85
655000e7 86struct strlist;
e03eaa40 87struct intlist;
655000e7 88
b32d133a
ACM
89struct symbol_conf {
90 unsigned short priv_size;
d04b35f8 91 unsigned short nr_events;
b32d133a 92 bool try_vmlinux_path,
b01141f4 93 init_annotation,
2059fc7a 94 force,
fc2be696 95 ignore_vmlinux,
00dc8657 96 ignore_vmlinux_buildid,
0bc8d205 97 show_kernel_path,
79406cd7 98 use_modules,
680d926a 99 allow_aliases,
d599db3f
ACM
100 sort_by_name,
101 show_nr_samples,
3f2728bd 102 show_total_period,
d599db3f 103 use_callchain,
f8be1c8c 104 cumulate_callchain,
f9a7be7c 105 show_branchflag_count,
f7d87444 106 exclude_other,
85e00b55 107 show_cpu_utilization,
ec80fde7 108 initialized,
3e6a2a7f
SE
109 kptr_restrict,
110 annotate_asm_raw,
6e1f601a 111 annotate_src,
328ccdac 112 event_group,
f2148330 113 demangle,
763122ad 114 demangle_kernel,
c8302367 115 filter_relative,
8b7bad58 116 show_hist_headers,
0bc2f2f7 117 branch_callstack,
9e207ddf 118 has_filter,
b49a8fe5 119 show_ref_callgraph,
053a3989 120 hide_unresolved,
aef810ec 121 raw_trace,
f3a60646
JY
122 report_hierarchy,
123 inline_name;
c410a338 124 const char *vmlinux_name,
b226a5a7 125 *kallsyms_name,
9ed7e1b8 126 *source_prefix,
c410a338 127 *field_sep;
a1645ce1
ZY
128 const char *default_guest_vmlinux_name,
129 *default_guest_kallsyms,
130 *default_guest_modules;
131 const char *guestmount;
edb7c60e 132 const char *dso_list_str,
655000e7 133 *comm_list_str,
e03eaa40
DA
134 *pid_list_str,
135 *tid_list_str,
655000e7 136 *sym_list_str,
64eff7d9
DA
137 *col_width_list_str,
138 *bt_stop_list_str;
655000e7
ACM
139 struct strlist *dso_list,
140 *comm_list,
a68c2c58
SE
141 *sym_list,
142 *dso_from_list,
143 *dso_to_list,
144 *sym_from_list,
64eff7d9
DA
145 *sym_to_list,
146 *bt_stop_list;
e03eaa40
DA
147 struct intlist *pid_list,
148 *tid_list;
ec5761ea 149 const char *symfs;
b32d133a
ACM
150};
151
75be6cf4 152extern struct symbol_conf symbol_conf;
972f393b 153
bfbba189
ACM
154struct symbol_name_rb_node {
155 struct rb_node rb_node;
156 struct symbol sym;
157};
158
972f393b
ACM
159static inline int __symbol__join_symfs(char *bf, size_t size, const char *path)
160{
161 return path__join(bf, size, symbol_conf.symfs, path);
162}
163
164#define symbol__join_symfs(bf, path) __symbol__join_symfs(bf, sizeof(bf), path)
165
3f067dca
ACM
166extern int vmlinux_path__nr_entries;
167extern char **vmlinux_path;
00a192b3 168
aeafcbaf 169static inline void *symbol__priv(struct symbol *sym)
00a192b3 170{
aeafcbaf 171 return ((void *)sym) - symbol_conf.priv_size;
00a192b3
ACM
172}
173
9de89fe7
ACM
174struct ref_reloc_sym {
175 const char *name;
176 u64 addr;
177 u64 unrelocated_addr;
178};
179
59fd5306
ACM
180struct map_symbol {
181 struct map *map;
182 struct symbol *sym;
183};
184
b5387528
RAV
185struct addr_map_symbol {
186 struct map *map;
187 struct symbol *sym;
188 u64 addr;
a68c2c58 189 u64 al_addr;
8780fb25 190 u64 phys_addr;
b5387528
RAV
191};
192
193struct branch_info {
194 struct addr_map_symbol from;
195 struct addr_map_symbol to;
196 struct branch_flags flags;
508be0df
AK
197 char *srcline_from;
198 char *srcline_to;
b5387528
RAV
199};
200
98a3b32c
SE
201struct mem_info {
202 struct addr_map_symbol iaddr;
203 struct addr_map_symbol daddr;
204 union perf_mem_data_src data_src;
205};
206
1ed091c4 207struct addr_location {
cc22e575 208 struct machine *machine;
1ed091c4
ACM
209 struct thread *thread;
210 struct map *map;
211 struct symbol *sym;
212 u64 addr;
213 char level;
b3cef7f6 214 u8 filtered;
f60f3593
AS
215 u8 cpumode;
216 s32 cpu;
0c4c4deb 217 s32 socket;
a1645ce1
ZY
218};
219
b68e2f91
CS
220struct symsrc {
221 char *name;
222 int fd;
223 enum dso_binary_type type;
224
89fe808a 225#ifdef HAVE_LIBELF_SUPPORT
b68e2f91
CS
226 Elf *elf;
227 GElf_Ehdr ehdr;
228
229 Elf_Scn *opdsec;
230 size_t opdidx;
231 GElf_Shdr opdshdr;
232
233 Elf_Scn *symtab;
234 GElf_Shdr symshdr;
235
236 Elf_Scn *dynsym;
237 size_t dynsym_idx;
238 GElf_Shdr dynshdr;
239
240 bool adjust_symbols;
c6d8f2a4 241 bool is_64_bit;
b68e2f91
CS
242#endif
243};
244
245void symsrc__destroy(struct symsrc *ss);
246int symsrc__init(struct symsrc *ss, struct dso *dso, const char *name,
247 enum dso_binary_type type);
d26cd12b 248bool symsrc__has_symtab(struct symsrc *ss);
3aafe5ae 249bool symsrc__possibly_runtime(struct symsrc *ss);
b68e2f91 250
be39db9f 251int dso__load(struct dso *dso, struct map *map);
aeafcbaf 252int dso__load_vmlinux(struct dso *dso, struct map *map,
be39db9f
ACM
253 const char *vmlinux, bool vmlinux_allocated);
254int dso__load_vmlinux_path(struct dso *dso, struct map *map);
e02092b9 255int __dso__load_kallsyms(struct dso *dso, const char *filename, struct map *map,
be39db9f
ACM
256 bool no_kcore);
257int dso__load_kallsyms(struct dso *dso, const char *filename, struct map *map);
cdd059d7 258
ae93a6c7
CP
259void dso__insert_symbol(struct dso *dso, enum map_type type,
260 struct symbol *sym);
261
aeafcbaf
ACM
262struct symbol *dso__find_symbol(struct dso *dso, enum map_type type,
263 u64 addr);
264struct symbol *dso__find_symbol_by_name(struct dso *dso, enum map_type type,
79406cd7 265 const char *name);
18bd7264 266struct symbol *symbol__next_by_name(struct symbol *sym);
a2928c42 267
9c00a81b 268struct symbol *dso__first_symbol(struct dso *dso, enum map_type type);
cd67f99f 269struct symbol *dso__last_symbol(struct dso *dso, enum map_type type);
9c00a81b
AH
270struct symbol *dso__next_symbol(struct symbol *sym);
271
2b5b8bb2
AH
272enum dso_type dso__type_fd(int fd);
273
2643ce11 274int filename__read_build_id(const char *filename, void *bf, size_t size);
f1617b40 275int sysfs__read_build_id(const char *filename, void *bf, size_t size);
316d70d6
AH
276int modules__parse(const char *filename, void *arg,
277 int (*process_module)(void *arg, const char *name,
9ad4652b 278 u64 start, u64 size));
e5a1845f
NK
279int filename__read_debuglink(const char *filename, char *debuglink,
280 size_t size);
2643ce11 281
ce80d3be
KL
282struct perf_env;
283int symbol__init(struct perf_env *env);
d65a458b 284void symbol__exit(void);
166ccc9c 285void symbol__elf_init(void);
b01141f4
ACM
286int symbol__annotation_init(void);
287
e5a1845f 288struct symbol *symbol__new(u64 start, u64 len, u8 binding, const char *name);
fd4be130
ACM
289size_t __symbol__fprintf_symname_offs(const struct symbol *sym,
290 const struct addr_location *al,
a8763445
NK
291 bool unknown_as_addr,
292 bool print_offsets, FILE *fp);
a978f2ab
AN
293size_t symbol__fprintf_symname_offs(const struct symbol *sym,
294 const struct addr_location *al, FILE *fp);
fd4be130
ACM
295size_t __symbol__fprintf_symname(const struct symbol *sym,
296 const struct addr_location *al,
297 bool unknown_as_addr, FILE *fp);
547a92e0 298size_t symbol__fprintf_symname(const struct symbol *sym, FILE *fp);
cdd059d7 299size_t symbol__fprintf(struct symbol *sym, FILE *fp);
36a3e646 300bool symbol_type__is_a(char symbol_type, enum map_type map_type);
3f067dca
ACM
301bool symbol__restricted_filename(const char *filename,
302 const char *restricted_filename);
a7066709
HK
303int symbol__config_symfs(const struct option *opt __maybe_unused,
304 const char *dir, int unset __maybe_unused);
36a3e646 305
261360b6 306int dso__load_sym(struct dso *dso, struct map *map, struct symsrc *syms_ss,
be39db9f 307 struct symsrc *runtime_ss, int kmodule);
a44f605b 308int dso__synthesize_plt_symbols(struct dso *dso, struct symsrc *ss,
be39db9f 309 struct map *map);
e5a1845f 310
80c345b2 311char *dso__demangle_sym(struct dso *dso, int kmodule, const char *elf_name);
a64489c5 312
608c34de 313void __symbols__insert(struct rb_root *symbols, struct symbol *sym, bool kernel);
e5a1845f
NK
314void symbols__insert(struct rb_root *symbols, struct symbol *sym);
315void symbols__fixup_duplicate(struct rb_root *symbols);
316void symbols__fixup_end(struct rb_root *symbols);
317void __map_groups__fixup_end(struct map_groups *mg, enum map_type type);
318
8e0cf965
AH
319typedef int (*mapfn_t)(u64 start, u64 len, u64 pgoff, void *data);
320int file__read_maps(int fd, bool exe, mapfn_t mapfn, void *data,
321 bool *is_64_bit);
322
afba19d9
AH
323#define PERF_KCORE_EXTRACT "/tmp/perf-kcore-XXXXXX"
324
325struct kcore_extract {
326 char *kcore_filename;
327 u64 addr;
328 u64 offs;
329 u64 len;
330 char extract_filename[sizeof(PERF_KCORE_EXTRACT)];
331 int fd;
332};
333
334int kcore_extract__create(struct kcore_extract *kce);
335void kcore_extract__delete(struct kcore_extract *kce);
336
fc1b691d
AH
337int kcore_copy(const char *from_dir, const char *to_dir);
338int compare_proc_modules(const char *from, const char *to);
339
3bfe5f81
DA
340int setup_list(struct strlist **list, const char *list_str,
341 const char *list_name);
e03eaa40
DA
342int setup_intlist(struct intlist **list, const char *list_str,
343 const char *list_name);
3bfe5f81 344
d2332098
NR
345#ifdef HAVE_LIBELF_SUPPORT
346bool elf__needs_adjust_symbols(GElf_Ehdr ehdr);
0b3c2264 347void arch__sym_update(struct symbol *s, GElf_Sym *sym);
d2332098
NR
348#endif
349
fb6d5942
NR
350#define SYMBOL_A 0
351#define SYMBOL_B 1
352
d8040645
PC
353int arch__compare_symbol_names(const char *namea, const char *nameb);
354int arch__compare_symbol_names_n(const char *namea, const char *nameb,
355 unsigned int n);
fb6d5942
NR
356int arch__choose_best_symbol(struct symbol *syma, struct symbol *symb);
357
d8040645
PC
358enum symbol_tag_include {
359 SYMBOL_TAG_INCLUDE__NONE = 0,
360 SYMBOL_TAG_INCLUDE__DEFAULT_ONLY
361};
362
363int symbol__match_symbol_name(const char *namea, const char *nameb,
364 enum symbol_tag_include includes);
365
060fa0c7
HK
366/* structure containing an SDT note's info */
367struct sdt_note {
368 char *name; /* name of the note*/
369 char *provider; /* provider name */
be88184b 370 char *args;
060fa0c7
HK
371 bool bit32; /* whether the location is 32 bits? */
372 union { /* location, base and semaphore addrs */
373 Elf64_Addr a64[3];
374 Elf32_Addr a32[3];
375 } addr;
376 struct list_head note_list; /* SDT notes' list */
377};
378
379int get_sdt_note_list(struct list_head *head, const char *target);
380int cleanup_sdt_note_list(struct list_head *sdt_notes);
381int sdt_notes__get_count(struct list_head *start);
382
383#define SDT_BASE_SCN ".stapsdt.base"
384#define SDT_NOTE_SCN ".note.stapsdt"
385#define SDT_NOTE_TYPE 3
386#define SDT_NOTE_NAME "stapsdt"
387#define NR_ADDR 3
388
8b40f521 389#endif /* __PERF_SYMBOL */