blob: 1030a6e504bb9fe2a8f7eca185a419332613d924 [file] [log] [blame]
Naveen N. Raod2332092015-04-28 17:35:35 +05301/*
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.
5 *
6 * Copyright (C) 2015 Naveen N. Rao, IBM Corporation
7 */
8
9#include "debug.h"
10#include "symbol.h"
Naveen N. Rao031b84c2015-04-28 17:35:37 +053011#include "map.h"
Naveen N. Raod5c2e2c2015-04-28 17:35:39 +053012#include "probe-event.h"
Naveen N. Raod2332092015-04-28 17:35:35 +053013
14#ifdef HAVE_LIBELF_SUPPORT
15bool elf__needs_adjust_symbols(GElf_Ehdr ehdr)
16{
17 return ehdr.e_type == ET_EXEC ||
18 ehdr.e_type == ET_REL ||
19 ehdr.e_type == ET_DYN;
20}
Ananth N Mavinakayanahallic50fc0a2015-04-28 17:35:38 +053021
Naveen N. Raod2332092015-04-28 17:35:35 +053022#endif
Naveen N. Raofb6d5942015-04-28 17:35:36 +053023
24#if !defined(_CALL_ELF) || _CALL_ELF != 2
25int arch__choose_best_symbol(struct symbol *syma,
26 struct symbol *symb __maybe_unused)
27{
28 char *sym = syma->name;
29
30 /* Skip over any initial dot */
31 if (*sym == '.')
32 sym++;
33
34 /* Avoid "SyS" kernel syscall aliases */
35 if (strlen(sym) >= 3 && !strncmp(sym, "SyS", 3))
36 return SYMBOL_B;
37 if (strlen(sym) >= 10 && !strncmp(sym, "compat_SyS", 10))
38 return SYMBOL_B;
39
40 return SYMBOL_A;
41}
Naveen N. Rao031b84c2015-04-28 17:35:37 +053042
43/* Allow matching against dot variants */
44int arch__compare_symbol_names(const char *namea, const char *nameb)
45{
46 /* Skip over initial dot */
47 if (*namea == '.')
48 namea++;
49 if (*nameb == '.')
50 nameb++;
51
52 return strcmp(namea, nameb);
53}
Naveen N. Raofb6d5942015-04-28 17:35:36 +053054#endif
Naveen N. Raod5c2e2c2015-04-28 17:35:39 +053055
56#if defined(_CALL_ELF) && _CALL_ELF == 2
Naveen N. Rao7b6ff0b2015-04-28 17:35:40 +053057
Naveen N. Rao0b3c2262016-04-12 14:40:50 +053058#ifdef HAVE_LIBELF_SUPPORT
59void arch__sym_update(struct symbol *s, GElf_Sym *sym)
60{
61 s->arch_sym = sym->st_other;
62}
63#endif
64
Naveen N. Rao7b6ff0b2015-04-28 17:35:40 +053065#define PPC64LE_LEP_OFFSET 8
66
67void arch__fix_tev_from_maps(struct perf_probe_event *pev,
Naveen N. Rao0b3c2262016-04-12 14:40:50 +053068 struct probe_trace_event *tev, struct map *map,
69 struct symbol *sym)
Naveen N. Rao7b6ff0b2015-04-28 17:35:40 +053070{
Naveen N. Rao0b3c2262016-04-12 14:40:50 +053071 int lep_offset;
72
Naveen N. Rao7b6ff0b2015-04-28 17:35:40 +053073 /*
Naveen N. Rao239aeba2016-04-12 14:40:49 +053074 * When probing at a function entry point, we normally always want the
75 * LEP since that catches calls to the function through both the GEP and
76 * the LEP. Hence, we would like to probe at an offset of 8 bytes if
77 * the user only specified the function entry.
78 *
79 * However, if the user specifies an offset, we fall back to using the
80 * GEP since all userspace applications (objdump/readelf) show function
81 * disassembly with offsets from the GEP.
82 *
83 * In addition, we shouldn't specify an offset for kretprobes.
Naveen N. Rao7b6ff0b2015-04-28 17:35:40 +053084 */
Ravi Bangoriaa1d99722016-10-04 15:57:45 +053085 if (pev->point.offset || (!pev->uprobes && pev->point.retprobe) ||
86 !map || !sym)
Naveen N. Rao239aeba2016-04-12 14:40:49 +053087 return;
88
Naveen N. Rao0b3c2262016-04-12 14:40:50 +053089 lep_offset = PPC64_LOCAL_ENTRY_OFFSET(sym->arch_sym);
90
Naveen N. Rao239aeba2016-04-12 14:40:49 +053091 if (map->dso->symtab_type == DSO_BINARY_TYPE__KALLSYMS)
Naveen N. Rao7b6ff0b2015-04-28 17:35:40 +053092 tev->point.offset += PPC64LE_LEP_OFFSET;
Naveen N. Rao0b3c2262016-04-12 14:40:50 +053093 else if (lep_offset) {
94 if (pev->uprobes)
95 tev->point.address += lep_offset;
96 else
97 tev->point.offset += lep_offset;
98 }
Naveen N. Rao7b6ff0b2015-04-28 17:35:40 +053099}
Ravi Bangoria99e608b2016-08-09 01:23:25 -0500100
Ravi Bangoriaf046f3d2016-08-11 14:43:59 -0300101#ifdef HAVE_LIBELF_SUPPORT
Ravi Bangoria99e608b2016-08-09 01:23:25 -0500102void arch__post_process_probe_trace_events(struct perf_probe_event *pev,
103 int ntevs)
104{
105 struct probe_trace_event *tev;
106 struct map *map;
107 struct symbol *sym = NULL;
108 struct rb_node *tmp;
109 int i = 0;
110
111 map = get_target_map(pev->target, pev->uprobes);
Arnaldo Carvalho de Melobe39db92016-09-01 19:25:52 -0300112 if (!map || map__load(map) < 0)
Ravi Bangoria99e608b2016-08-09 01:23:25 -0500113 return;
114
115 for (i = 0; i < ntevs; i++) {
116 tev = &pev->tevs[i];
117 map__for_each_symbol(map, sym, tmp) {
118 if (map->unmap_ip(map, sym->start) == tev->point.address)
119 arch__fix_tev_from_maps(pev, tev, map, sym);
120 }
121 }
122}
Ravi Bangoriaf046f3d2016-08-11 14:43:59 -0300123#endif /* HAVE_LIBELF_SUPPORT */
Ravi Bangoria99e608b2016-08-09 01:23:25 -0500124
Naveen N. Raod5c2e2c2015-04-28 17:35:39 +0530125#endif