#define BPF_FS_MAGIC           0xcafe4a11
 #endif
 
+#define MAX_EVENT_NAME_LEN     64
+
 #define BPF_FS_DEFAULT_PATH "/sys/fs/bpf"
 
 #define BPF_INSN_SZ (sizeof(struct bpf_insn))
                             : TRACEFS"/available_filter_functions_addrs";
 }
 
-static void gen_kprobe_legacy_event_name(char *buf, size_t buf_sz,
-                                        const char *kfunc_name, size_t offset)
+static void gen_probe_legacy_event_name(char *buf, size_t buf_sz,
+                                       const char *name, size_t offset)
 {
        static int index = 0;
        int i;
 
-       snprintf(buf, buf_sz, "libbpf_%u_%s_0x%zx_%d", getpid(), kfunc_name, offset,
-                __sync_fetch_and_add(&index, 1));
+       snprintf(buf, buf_sz, "libbpf_%u_%d_%s_0x%zx", getpid(),
+                __sync_fetch_and_add(&index, 1), name, offset);
 
-       /* sanitize binary_path in the probe name */
+       /* sanitize name in the probe name */
        for (i = 0; buf[i]; i++) {
                if (!isalnum(buf[i]))
                        buf[i] = '_';
 
                return pfd >= 0 ? 1 : 0;
        } else { /* legacy mode */
-               char probe_name[128];
+               char probe_name[MAX_EVENT_NAME_LEN];
 
-               gen_kprobe_legacy_event_name(probe_name, sizeof(probe_name), syscall_name, 0);
+               gen_probe_legacy_event_name(probe_name, sizeof(probe_name), syscall_name, 0);
                if (add_kprobe_event_legacy(probe_name, false, syscall_name, 0) < 0)
                        return 0;
 
                                            func_name, offset,
                                            -1 /* pid */, 0 /* ref_ctr_off */);
        } else {
-               char probe_name[256];
+               char probe_name[MAX_EVENT_NAME_LEN];
 
-               gen_kprobe_legacy_event_name(probe_name, sizeof(probe_name),
-                                            func_name, offset);
+               gen_probe_legacy_event_name(probe_name, sizeof(probe_name),
+                                           func_name, offset);
 
                legacy_probe = strdup(probe_name);
                if (!legacy_probe)
        return ret;
 }
 
-static void gen_uprobe_legacy_event_name(char *buf, size_t buf_sz,
-                                        const char *binary_path, uint64_t offset)
-{
-       int i;
-
-       snprintf(buf, buf_sz, "libbpf_%u_%s_0x%zx", getpid(), binary_path, (size_t)offset);
-
-       /* sanitize binary_path in the probe name */
-       for (i = 0; buf[i]; i++) {
-               if (!isalnum(buf[i]))
-                       buf[i] = '_';
-       }
-}
-
 static inline int add_uprobe_event_legacy(const char *probe_name, bool retprobe,
                                          const char *binary_path, size_t offset)
 {
                pfd = perf_event_open_probe(true /* uprobe */, retprobe, binary_path,
                                            func_offset, pid, ref_ctr_off);
        } else {
-               char probe_name[PATH_MAX + 64];
+               char probe_name[MAX_EVENT_NAME_LEN];
 
                if (ref_ctr_off)
                        return libbpf_err_ptr(-EINVAL);
 
-               gen_uprobe_legacy_event_name(probe_name, sizeof(probe_name),
-                                            binary_path, func_offset);
+               gen_probe_legacy_event_name(probe_name, sizeof(probe_name),
+                                           strrchr(binary_path, '/') ? : binary_path,
+                                           func_offset);
 
                legacy_probe = strdup(probe_name);
                if (!legacy_probe)