Merge tag 'block-5.11-2021-01-10' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / tools / perf / arch / powerpc / util / sym-handling.c
blob0856b32f9e08a1f525997e7fa8e93d64ad00244e
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
4 * Copyright (C) 2015 Naveen N. Rao, IBM Corporation
5 */
7 #include "dso.h"
8 #include "symbol.h"
9 #include "map.h"
10 #include "probe-event.h"
11 #include "probe-file.h"
13 int arch__choose_best_symbol(struct symbol *syma,
14 struct symbol *symb __maybe_unused)
16 char *sym = syma->name;
18 #if !defined(_CALL_ELF) || _CALL_ELF != 2
19 /* Skip over any initial dot */
20 if (*sym == '.')
21 sym++;
22 #endif
24 /* Avoid "SyS" kernel syscall aliases */
25 if (strlen(sym) >= 3 && !strncmp(sym, "SyS", 3))
26 return SYMBOL_B;
27 if (strlen(sym) >= 10 && !strncmp(sym, "compat_SyS", 10))
28 return SYMBOL_B;
30 return SYMBOL_A;
33 #if !defined(_CALL_ELF) || _CALL_ELF != 2
34 /* Allow matching against dot variants */
35 int arch__compare_symbol_names(const char *namea, const char *nameb)
37 /* Skip over initial dot */
38 if (*namea == '.')
39 namea++;
40 if (*nameb == '.')
41 nameb++;
43 return strcmp(namea, nameb);
46 int arch__compare_symbol_names_n(const char *namea, const char *nameb,
47 unsigned int n)
49 /* Skip over initial dot */
50 if (*namea == '.')
51 namea++;
52 if (*nameb == '.')
53 nameb++;
55 return strncmp(namea, nameb, n);
58 const char *arch__normalize_symbol_name(const char *name)
60 /* Skip over initial dot */
61 if (name && *name == '.')
62 name++;
63 return name;
65 #endif
67 #if defined(_CALL_ELF) && _CALL_ELF == 2
69 #ifdef HAVE_LIBELF_SUPPORT
70 void arch__sym_update(struct symbol *s, GElf_Sym *sym)
72 s->arch_sym = sym->st_other;
74 #endif
76 #define PPC64LE_LEP_OFFSET 8
78 void arch__fix_tev_from_maps(struct perf_probe_event *pev,
79 struct probe_trace_event *tev, struct map *map,
80 struct symbol *sym)
82 int lep_offset;
85 * When probing at a function entry point, we normally always want the
86 * LEP since that catches calls to the function through both the GEP and
87 * the LEP. Hence, we would like to probe at an offset of 8 bytes if
88 * the user only specified the function entry.
90 * However, if the user specifies an offset, we fall back to using the
91 * GEP since all userspace applications (objdump/readelf) show function
92 * disassembly with offsets from the GEP.
94 if (pev->point.offset || !map || !sym)
95 return;
97 /* For kretprobes, add an offset only if the kernel supports it */
98 if (!pev->uprobes && pev->point.retprobe) {
99 #ifdef HAVE_LIBELF_SUPPORT
100 if (!kretprobe_offset_is_supported())
101 #endif
102 return;
105 lep_offset = PPC64_LOCAL_ENTRY_OFFSET(sym->arch_sym);
107 if (map->dso->symtab_type == DSO_BINARY_TYPE__KALLSYMS)
108 tev->point.offset += PPC64LE_LEP_OFFSET;
109 else if (lep_offset) {
110 if (pev->uprobes)
111 tev->point.address += lep_offset;
112 else
113 tev->point.offset += lep_offset;
117 #ifdef HAVE_LIBELF_SUPPORT
118 void arch__post_process_probe_trace_events(struct perf_probe_event *pev,
119 int ntevs)
121 struct probe_trace_event *tev;
122 struct map *map;
123 struct symbol *sym = NULL;
124 struct rb_node *tmp;
125 int i = 0;
127 map = get_target_map(pev->target, pev->nsi, pev->uprobes);
128 if (!map || map__load(map) < 0)
129 return;
131 for (i = 0; i < ntevs; i++) {
132 tev = &pev->tevs[i];
133 map__for_each_symbol(map, sym, tmp) {
134 if (map->unmap_ip(map, sym->start) == tev->point.address) {
135 arch__fix_tev_from_maps(pev, tev, map, sym);
136 break;
141 #endif /* HAVE_LIBELF_SUPPORT */
143 #endif