blob: c6d0f91731a14732333af62d0a40a3ea43fb4c99 [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
57bool arch__prefers_symtab(void)
58{
59 return true;
60}
Naveen N. Rao7b6ff0b2015-04-28 17:35:40 +053061
Naveen N. Rao0b3c2262016-04-12 14:40:50 +053062#ifdef HAVE_LIBELF_SUPPORT
63void arch__sym_update(struct symbol *s, GElf_Sym *sym)
64{
65 s->arch_sym = sym->st_other;
66}
67#endif
68
Naveen N. Rao7b6ff0b2015-04-28 17:35:40 +053069#define PPC64LE_LEP_OFFSET 8
70
71void arch__fix_tev_from_maps(struct perf_probe_event *pev,
Naveen N. Rao0b3c2262016-04-12 14:40:50 +053072 struct probe_trace_event *tev, struct map *map,
73 struct symbol *sym)
Naveen N. Rao7b6ff0b2015-04-28 17:35:40 +053074{
Naveen N. Rao0b3c2262016-04-12 14:40:50 +053075 int lep_offset;
76
Naveen N. Rao7b6ff0b2015-04-28 17:35:40 +053077 /*
Naveen N. Rao239aeba2016-04-12 14:40:49 +053078 * When probing at a function entry point, we normally always want the
79 * LEP since that catches calls to the function through both the GEP and
80 * the LEP. Hence, we would like to probe at an offset of 8 bytes if
81 * the user only specified the function entry.
82 *
83 * However, if the user specifies an offset, we fall back to using the
84 * GEP since all userspace applications (objdump/readelf) show function
85 * disassembly with offsets from the GEP.
86 *
87 * In addition, we shouldn't specify an offset for kretprobes.
Naveen N. Rao7b6ff0b2015-04-28 17:35:40 +053088 */
Naveen N. Rao0b3c2262016-04-12 14:40:50 +053089 if (pev->point.offset || pev->point.retprobe || !map || !sym)
Naveen N. Rao239aeba2016-04-12 14:40:49 +053090 return;
91
Naveen N. Rao0b3c2262016-04-12 14:40:50 +053092 lep_offset = PPC64_LOCAL_ENTRY_OFFSET(sym->arch_sym);
93
Naveen N. Rao239aeba2016-04-12 14:40:49 +053094 if (map->dso->symtab_type == DSO_BINARY_TYPE__KALLSYMS)
Naveen N. Rao7b6ff0b2015-04-28 17:35:40 +053095 tev->point.offset += PPC64LE_LEP_OFFSET;
Naveen N. Rao0b3c2262016-04-12 14:40:50 +053096 else if (lep_offset) {
97 if (pev->uprobes)
98 tev->point.address += lep_offset;
99 else
100 tev->point.offset += lep_offset;
101 }
Naveen N. Rao7b6ff0b2015-04-28 17:35:40 +0530102}
Naveen N. Raod5c2e2c2015-04-28 17:35:39 +0530103#endif