Linux 5.1.15
[linux/fpc-iii.git] / tools / perf / arch / powerpc / util / sym-handling.c
blob10a44e946f7734b911ed00f74184f754b09d56ba
1 /*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License, version 2, as
4 * published by the Free Software Foundation.
6 * Copyright (C) 2015 Naveen N. Rao, IBM Corporation
7 */
9 #include "debug.h"
10 #include "symbol.h"
11 #include "map.h"
12 #include "probe-event.h"
13 #include "probe-file.h"
15 #ifdef HAVE_LIBELF_SUPPORT
16 bool elf__needs_adjust_symbols(GElf_Ehdr ehdr)
18 return ehdr.e_type == ET_EXEC ||
19 ehdr.e_type == ET_REL ||
20 ehdr.e_type == ET_DYN;
23 #endif
25 int arch__choose_best_symbol(struct symbol *syma,
26 struct symbol *symb __maybe_unused)
28 char *sym = syma->name;
30 #if !defined(_CALL_ELF) || _CALL_ELF != 2
31 /* Skip over any initial dot */
32 if (*sym == '.')
33 sym++;
34 #endif
36 /* Avoid "SyS" kernel syscall aliases */
37 if (strlen(sym) >= 3 && !strncmp(sym, "SyS", 3))
38 return SYMBOL_B;
39 if (strlen(sym) >= 10 && !strncmp(sym, "compat_SyS", 10))
40 return SYMBOL_B;
42 return SYMBOL_A;
45 #if !defined(_CALL_ELF) || _CALL_ELF != 2
46 /* Allow matching against dot variants */
47 int arch__compare_symbol_names(const char *namea, const char *nameb)
49 /* Skip over initial dot */
50 if (*namea == '.')
51 namea++;
52 if (*nameb == '.')
53 nameb++;
55 return strcmp(namea, nameb);
58 int arch__compare_symbol_names_n(const char *namea, const char *nameb,
59 unsigned int n)
61 /* Skip over initial dot */
62 if (*namea == '.')
63 namea++;
64 if (*nameb == '.')
65 nameb++;
67 return strncmp(namea, nameb, n);
70 const char *arch__normalize_symbol_name(const char *name)
72 /* Skip over initial dot */
73 if (name && *name == '.')
74 name++;
75 return name;
77 #endif
79 #if defined(_CALL_ELF) && _CALL_ELF == 2
81 #ifdef HAVE_LIBELF_SUPPORT
82 void arch__sym_update(struct symbol *s, GElf_Sym *sym)
84 s->arch_sym = sym->st_other;
86 #endif
88 #define PPC64LE_LEP_OFFSET 8
90 void arch__fix_tev_from_maps(struct perf_probe_event *pev,
91 struct probe_trace_event *tev, struct map *map,
92 struct symbol *sym)
94 int lep_offset;
97 * When probing at a function entry point, we normally always want the
98 * LEP since that catches calls to the function through both the GEP and
99 * the LEP. Hence, we would like to probe at an offset of 8 bytes if
100 * the user only specified the function entry.
102 * However, if the user specifies an offset, we fall back to using the
103 * GEP since all userspace applications (objdump/readelf) show function
104 * disassembly with offsets from the GEP.
106 if (pev->point.offset || !map || !sym)
107 return;
109 /* For kretprobes, add an offset only if the kernel supports it */
110 if (!pev->uprobes && pev->point.retprobe) {
111 #ifdef HAVE_LIBELF_SUPPORT
112 if (!kretprobe_offset_is_supported())
113 #endif
114 return;
117 lep_offset = PPC64_LOCAL_ENTRY_OFFSET(sym->arch_sym);
119 if (map->dso->symtab_type == DSO_BINARY_TYPE__KALLSYMS)
120 tev->point.offset += PPC64LE_LEP_OFFSET;
121 else if (lep_offset) {
122 if (pev->uprobes)
123 tev->point.address += lep_offset;
124 else
125 tev->point.offset += lep_offset;
129 #ifdef HAVE_LIBELF_SUPPORT
130 void arch__post_process_probe_trace_events(struct perf_probe_event *pev,
131 int ntevs)
133 struct probe_trace_event *tev;
134 struct map *map;
135 struct symbol *sym = NULL;
136 struct rb_node *tmp;
137 int i = 0;
139 map = get_target_map(pev->target, pev->nsi, pev->uprobes);
140 if (!map || map__load(map) < 0)
141 return;
143 for (i = 0; i < ntevs; i++) {
144 tev = &pev->tevs[i];
145 map__for_each_symbol(map, sym, tmp) {
146 if (map->unmap_ip(map, sym->start) == tev->point.address) {
147 arch__fix_tev_from_maps(pev, tev, map, sym);
148 break;
153 #endif /* HAVE_LIBELF_SUPPORT */
155 #endif