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
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
;
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 */
36 /* Avoid "SyS" kernel syscall aliases */
37 if (strlen(sym
) >= 3 && !strncmp(sym
, "SyS", 3))
39 if (strlen(sym
) >= 10 && !strncmp(sym
, "compat_SyS", 10))
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 */
55 return strcmp(namea
, nameb
);
58 int arch__compare_symbol_names_n(const char *namea
, const char *nameb
,
61 /* Skip over initial dot */
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
== '.')
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
;
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
,
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
)
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())
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
) {
123 tev
->point
.address
+= lep_offset
;
125 tev
->point
.offset
+= lep_offset
;
129 #ifdef HAVE_LIBELF_SUPPORT
130 void arch__post_process_probe_trace_events(struct perf_probe_event
*pev
,
133 struct probe_trace_event
*tev
;
135 struct symbol
*sym
= NULL
;
139 map
= get_target_map(pev
->target
, pev
->nsi
, pev
->uprobes
);
140 if (!map
|| map__load(map
) < 0)
143 for (i
= 0; i
< ntevs
; 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
);
153 #endif /* HAVE_LIBELF_SUPPORT */