Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  *
0004  * Copyright (C) 2015 Naveen N. Rao, IBM Corporation
0005  */
0006 
0007 #include "dso.h"
0008 #include "symbol.h"
0009 #include "map.h"
0010 #include "probe-event.h"
0011 #include "probe-file.h"
0012 
0013 int arch__choose_best_symbol(struct symbol *syma,
0014                  struct symbol *symb __maybe_unused)
0015 {
0016     char *sym = syma->name;
0017 
0018 #if !defined(_CALL_ELF) || _CALL_ELF != 2
0019     /* Skip over any initial dot */
0020     if (*sym == '.')
0021         sym++;
0022 #endif
0023 
0024     /* Avoid "SyS" kernel syscall aliases */
0025     if (strlen(sym) >= 3 && !strncmp(sym, "SyS", 3))
0026         return SYMBOL_B;
0027     if (strlen(sym) >= 10 && !strncmp(sym, "compat_SyS", 10))
0028         return SYMBOL_B;
0029 
0030     return SYMBOL_A;
0031 }
0032 
0033 #if !defined(_CALL_ELF) || _CALL_ELF != 2
0034 /* Allow matching against dot variants */
0035 int arch__compare_symbol_names(const char *namea, const char *nameb)
0036 {
0037     /* Skip over initial dot */
0038     if (*namea == '.')
0039         namea++;
0040     if (*nameb == '.')
0041         nameb++;
0042 
0043     return strcmp(namea, nameb);
0044 }
0045 
0046 int arch__compare_symbol_names_n(const char *namea, const char *nameb,
0047                  unsigned int n)
0048 {
0049     /* Skip over initial dot */
0050     if (*namea == '.')
0051         namea++;
0052     if (*nameb == '.')
0053         nameb++;
0054 
0055     return strncmp(namea, nameb, n);
0056 }
0057 
0058 const char *arch__normalize_symbol_name(const char *name)
0059 {
0060     /* Skip over initial dot */
0061     if (name && *name == '.')
0062         name++;
0063     return name;
0064 }
0065 #endif
0066 
0067 #if defined(_CALL_ELF) && _CALL_ELF == 2
0068 
0069 #ifdef HAVE_LIBELF_SUPPORT
0070 void arch__sym_update(struct symbol *s, GElf_Sym *sym)
0071 {
0072     s->arch_sym = sym->st_other;
0073 }
0074 #endif
0075 
0076 #define PPC64LE_LEP_OFFSET  8
0077 
0078 void arch__fix_tev_from_maps(struct perf_probe_event *pev,
0079                  struct probe_trace_event *tev, struct map *map,
0080                  struct symbol *sym)
0081 {
0082     int lep_offset;
0083 
0084     /*
0085      * When probing at a function entry point, we normally always want the
0086      * LEP since that catches calls to the function through both the GEP and
0087      * the LEP. Hence, we would like to probe at an offset of 8 bytes if
0088      * the user only specified the function entry.
0089      *
0090      * However, if the user specifies an offset, we fall back to using the
0091      * GEP since all userspace applications (objdump/readelf) show function
0092      * disassembly with offsets from the GEP.
0093      */
0094     if (pev->point.offset || !map || !sym)
0095         return;
0096 
0097     /* For kretprobes, add an offset only if the kernel supports it */
0098     if (!pev->uprobes && pev->point.retprobe) {
0099 #ifdef HAVE_LIBELF_SUPPORT
0100         if (!kretprobe_offset_is_supported())
0101 #endif
0102             return;
0103     }
0104 
0105     lep_offset = PPC64_LOCAL_ENTRY_OFFSET(sym->arch_sym);
0106 
0107     if (map->dso->symtab_type == DSO_BINARY_TYPE__KALLSYMS)
0108         tev->point.offset += PPC64LE_LEP_OFFSET;
0109     else if (lep_offset) {
0110         if (pev->uprobes)
0111             tev->point.address += lep_offset;
0112         else
0113             tev->point.offset += lep_offset;
0114     }
0115 }
0116 
0117 #ifdef HAVE_LIBELF_SUPPORT
0118 void arch__post_process_probe_trace_events(struct perf_probe_event *pev,
0119                        int ntevs)
0120 {
0121     struct probe_trace_event *tev;
0122     struct map *map;
0123     struct symbol *sym = NULL;
0124     struct rb_node *tmp;
0125     int i = 0;
0126 
0127     map = get_target_map(pev->target, pev->nsi, pev->uprobes);
0128     if (!map || map__load(map) < 0)
0129         return;
0130 
0131     for (i = 0; i < ntevs; i++) {
0132         tev = &pev->tevs[i];
0133         map__for_each_symbol(map, sym, tmp) {
0134             if (map->unmap_ip(map, sym->start) == tev->point.address) {
0135                 arch__fix_tev_from_maps(pev, tev, map, sym);
0136                 break;
0137             }
0138         }
0139     }
0140 }
0141 #endif /* HAVE_LIBELF_SUPPORT */
0142 
0143 #endif