Path: blob/master/tools/perf/arch/powerpc/util/sym-handling.c
29274 views
// SPDX-License-Identifier: GPL-2.0-only1/*2*3* Copyright (C) 2015 Naveen N. Rao, IBM Corporation4*/56#include "dso.h"7#include "symbol.h"8#include "map.h"9#include "probe-event.h"10#include "probe-file.h"1112int arch__choose_best_symbol(struct symbol *syma,13struct symbol *symb __maybe_unused)14{15char *sym = syma->name;1617#if !defined(_CALL_ELF) || _CALL_ELF != 218/* Skip over any initial dot */19if (*sym == '.')20sym++;21#endif2223/* Avoid "SyS" kernel syscall aliases */24if (strlen(sym) >= 3 && !strncmp(sym, "SyS", 3))25return SYMBOL_B;26if (strlen(sym) >= 10 && !strncmp(sym, "compat_SyS", 10))27return SYMBOL_B;2829return SYMBOL_A;30}3132#if !defined(_CALL_ELF) || _CALL_ELF != 233/* Allow matching against dot variants */34int arch__compare_symbol_names(const char *namea, const char *nameb)35{36/* Skip over initial dot */37if (*namea == '.')38namea++;39if (*nameb == '.')40nameb++;4142return strcmp(namea, nameb);43}4445int arch__compare_symbol_names_n(const char *namea, const char *nameb,46unsigned int n)47{48/* Skip over initial dot */49if (*namea == '.')50namea++;51if (*nameb == '.')52nameb++;5354return strncmp(namea, nameb, n);55}5657const char *arch__normalize_symbol_name(const char *name)58{59/* Skip over initial dot */60if (name && *name == '.')61name++;62return name;63}64#endif6566#if defined(_CALL_ELF) && _CALL_ELF == 26768#ifdef HAVE_LIBELF_SUPPORT69void arch__sym_update(struct symbol *s, GElf_Sym *sym)70{71s->arch_sym = sym->st_other;72}73#endif7475#define PPC64LE_LEP_OFFSET 87677void arch__fix_tev_from_maps(struct perf_probe_event *pev,78struct probe_trace_event *tev, struct map *map,79struct symbol *sym)80{81int lep_offset;8283/*84* When probing at a function entry point, we normally always want the85* LEP since that catches calls to the function through both the GEP and86* the LEP. Hence, we would like to probe at an offset of 8 bytes if87* the user only specified the function entry.88*89* However, if the user specifies an offset, we fall back to using the90* GEP since all userspace applications (objdump/readelf) show function91* disassembly with offsets from the GEP.92*/93if (pev->point.offset || !map || !sym)94return;9596/* For kretprobes, add an offset only if the kernel supports it */97if (!pev->uprobes && pev->point.retprobe) {98#ifdef HAVE_LIBELF_SUPPORT99if (!kretprobe_offset_is_supported())100#endif101return;102}103104lep_offset = PPC64_LOCAL_ENTRY_OFFSET(sym->arch_sym);105106if (map__dso(map)->symtab_type == DSO_BINARY_TYPE__KALLSYMS)107tev->point.offset += PPC64LE_LEP_OFFSET;108else if (lep_offset) {109if (pev->uprobes)110tev->point.address += lep_offset;111else112tev->point.offset += lep_offset;113}114}115116#ifdef HAVE_LIBELF_SUPPORT117void arch__post_process_probe_trace_events(struct perf_probe_event *pev,118int ntevs)119{120struct probe_trace_event *tev;121struct map *map;122struct symbol *sym = NULL;123struct rb_node *tmp;124int i = 0;125126map = get_target_map(pev->target, pev->nsi, pev->uprobes);127if (!map || map__load(map) < 0)128return;129130for (i = 0; i < ntevs; i++) {131tev = &pev->tevs[i];132map__for_each_symbol(map, sym, tmp) {133if (map__unmap_ip(map, sym->start) == tev->point.address) {134arch__fix_tev_from_maps(pev, tev, map, sym);135break;136}137}138}139}140#endif /* HAVE_LIBELF_SUPPORT */141142#endif143144145