1 /* SPDX-License-Identifier: GPL-2.0 */
3 #define __PERF_SYMBOL 1
5 #include <linux/types.h>
6 #include <linux/refcount.h>
9 #include <linux/list.h>
10 #include <linux/rbtree.h>
13 #include "symbol_conf.h"
15 #ifdef HAVE_LIBELF_SUPPORT
27 * libelf 0.8.x and earlier do not support ELF_C_READ_MMAP;
28 * for newer versions we can use mmap to reduce memory usage:
30 #ifdef HAVE_LIBELF_MMAP_SUPPORT
31 # define PERF_ELF_C_READ_MMAP ELF_C_READ_MMAP
33 # define PERF_ELF_C_READ_MMAP ELF_C_READ
36 #ifdef HAVE_LIBELF_SUPPORT
37 Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep,
38 GElf_Shdr *shp, const char *name, size_t *idx);
41 /** struct symbol - symtab entry
43 * @ignore - resolvable but tools ignore it (e.g. idle routines)
46 struct rb_node rb_node;
60 void symbol__delete(struct symbol *sym);
61 void symbols__delete(struct rb_root_cached *symbols);
63 /* symbols__for_each_entry - iterate over symbols (rb_root)
65 * @symbols: the rb_root of symbols
66 * @pos: the 'struct symbol *' to use as a loop cursor
67 * @nd: the 'struct rb_node *' to use as a temporary storage
69 #define symbols__for_each_entry(symbols, pos, nd) \
70 for (nd = rb_first_cached(symbols); \
71 nd && (pos = rb_entry(nd, struct symbol, rb_node)); \
74 static inline size_t symbol__size(const struct symbol *sym)
76 return sym->end - sym->start;
82 struct symbol_name_rb_node {
83 struct rb_node rb_node;
87 static inline int __symbol__join_symfs(char *bf, size_t size, const char *path)
89 return path__join(bf, size, symbol_conf.symfs, path);
92 #define symbol__join_symfs(bf, path) __symbol__join_symfs(bf, sizeof(bf), path)
94 extern int vmlinux_path__nr_entries;
95 extern char **vmlinux_path;
97 static inline void *symbol__priv(struct symbol *sym)
99 return ((void *)sym) - symbol_conf.priv_size;
102 struct ref_reloc_sym {
105 u64 unrelocated_addr;
119 struct addr_location {
120 struct machine *machine;
121 struct thread *thread;
133 int dso__load(struct dso *dso, struct map *map);
134 int dso__load_vmlinux(struct dso *dso, struct map *map,
135 const char *vmlinux, bool vmlinux_allocated);
136 int dso__load_vmlinux_path(struct dso *dso, struct map *map);
137 int __dso__load_kallsyms(struct dso *dso, const char *filename, struct map *map,
139 int dso__load_kallsyms(struct dso *dso, const char *filename, struct map *map);
141 void dso__insert_symbol(struct dso *dso,
144 struct symbol *dso__find_symbol(struct dso *dso, u64 addr);
145 struct symbol *dso__find_symbol_by_name(struct dso *dso, const char *name);
147 struct symbol *symbol__next_by_name(struct symbol *sym);
149 struct symbol *dso__first_symbol(struct dso *dso);
150 struct symbol *dso__last_symbol(struct dso *dso);
151 struct symbol *dso__next_symbol(struct symbol *sym);
153 enum dso_type dso__type_fd(int fd);
155 int filename__read_build_id(const char *filename, void *bf, size_t size);
156 int sysfs__read_build_id(const char *filename, void *bf, size_t size);
157 int modules__parse(const char *filename, void *arg,
158 int (*process_module)(void *arg, const char *name,
159 u64 start, u64 size));
160 int filename__read_debuglink(const char *filename, char *debuglink,
164 int symbol__init(struct perf_env *env);
165 void symbol__exit(void);
166 void symbol__elf_init(void);
167 int symbol__annotation_init(void);
169 struct symbol *symbol__new(u64 start, u64 len, u8 binding, u8 type, const char *name);
170 size_t __symbol__fprintf_symname_offs(const struct symbol *sym,
171 const struct addr_location *al,
172 bool unknown_as_addr,
173 bool print_offsets, FILE *fp);
174 size_t symbol__fprintf_symname_offs(const struct symbol *sym,
175 const struct addr_location *al, FILE *fp);
176 size_t __symbol__fprintf_symname(const struct symbol *sym,
177 const struct addr_location *al,
178 bool unknown_as_addr, FILE *fp);
179 size_t symbol__fprintf_symname(const struct symbol *sym, FILE *fp);
180 size_t symbol__fprintf(struct symbol *sym, FILE *fp);
181 bool symbol__restricted_filename(const char *filename,
182 const char *restricted_filename);
183 int symbol__config_symfs(const struct option *opt __maybe_unused,
184 const char *dir, int unset __maybe_unused);
188 int dso__load_sym(struct dso *dso, struct map *map, struct symsrc *syms_ss,
189 struct symsrc *runtime_ss, int kmodule);
190 int dso__synthesize_plt_symbols(struct dso *dso, struct symsrc *ss);
192 char *dso__demangle_sym(struct dso *dso, int kmodule, const char *elf_name);
194 void __symbols__insert(struct rb_root_cached *symbols, struct symbol *sym,
196 void symbols__insert(struct rb_root_cached *symbols, struct symbol *sym);
197 void symbols__fixup_duplicate(struct rb_root_cached *symbols);
198 void symbols__fixup_end(struct rb_root_cached *symbols);
199 void map_groups__fixup_end(struct map_groups *mg);
201 typedef int (*mapfn_t)(u64 start, u64 len, u64 pgoff, void *data);
202 int file__read_maps(int fd, bool exe, mapfn_t mapfn, void *data,
205 #define PERF_KCORE_EXTRACT "/tmp/perf-kcore-XXXXXX"
207 struct kcore_extract {
208 char *kcore_filename;
212 char extract_filename[sizeof(PERF_KCORE_EXTRACT)];
216 int kcore_extract__create(struct kcore_extract *kce);
217 void kcore_extract__delete(struct kcore_extract *kce);
219 int kcore_copy(const char *from_dir, const char *to_dir);
220 int compare_proc_modules(const char *from, const char *to);
222 int setup_list(struct strlist **list, const char *list_str,
223 const char *list_name);
224 int setup_intlist(struct intlist **list, const char *list_str,
225 const char *list_name);
227 #ifdef HAVE_LIBELF_SUPPORT
228 bool elf__needs_adjust_symbols(GElf_Ehdr ehdr);
229 void arch__sym_update(struct symbol *s, GElf_Sym *sym);
232 const char *arch__normalize_symbol_name(const char *name);
236 void arch__symbols__fixup_end(struct symbol *p, struct symbol *c);
237 int arch__compare_symbol_names(const char *namea, const char *nameb);
238 int arch__compare_symbol_names_n(const char *namea, const char *nameb,
240 int arch__choose_best_symbol(struct symbol *syma, struct symbol *symb);
242 enum symbol_tag_include {
243 SYMBOL_TAG_INCLUDE__NONE = 0,
244 SYMBOL_TAG_INCLUDE__DEFAULT_ONLY
247 int symbol__match_symbol_name(const char *namea, const char *nameb,
248 enum symbol_tag_include includes);
250 /* structure containing an SDT note's info */
252 char *name; /* name of the note*/
253 char *provider; /* provider name */
255 bool bit32; /* whether the location is 32 bits? */
256 union { /* location, base and semaphore addrs */
260 struct list_head note_list; /* SDT notes' list */
263 int get_sdt_note_list(struct list_head *head, const char *target);
264 int cleanup_sdt_note_list(struct list_head *sdt_notes);
265 int sdt_notes__get_count(struct list_head *start);
267 #define SDT_PROBES_SCN ".probes"
268 #define SDT_BASE_SCN ".stapsdt.base"
269 #define SDT_NOTE_SCN ".note.stapsdt"
270 #define SDT_NOTE_TYPE 3
271 #define SDT_NOTE_NAME "stapsdt"
275 SDT_NOTE_IDX_LOC = 0,
280 struct mem_info *mem_info__new(void);
281 struct mem_info *mem_info__get(struct mem_info *mi);
282 void mem_info__put(struct mem_info *mi);
284 static inline void __mem_info__zput(struct mem_info **mi)
290 #define mem_info__zput(mi) __mem_info__zput(&mi)
292 struct block_info *block_info__new(void);
293 struct block_info *block_info__get(struct block_info *bi);
294 void block_info__put(struct block_info *bi);
296 static inline void __block_info__zput(struct block_info **bi)
298 block_info__put(*bi);
302 #define block_info__zput(bi) __block_info__zput(&bi)
304 #endif /* __PERF_SYMBOL */