#include <inttypes.h>
#include <regex.h>
#include <stdlib.h>
+#include <string.h>
#include "callchain.h"
#include "debug.h"
#include "dso.h"
{
struct symbol *sym;
struct dso *dso = NULL;
- struct map *map = maps__find(machine__kernel_maps(machine), event->ksymbol.addr);
+ struct map *map;
int err = 0;
+ /* Ignore mapping symbols in ksymbol events - check early before any state mutation */
+ if (is_ignored_kernel_symbol(event->ksymbol.name))
+ return 0;
+
+ map = maps__find(machine__kernel_maps(machine), event->ksymbol.addr);
+
if (!map) {
dso = dso__new(event->ksymbol.name);
struct symbol *sym;
struct map *map;
+ /* Ignore mapping symbols in ksymbol events */
+ if (is_ignored_kernel_symbol(event->ksymbol.name))
+ return 0;
+
map = maps__find(machine__kernel_maps(machine), event->ksymbol.addr);
if (!map)
return 0;
if (dump_trace)
perf_event__fprintf_ksymbol(event, stdout);
+ if (event->header.size < offsetof(struct perf_record_ksymbol, name) + 2 ||
+ !memchr(event->ksymbol.name, '\0',
+ event->header.size - offsetof(struct perf_record_ksymbol, name)))
+ return -EINVAL;
+
/* no need to process non-JIT BPF as it cannot get samples */
if (event->ksymbol.len == 0)
return 0;
if (!symbol_type__filter(type))
return 0;
- /* Ignore local symbols for ARM modules */
- if (name[0] == '$')
+ /* Ignore mapping symbols in kallsyms */
+ if (is_ignored_kernel_symbol(name))
return 0;
/*
struct option;
struct build_id;
+/*
+ * Ignore kernel mapping symbols, matching kernel is_mapping_symbol() logic.
+ * This checks for '$' prefix (used by ARM, AArch64, RISC-V) and
+ * x86 local symbol prefixes (.L* and L0*).
+ * Only use this for kernel symbols (kallsyms, ksymbol events, kernel ELF DSOs).
+ */
+static inline bool is_ignored_kernel_symbol(const char *str)
+{
+ if (str[0] == '.' && str[1] == 'L')
+ return true;
+ if (str[0] == 'L' && str[1] == '0')
+ return true;
+ return str[0] == '$';
+}
+
/*
* libelf 0.8.x and earlier do not support ELF_C_READ_MMAP;
* for newer versions we can use mmap to reduce memory usage: