1 // SPDX-License-Identifier: GPL-2.0-only
4 * Copyright (C) 2015 Naveen N. Rao, IBM Corporation
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 */
24 /* Avoid "SyS" kernel syscall aliases */
25 if (strlen(sym
) >= 3 && !strncmp(sym
, "SyS", 3))
27 if (strlen(sym
) >= 10 && !strncmp(sym
, "compat_SyS", 10))
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 */
43 return strcmp(namea
, nameb
);
46 int arch__compare_symbol_names_n(const char *namea
, const char *nameb
,
49 /* Skip over initial dot */
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
== '.')
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
;
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
,
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
)
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())
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
) {
111 tev
->point
.address
+= lep_offset
;
113 tev
->point
.offset
+= lep_offset
;
117 #ifdef HAVE_LIBELF_SUPPORT
118 void arch__post_process_probe_trace_events(struct perf_probe_event
*pev
,
121 struct probe_trace_event
*tev
;
123 struct symbol
*sym
= NULL
;
127 map
= get_target_map(pev
->target
, pev
->nsi
, pev
->uprobes
);
128 if (!map
|| map__load(map
) < 0)
131 for (i
= 0; i
< ntevs
; 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
);
141 #endif /* HAVE_LIBELF_SUPPORT */