sym-handling.c 3.0 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License, version 2, as
 * published by the Free Software Foundation.
 *
 * Copyright (C) 2015 Naveen N. Rao, IBM Corporation
 */

#include "debug.h"
#include "symbol.h"
11
#include "map.h"
12
#include "probe-event.h"
13 14 15 16 17 18 19 20

#ifdef HAVE_LIBELF_SUPPORT
bool elf__needs_adjust_symbols(GElf_Ehdr ehdr)
{
	return ehdr.e_type == ET_EXEC ||
	       ehdr.e_type == ET_REL ||
	       ehdr.e_type == ET_DYN;
}
21

22
#endif
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41

#if !defined(_CALL_ELF) || _CALL_ELF != 2
int arch__choose_best_symbol(struct symbol *syma,
			     struct symbol *symb __maybe_unused)
{
	char *sym = syma->name;

	/* Skip over any initial dot */
	if (*sym == '.')
		sym++;

	/* Avoid "SyS" kernel syscall aliases */
	if (strlen(sym) >= 3 && !strncmp(sym, "SyS", 3))
		return SYMBOL_B;
	if (strlen(sym) >= 10 && !strncmp(sym, "compat_SyS", 10))
		return SYMBOL_B;

	return SYMBOL_A;
}
42 43 44 45 46 47 48 49 50 51 52 53

/* Allow matching against dot variants */
int arch__compare_symbol_names(const char *namea, const char *nameb)
{
	/* Skip over initial dot */
	if (*namea == '.')
		namea++;
	if (*nameb == '.')
		nameb++;

	return strcmp(namea, nameb);
}
54
#endif
55 56

#if defined(_CALL_ELF) && _CALL_ELF == 2
57

58 59 60 61 62 63 64
#ifdef HAVE_LIBELF_SUPPORT
void arch__sym_update(struct symbol *s, GElf_Sym *sym)
{
	s->arch_sym = sym->st_other;
}
#endif

65 66 67
#define PPC64LE_LEP_OFFSET	8

void arch__fix_tev_from_maps(struct perf_probe_event *pev,
68 69
			     struct probe_trace_event *tev, struct map *map,
			     struct symbol *sym)
70
{
71 72
	int lep_offset;

73
	/*
74 75 76 77 78 79 80 81 82 83
	 * When probing at a function entry point, we normally always want the
	 * LEP since that catches calls to the function through both the GEP and
	 * the LEP. Hence, we would like to probe at an offset of 8 bytes if
	 * the user only specified the function entry.
	 *
	 * However, if the user specifies an offset, we fall back to using the
	 * GEP since all userspace applications (objdump/readelf) show function
	 * disassembly with offsets from the GEP.
	 *
	 * In addition, we shouldn't specify an offset for kretprobes.
84
	 */
85
	if (pev->point.offset || pev->point.retprobe || !map || !sym)
86 87
		return;

88 89
	lep_offset = PPC64_LOCAL_ENTRY_OFFSET(sym->arch_sym);

90
	if (map->dso->symtab_type == DSO_BINARY_TYPE__KALLSYMS)
91
		tev->point.offset += PPC64LE_LEP_OFFSET;
92 93 94 95 96 97
	else if (lep_offset) {
		if (pev->uprobes)
			tev->point.address += lep_offset;
		else
			tev->point.offset += lep_offset;
	}
98
}
99

100
#ifdef HAVE_LIBELF_SUPPORT
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
void arch__post_process_probe_trace_events(struct perf_probe_event *pev,
					   int ntevs)
{
	struct probe_trace_event *tev;
	struct map *map;
	struct symbol *sym = NULL;
	struct rb_node *tmp;
	int i = 0;

	map = get_target_map(pev->target, pev->uprobes);
	if (!map || map__load(map, NULL) < 0)
		return;

	for (i = 0; i < ntevs; i++) {
		tev = &pev->tevs[i];
		map__for_each_symbol(map, sym, tmp) {
			if (map->unmap_ip(map, sym->start) == tev->point.address)
				arch__fix_tev_from_maps(pev, tev, map, sym);
		}
	}
}
122
#endif /* HAVE_LIBELF_SUPPORT */
123

124
#endif
新手
引导
客服 返回
顶部