Linux Perf
sym-handling.c
Go to the documentation of this file.
1 /*
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"
11 #include "map.h"
12 #include "probe-event.h"
13 #include "probe-file.h"
14 
15 #ifdef HAVE_LIBELF_SUPPORT
16 bool elf__needs_adjust_symbols(GElf_Ehdr ehdr)
17 {
18  return ehdr.e_type == ET_EXEC ||
19  ehdr.e_type == ET_REL ||
20  ehdr.e_type == ET_DYN;
21 }
22 
23 #endif
24 
25 #if !defined(_CALL_ELF) || _CALL_ELF != 2
27  struct symbol *symb __maybe_unused)
28 {
29  char *sym = syma->name;
30 
31  /* Skip over any initial dot */
32  if (*sym == '.')
33  sym++;
34 
35  /* Avoid "SyS" kernel syscall aliases */
36  if (strlen(sym) >= 3 && !strncmp(sym, "SyS", 3))
37  return SYMBOL_B;
38  if (strlen(sym) >= 10 && !strncmp(sym, "compat_SyS", 10))
39  return SYMBOL_B;
40 
41  return SYMBOL_A;
42 }
43 
44 /* Allow matching against dot variants */
45 int arch__compare_symbol_names(const char *namea, const char *nameb)
46 {
47  /* Skip over initial dot */
48  if (*namea == '.')
49  namea++;
50  if (*nameb == '.')
51  nameb++;
52 
53  return strcmp(namea, nameb);
54 }
55 
56 int arch__compare_symbol_names_n(const char *namea, const char *nameb,
57  unsigned int n)
58 {
59  /* Skip over initial dot */
60  if (*namea == '.')
61  namea++;
62  if (*nameb == '.')
63  nameb++;
64 
65  return strncmp(namea, nameb, n);
66 }
67 
68 const char *arch__normalize_symbol_name(const char *name)
69 {
70  /* Skip over initial dot */
71  if (name && *name == '.')
72  name++;
73  return name;
74 }
75 #endif
76 
77 #if defined(_CALL_ELF) && _CALL_ELF == 2
78 
79 #ifdef HAVE_LIBELF_SUPPORT
80 void arch__sym_update(struct symbol *s, GElf_Sym *sym)
81 {
82  s->arch_sym = sym->st_other;
83 }
84 #endif
85 
86 #define PPC64LE_LEP_OFFSET 8
87 
89  struct probe_trace_event *tev, struct map *map,
90  struct symbol *sym)
91 {
92  int lep_offset;
93 
94  /*
95  * When probing at a function entry point, we normally always want the
96  * LEP since that catches calls to the function through both the GEP and
97  * the LEP. Hence, we would like to probe at an offset of 8 bytes if
98  * the user only specified the function entry.
99  *
100  * However, if the user specifies an offset, we fall back to using the
101  * GEP since all userspace applications (objdump/readelf) show function
102  * disassembly with offsets from the GEP.
103  */
104  if (pev->point.offset || !map || !sym)
105  return;
106 
107  /* For kretprobes, add an offset only if the kernel supports it */
108  if (!pev->uprobes && pev->point.retprobe) {
109 #ifdef HAVE_LIBELF_SUPPORT
111 #endif
112  return;
113  }
114 
115  lep_offset = PPC64_LOCAL_ENTRY_OFFSET(sym->arch_sym);
116 
118  tev->point.offset += PPC64LE_LEP_OFFSET;
119  else if (lep_offset) {
120  if (pev->uprobes)
121  tev->point.address += lep_offset;
122  else
123  tev->point.offset += lep_offset;
124  }
125 }
126 
127 #ifdef HAVE_LIBELF_SUPPORT
129  int ntevs)
130 {
131  struct probe_trace_event *tev;
132  struct map *map;
133  struct symbol *sym = NULL;
134  struct rb_node *tmp;
135  int i = 0;
136 
137  map = get_target_map(pev->target, pev->nsi, pev->uprobes);
138  if (!map || map__load(map) < 0)
139  return;
140 
141  for (i = 0; i < ntevs; i++) {
142  tev = &pev->tevs[i];
143  map__for_each_symbol(map, sym, tmp) {
144  if (map->unmap_ip(map, sym->start) == tev->point.address)
145  arch__fix_tev_from_maps(pev, tev, map, sym);
146  }
147  }
148 }
149 #endif /* HAVE_LIBELF_SUPPORT */
150 
151 #endif
struct probe_trace_point point
Definition: probe-event.h:52
unsigned long offset
Definition: probe-event.h:65
#define map__for_each_symbol(map, pos, n)
Definition: map.h:122
unsigned long address
Definition: probe-event.h:30
struct perf_probe_point point
Definition: probe-event.h:89
#define SYMBOL_A
Definition: symbol.h:349
void __weak arch__sym_update(struct symbol *s __maybe_unused, GElf_Sym *sym __maybe_unused)
Definition: symbol-elf.c:797
bool kretprobe_offset_is_supported(void)
Definition: probe-file.c:1063
struct probe_trace_event * tevs
Definition: probe-event.h:95
#define SYMBOL_B
Definition: symbol.h:350
const char * name
bool __weak elf__needs_adjust_symbols(GElf_Ehdr ehdr)
Definition: symbol-elf.c:661
u64 start
Definition: symbol.h:57
struct dso * dso
Definition: map.h:45
char name[0]
Definition: symbol.h:66
void __weak arch__fix_tev_from_maps(struct perf_probe_event *pev __maybe_unused, struct probe_trace_event *tev __maybe_unused, struct map *map __maybe_unused, struct symbol *sym __maybe_unused)
Definition: probe-event.c:2834
void arch__post_process_probe_trace_events(struct perf_probe_event *pev, int ntevs)
Definition: jevents.c:228
struct map * get_target_map(const char *target, struct nsinfo *nsi, bool user)
Definition: probe-event.c:174
static int sym(yyscan_t scanner, int type, int config)
u8 arch_sym
Definition: symbol.h:65
int arch__choose_best_symbol(struct symbol *syma, struct symbol *symb __maybe_unused)
Definition: sym-handling.c:26
unsigned long offset
Definition: probe-event.h:29
const char * arch__normalize_symbol_name(const char *name)
Definition: sym-handling.c:68
enum dso_binary_type symtab_type
Definition: dso.h:156
u64(* unmap_ip)(struct map *, u64)
Definition: map.h:43
Definition: symbol.h:55
int arch__compare_symbol_names(const char *namea, const char *nameb)
Definition: sym-handling.c:45
int arch__compare_symbol_names_n(const char *namea, const char *nameb, unsigned int n)
Definition: sym-handling.c:56
int map__load(struct map *map)
Definition: map.c:307
struct nsinfo * nsi
Definition: probe-event.h:97