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 #ifdef HAVE_LIBELF_SUPPORT
14 bool elf__needs_adjust_symbols(GElf_Ehdr ehdr
)
16 return ehdr
.e_type
== ET_EXEC
||
17 ehdr
.e_type
== ET_REL
||
18 ehdr
.e_type
== ET_DYN
;
23 int arch__choose_best_symbol(struct symbol
*syma
,
24 struct symbol
*symb __maybe_unused
)
26 char *sym
= syma
->name
;
28 #if !defined(_CALL_ELF) || _CALL_ELF != 2
29 /* Skip over any initial dot */
34 /* Avoid "SyS" kernel syscall aliases */
35 if (strlen(sym
) >= 3 && !strncmp(sym
, "SyS", 3))
37 if (strlen(sym
) >= 10 && !strncmp(sym
, "compat_SyS", 10))
43 #if !defined(_CALL_ELF) || _CALL_ELF != 2
44 /* Allow matching against dot variants */
45 int arch__compare_symbol_names(const char *namea
, const char *nameb
)
47 /* Skip over initial dot */
53 return strcmp(namea
, nameb
);
56 int arch__compare_symbol_names_n(const char *namea
, const char *nameb
,
59 /* Skip over initial dot */
65 return strncmp(namea
, nameb
, n
);
68 const char *arch__normalize_symbol_name(const char *name
)
70 /* Skip over initial dot */
71 if (name
&& *name
== '.')
77 #if defined(_CALL_ELF) && _CALL_ELF == 2
79 #ifdef HAVE_LIBELF_SUPPORT
80 void arch__sym_update(struct symbol
*s
, GElf_Sym
*sym
)
82 s
->arch_sym
= sym
->st_other
;
86 #define PPC64LE_LEP_OFFSET 8
88 void arch__fix_tev_from_maps(struct perf_probe_event
*pev
,
89 struct probe_trace_event
*tev
, struct map
*map
,
95 * When probing at a function entry point, we normally always want the
96 * LEP since that catches calls to the function through both the GEP and
97 * the LEP. Hence, we would like to probe at an offset of 8 bytes if
98 * the user only specified the function entry.
100 * However, if the user specifies an offset, we fall back to using the
101 * GEP since all userspace applications (objdump/readelf) show function
102 * disassembly with offsets from the GEP.
104 if (pev
->point
.offset
|| !map
|| !sym
)
107 /* For kretprobes, add an offset only if the kernel supports it */
108 if (!pev
->uprobes
&& pev
->point
.retprobe
) {
109 #ifdef HAVE_LIBELF_SUPPORT
110 if (!kretprobe_offset_is_supported())
115 lep_offset
= PPC64_LOCAL_ENTRY_OFFSET(sym
->arch_sym
);
117 if (map
->dso
->symtab_type
== DSO_BINARY_TYPE__KALLSYMS
)
118 tev
->point
.offset
+= PPC64LE_LEP_OFFSET
;
119 else if (lep_offset
) {
121 tev
->point
.address
+= lep_offset
;
123 tev
->point
.offset
+= lep_offset
;
127 #ifdef HAVE_LIBELF_SUPPORT
128 void arch__post_process_probe_trace_events(struct perf_probe_event
*pev
,
131 struct probe_trace_event
*tev
;
133 struct symbol
*sym
= NULL
;
137 map
= get_target_map(pev
->target
, pev
->nsi
, pev
->uprobes
);
138 if (!map
|| map__load(map
) < 0)
141 for (i
= 0; i
< ntevs
; i
++) {
143 map__for_each_symbol(map
, sym
, tmp
) {
144 if (map
->unmap_ip(map
, sym
->start
) == tev
->point
.address
) {
145 arch__fix_tev_from_maps(pev
, tev
, map
, sym
);
151 #endif /* HAVE_LIBELF_SUPPORT */