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 #if !defined(_CALL_ELF) || _CALL_ELF != 2
26 int arch__choose_best_symbol(struct symbol *syma,
27 struct symbol *symb __maybe_unused)
29 char *sym = syma->name;
31 /* Skip over any initial dot */
35 /* Avoid "SyS" kernel syscall aliases */
36 if (strlen(sym) >= 3 && !strncmp(sym, "SyS", 3))
38 if (strlen(sym) >= 10 && !strncmp(sym, "compat_SyS", 10))
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);
57 #if defined(_CALL_ELF) && _CALL_ELF == 2
59 #ifdef HAVE_LIBELF_SUPPORT
60 void arch__sym_update(struct symbol *s, GElf_Sym *sym)
62 s->arch_sym = sym->st_other;
66 #define PPC64LE_LEP_OFFSET 8
68 void arch__fix_tev_from_maps(struct perf_probe_event *pev,
69 struct probe_trace_event *tev, struct map *map,
75 * When probing at a function entry point, we normally always want the
76 * LEP since that catches calls to the function through both the GEP and
77 * the LEP. Hence, we would like to probe at an offset of 8 bytes if
78 * the user only specified the function entry.
80 * However, if the user specifies an offset, we fall back to using the
81 * GEP since all userspace applications (objdump/readelf) show function
82 * disassembly with offsets from the GEP.
84 if (pev->point.offset || !map || !sym)
87 /* For kretprobes, add an offset only if the kernel supports it */
88 if (!pev->uprobes && pev->point.retprobe) {
89 #ifdef HAVE_LIBELF_SUPPORT
90 if (!kretprobe_offset_is_supported())
95 lep_offset = PPC64_LOCAL_ENTRY_OFFSET(sym->arch_sym);
97 if (map->dso->symtab_type == DSO_BINARY_TYPE__KALLSYMS)
98 tev->point.offset += PPC64LE_LEP_OFFSET;
99 else if (lep_offset) {
101 tev->point.address += lep_offset;
103 tev->point.offset += lep_offset;
107 #ifdef HAVE_LIBELF_SUPPORT
108 void arch__post_process_probe_trace_events(struct perf_probe_event *pev,
111 struct probe_trace_event *tev;
113 struct symbol *sym = NULL;
117 map = get_target_map(pev->target, pev->uprobes);
118 if (!map || map__load(map) < 0)
121 for (i = 0; i < ntevs; i++) {
123 map__for_each_symbol(map, sym, tmp) {
124 if (map->unmap_ip(map, sym->start) == tev->point.address)
125 arch__fix_tev_from_maps(pev, tev, map, sym);
129 #endif /* HAVE_LIBELF_SUPPORT */