Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef __PERF_SYMBOL
0003 #define __PERF_SYMBOL 1
0004 
0005 #include <linux/types.h>
0006 #include <linux/refcount.h>
0007 #include <stdbool.h>
0008 #include <stdint.h>
0009 #include <linux/list.h>
0010 #include <linux/rbtree.h>
0011 #include <stdio.h>
0012 #include "path.h"
0013 #include "symbol_conf.h"
0014 #include "spark.h"
0015 
0016 #ifdef HAVE_LIBELF_SUPPORT
0017 #include <libelf.h>
0018 #include <gelf.h>
0019 #endif
0020 #include <elf.h>
0021 
0022 struct dso;
0023 struct map;
0024 struct maps;
0025 struct option;
0026 struct build_id;
0027 
0028 /*
0029  * libelf 0.8.x and earlier do not support ELF_C_READ_MMAP;
0030  * for newer versions we can use mmap to reduce memory usage:
0031  */
0032 #ifdef ELF_C_READ_MMAP
0033 # define PERF_ELF_C_READ_MMAP ELF_C_READ_MMAP
0034 #else
0035 # define PERF_ELF_C_READ_MMAP ELF_C_READ
0036 #endif
0037 
0038 #ifdef HAVE_LIBELF_SUPPORT
0039 Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep,
0040                  GElf_Shdr *shp, const char *name, size_t *idx);
0041 #endif
0042 
0043 /**
0044  * A symtab entry. When allocated this may be preceded by an annotation (see
0045  * symbol__annotation), a browser_index (see symbol__browser_index) and rb_node
0046  * to sort by name (see struct symbol_name_rb_node).
0047  */
0048 struct symbol {
0049     struct rb_node  rb_node;
0050     /** Range of symbol [start, end). */
0051     u64     start;
0052     u64     end;
0053     /** Length of the string name. */
0054     u16     namelen;
0055     /** ELF symbol type as defined for st_info. E.g STT_OBJECT or STT_FUNC. */
0056     u8      type:4;
0057     /** ELF binding type as defined for st_info. E.g. STB_WEAK or STB_GLOBAL. */
0058     u8      binding:4;
0059     /** Set true for kernel symbols of idle routines. */
0060     u8      idle:1;
0061     /** Resolvable but tools ignore it (e.g. idle routines). */
0062     u8      ignore:1;
0063     /** Symbol for an inlined function. */
0064     u8      inlined:1;
0065     /** Has symbol__annotate2 been performed. */
0066     u8      annotate2:1;
0067     /** Architecture specific. Unused except on PPC where it holds st_other. */
0068     u8      arch_sym;
0069     /** The name of length namelen associated with the symbol. */
0070     char        name[];
0071 };
0072 
0073 void symbol__delete(struct symbol *sym);
0074 void symbols__delete(struct rb_root_cached *symbols);
0075 
0076 /* symbols__for_each_entry - iterate over symbols (rb_root)
0077  *
0078  * @symbols: the rb_root of symbols
0079  * @pos: the 'struct symbol *' to use as a loop cursor
0080  * @nd: the 'struct rb_node *' to use as a temporary storage
0081  */
0082 #define symbols__for_each_entry(symbols, pos, nd)           \
0083     for (nd = rb_first_cached(symbols);                 \
0084          nd && (pos = rb_entry(nd, struct symbol, rb_node));    \
0085          nd = rb_next(nd))
0086 
0087 static inline size_t symbol__size(const struct symbol *sym)
0088 {
0089     return sym->end - sym->start;
0090 }
0091 
0092 struct strlist;
0093 struct intlist;
0094 
0095 struct symbol_name_rb_node {
0096     struct rb_node  rb_node;
0097     struct symbol   sym;
0098 };
0099 
0100 static inline int __symbol__join_symfs(char *bf, size_t size, const char *path)
0101 {
0102     return path__join(bf, size, symbol_conf.symfs, path);
0103 }
0104 
0105 #define symbol__join_symfs(bf, path) __symbol__join_symfs(bf, sizeof(bf), path)
0106 
0107 extern int vmlinux_path__nr_entries;
0108 extern char **vmlinux_path;
0109 
0110 static inline void *symbol__priv(struct symbol *sym)
0111 {
0112     return ((void *)sym) - symbol_conf.priv_size;
0113 }
0114 
0115 struct ref_reloc_sym {
0116     const char  *name;
0117     u64     addr;
0118     u64     unrelocated_addr;
0119 };
0120 
0121 struct addr_location {
0122     struct thread *thread;
0123     struct maps   *maps;
0124     struct map    *map;
0125     struct symbol *sym;
0126     const char    *srcline;
0127     u64       addr;
0128     char          level;
0129     u8        filtered;
0130     u8        cpumode;
0131     s32       cpu;
0132     s32       socket;
0133 };
0134 
0135 int dso__load(struct dso *dso, struct map *map);
0136 int dso__load_vmlinux(struct dso *dso, struct map *map,
0137               const char *vmlinux, bool vmlinux_allocated);
0138 int dso__load_vmlinux_path(struct dso *dso, struct map *map);
0139 int __dso__load_kallsyms(struct dso *dso, const char *filename, struct map *map,
0140              bool no_kcore);
0141 int dso__load_kallsyms(struct dso *dso, const char *filename, struct map *map);
0142 
0143 void dso__insert_symbol(struct dso *dso,
0144             struct symbol *sym);
0145 void dso__delete_symbol(struct dso *dso,
0146             struct symbol *sym);
0147 
0148 struct symbol *dso__find_symbol(struct dso *dso, u64 addr);
0149 struct symbol *dso__find_symbol_by_name(struct dso *dso, const char *name);
0150 
0151 struct symbol *symbol__next_by_name(struct symbol *sym);
0152 
0153 struct symbol *dso__first_symbol(struct dso *dso);
0154 struct symbol *dso__last_symbol(struct dso *dso);
0155 struct symbol *dso__next_symbol(struct symbol *sym);
0156 
0157 enum dso_type dso__type_fd(int fd);
0158 
0159 int filename__read_build_id(const char *filename, struct build_id *id);
0160 int sysfs__read_build_id(const char *filename, struct build_id *bid);
0161 int modules__parse(const char *filename, void *arg,
0162            int (*process_module)(void *arg, const char *name,
0163                      u64 start, u64 size));
0164 int filename__read_debuglink(const char *filename, char *debuglink,
0165                  size_t size);
0166 
0167 struct perf_env;
0168 int symbol__init(struct perf_env *env);
0169 void symbol__exit(void);
0170 void symbol__elf_init(void);
0171 int symbol__annotation_init(void);
0172 
0173 struct symbol *symbol__new(u64 start, u64 len, u8 binding, u8 type, const char *name);
0174 size_t __symbol__fprintf_symname_offs(const struct symbol *sym,
0175                       const struct addr_location *al,
0176                       bool unknown_as_addr,
0177                       bool print_offsets, FILE *fp);
0178 size_t symbol__fprintf_symname_offs(const struct symbol *sym,
0179                     const struct addr_location *al, FILE *fp);
0180 size_t __symbol__fprintf_symname(const struct symbol *sym,
0181                  const struct addr_location *al,
0182                  bool unknown_as_addr, FILE *fp);
0183 size_t symbol__fprintf_symname(const struct symbol *sym, FILE *fp);
0184 size_t symbol__fprintf(struct symbol *sym, FILE *fp);
0185 bool symbol__restricted_filename(const char *filename,
0186                  const char *restricted_filename);
0187 int symbol__config_symfs(const struct option *opt __maybe_unused,
0188              const char *dir, int unset __maybe_unused);
0189 
0190 struct symsrc;
0191 
0192 #ifdef HAVE_LIBBFD_SUPPORT
0193 int dso__load_bfd_symbols(struct dso *dso, const char *debugfile);
0194 #endif
0195 
0196 int dso__load_sym(struct dso *dso, struct map *map, struct symsrc *syms_ss,
0197           struct symsrc *runtime_ss, int kmodule);
0198 int dso__synthesize_plt_symbols(struct dso *dso, struct symsrc *ss);
0199 
0200 char *dso__demangle_sym(struct dso *dso, int kmodule, const char *elf_name);
0201 
0202 void __symbols__insert(struct rb_root_cached *symbols, struct symbol *sym,
0203                bool kernel);
0204 void symbols__insert(struct rb_root_cached *symbols, struct symbol *sym);
0205 void symbols__fixup_duplicate(struct rb_root_cached *symbols);
0206 void symbols__fixup_end(struct rb_root_cached *symbols, bool is_kallsyms);
0207 void maps__fixup_end(struct maps *maps);
0208 
0209 typedef int (*mapfn_t)(u64 start, u64 len, u64 pgoff, void *data);
0210 int file__read_maps(int fd, bool exe, mapfn_t mapfn, void *data,
0211             bool *is_64_bit);
0212 
0213 #define PERF_KCORE_EXTRACT "/tmp/perf-kcore-XXXXXX"
0214 
0215 struct kcore_extract {
0216     char *kcore_filename;
0217     u64 addr;
0218     u64 offs;
0219     u64 len;
0220     char extract_filename[sizeof(PERF_KCORE_EXTRACT)];
0221     int fd;
0222 };
0223 
0224 int kcore_extract__create(struct kcore_extract *kce);
0225 void kcore_extract__delete(struct kcore_extract *kce);
0226 
0227 int kcore_copy(const char *from_dir, const char *to_dir);
0228 int compare_proc_modules(const char *from, const char *to);
0229 
0230 int setup_list(struct strlist **list, const char *list_str,
0231            const char *list_name);
0232 int setup_intlist(struct intlist **list, const char *list_str,
0233           const char *list_name);
0234 
0235 #ifdef HAVE_LIBELF_SUPPORT
0236 bool elf__needs_adjust_symbols(GElf_Ehdr ehdr);
0237 void arch__sym_update(struct symbol *s, GElf_Sym *sym);
0238 #endif
0239 
0240 const char *arch__normalize_symbol_name(const char *name);
0241 #define SYMBOL_A 0
0242 #define SYMBOL_B 1
0243 
0244 int arch__compare_symbol_names(const char *namea, const char *nameb);
0245 int arch__compare_symbol_names_n(const char *namea, const char *nameb,
0246                  unsigned int n);
0247 int arch__choose_best_symbol(struct symbol *syma, struct symbol *symb);
0248 
0249 enum symbol_tag_include {
0250     SYMBOL_TAG_INCLUDE__NONE = 0,
0251     SYMBOL_TAG_INCLUDE__DEFAULT_ONLY
0252 };
0253 
0254 int symbol__match_symbol_name(const char *namea, const char *nameb,
0255                   enum symbol_tag_include includes);
0256 
0257 /* structure containing an SDT note's info */
0258 struct sdt_note {
0259     char *name;         /* name of the note*/
0260     char *provider;         /* provider name */
0261     char *args;
0262     bool bit32;         /* whether the location is 32 bits? */
0263     union {             /* location, base and semaphore addrs */
0264         Elf64_Addr a64[3];
0265         Elf32_Addr a32[3];
0266     } addr;
0267     struct list_head note_list; /* SDT notes' list */
0268 };
0269 
0270 int get_sdt_note_list(struct list_head *head, const char *target);
0271 int cleanup_sdt_note_list(struct list_head *sdt_notes);
0272 int sdt_notes__get_count(struct list_head *start);
0273 
0274 #define SDT_PROBES_SCN ".probes"
0275 #define SDT_BASE_SCN ".stapsdt.base"
0276 #define SDT_NOTE_SCN  ".note.stapsdt"
0277 #define SDT_NOTE_TYPE 3
0278 #define SDT_NOTE_NAME "stapsdt"
0279 #define NR_ADDR 3
0280 
0281 enum {
0282     SDT_NOTE_IDX_LOC = 0,
0283     SDT_NOTE_IDX_BASE,
0284     SDT_NOTE_IDX_REFCTR,
0285 };
0286 
0287 struct mem_info *mem_info__new(void);
0288 struct mem_info *mem_info__get(struct mem_info *mi);
0289 void   mem_info__put(struct mem_info *mi);
0290 
0291 static inline void __mem_info__zput(struct mem_info **mi)
0292 {
0293     mem_info__put(*mi);
0294     *mi = NULL;
0295 }
0296 
0297 #define mem_info__zput(mi) __mem_info__zput(&mi)
0298 
0299 int symbol__validate_sym_arguments(void);
0300 
0301 #endif /* __PERF_SYMBOL */