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"
14 #ifdef HAVE_LIBELF_SUPPORT
15 bool elf__needs_adjust_symbols(GElf_Ehdr ehdr)
17 return ehdr.e_type == ET_EXEC ||
18 ehdr.e_type == ET_REL ||
19 ehdr.e_type == ET_DYN;
24 int arch__choose_best_symbol(struct symbol *syma,
25 struct symbol *symb __maybe_unused)
27 char *sym = syma->name;
29 #if !defined(_CALL_ELF) || _CALL_ELF != 2
30 /* 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 #if !defined(_CALL_ELF) || _CALL_ELF != 2
45 /* Allow matching against dot variants */
46 int arch__compare_symbol_names(const char *namea, const char *nameb)
48 /* Skip over initial dot */
54 return strcmp(namea, nameb);
58 #if defined(_CALL_ELF) && _CALL_ELF == 2
60 #ifdef HAVE_LIBELF_SUPPORT
61 void arch__sym_update(struct symbol *s, GElf_Sym *sym)
63 s->arch_sym = sym->st_other;
67 #define PPC64LE_LEP_OFFSET 8
69 void arch__fix_tev_from_maps(struct perf_probe_event *pev,
70 struct probe_trace_event *tev, struct map *map,
76 * When probing at a function entry point, we normally always want the
77 * LEP since that catches calls to the function through both the GEP and
78 * the LEP. Hence, we would like to probe at an offset of 8 bytes if
79 * the user only specified the function entry.
81 * However, if the user specifies an offset, we fall back to using the
82 * GEP since all userspace applications (objdump/readelf) show function
83 * disassembly with offsets from the GEP.
85 * In addition, we shouldn't specify an offset for kretprobes.
87 if (pev->point.offset || (!pev->uprobes && pev->point.retprobe) ||
91 lep_offset = PPC64_LOCAL_ENTRY_OFFSET(sym->arch_sym);
93 if (map->dso->symtab_type == DSO_BINARY_TYPE__KALLSYMS)
94 tev->point.offset += PPC64LE_LEP_OFFSET;
95 else if (lep_offset) {
97 tev->point.address += lep_offset;
99 tev->point.offset += lep_offset;
103 #ifdef HAVE_LIBELF_SUPPORT
104 void arch__post_process_probe_trace_events(struct perf_probe_event *pev,
107 struct probe_trace_event *tev;
109 struct symbol *sym = NULL;
113 map = get_target_map(pev->target, pev->uprobes);
114 if (!map || map__load(map) < 0)
117 for (i = 0; i < ntevs; i++) {
119 map__for_each_symbol(map, sym, tmp) {
120 if (map->unmap_ip(map, sym->start) == tev->point.address) {
121 arch__fix_tev_from_maps(pev, tev, map, sym);
127 #endif /* HAVE_LIBELF_SUPPORT */