@@ -175,6 +175,7 @@ TPROGS_CFLAGS += -I$(srctree)/tools/testing/selftests/bpf/
TPROGS_CFLAGS += -I$(LIBBPF_INCLUDE)
TPROGS_CFLAGS += -I$(srctree)/tools/include
TPROGS_CFLAGS += -I$(srctree)/tools/perf
+TPROGS_CFLAGS += -I$(srctree)/tools/lib
TPROGS_CFLAGS += -DHAVE_ATTR_TEST=0
ifdef SYSROOT
@@ -314,6 +315,7 @@ XDP_SAMPLE_CFLAGS += -Wall -O2 \
$(obj)/$(XDP_SAMPLE): TPROGS_CFLAGS = $(XDP_SAMPLE_CFLAGS)
$(obj)/$(XDP_SAMPLE): $(src)/xdp_sample_user.h $(src)/xdp_sample_shared.h
+$(obj)/$(TRACE_HELPERS): TPROGS_CFLAGS := $(TPROGS_CFLAGS) -D__must_check=
-include $(BPF_SAMPLES_PATH)/Makefile.target
@@ -14,13 +14,44 @@
#include <linux/limits.h>
#include <libelf.h>
#include <gelf.h>
+#include "bpf/libbpf_internal.h"
#define TRACEFS_PIPE "/sys/kernel/tracing/trace_pipe"
#define DEBUGFS_PIPE "/sys/kernel/debug/tracing/trace_pipe"
-#define MAX_SYMS 400000
-static struct ksym syms[MAX_SYMS];
-static int sym_cnt;
+static struct ksym *syms;
+static size_t sym_cap;
+static size_t sym_cnt;
+
+static int ksyms__add_symbol(const char *name, unsigned long addr)
+{
+ void *tmp;
+
+ tmp = strdup(name);
+ if (!tmp)
+ return -ENOMEM;
+ syms[sym_cnt].addr = addr;
+ syms[sym_cnt].name = tmp;
+
+ sym_cnt++;
+
+ return 0;
+}
+
+static void ksyms__free(void)
+{
+ unsigned int i;
+
+ if (!syms)
+ return;
+
+ for (i = 0; i < sym_cnt; i++)
+ free(syms[i].name);
+ free(syms);
+ syms = NULL;
+ sym_cnt = 0;
+ sym_cap = 0;
+}
static int ksym_cmp(const void *p1, const void *p2)
{
@@ -33,9 +64,7 @@ int load_kallsyms_refresh(void)
char func[256], buf[256];
char symbol;
void *addr;
- int i = 0;
-
- sym_cnt = 0;
+ int ret;
f = fopen("/proc/kallsyms", "r");
if (!f)
@@ -46,17 +75,22 @@ int load_kallsyms_refresh(void)
break;
if (!addr)
continue;
- if (i >= MAX_SYMS)
- return -EFBIG;
- syms[i].addr = (long) addr;
- syms[i].name = strdup(func);
- i++;
+ ret = libbpf_ensure_mem((void **) &syms, &sym_cap,
+ sizeof(struct ksym), sym_cnt + 1);
+ if (ret)
+ goto error;
+ ret = ksyms__add_symbol(func, (unsigned long)addr);
+ if (ret)
+ goto error;
}
fclose(f);
- sym_cnt = i;
qsort(syms, sym_cnt, sizeof(struct ksym), ksym_cmp);
return 0;
+
+error:
+ ksyms__free();
+ return ret;
}
int load_kallsyms(void)