summaryrefslogtreecommitdiff
path: root/tools/lib
diff options
context:
space:
mode:
authorAndrii Nakryiko <andrii@kernel.org>2025-10-01 10:13:24 -0700
committerAlexei Starovoitov <ast@kernel.org>2025-10-01 15:27:25 -0700
commitc68b6fdc3600466e3c265bad34d099eb8c5280f1 (patch)
treead84257239d9e3dc5e957f4ef511bb94d0fe33da /tools/lib
parentd05ab6181be0060ca259a49e69de9bc95b19edb7 (diff)
libbpf: move libbpf_errstr() into libbpf_utils.c
Get rid of str_err.{c,h} by moving implementation of libbpf_errstr() into libbpf_utils.c and declarations into libbpf_internal.h. Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/r/20251001171326.3883055-4-andrii@kernel.org Signed-off-by: Alexei Starovoitov <ast@kernel.org> Acked-by: Eduard Zingerman <eddyz87@gmail.com>
Diffstat (limited to 'tools/lib')
-rw-r--r--tools/lib/bpf/Build2
-rw-r--r--tools/lib/bpf/btf.c1
-rw-r--r--tools/lib/bpf/btf_dump.c1
-rw-r--r--tools/lib/bpf/elf.c1
-rw-r--r--tools/lib/bpf/features.c1
-rw-r--r--tools/lib/bpf/gen_loader.c3
-rw-r--r--tools/lib/bpf/libbpf.c1
-rw-r--r--tools/lib/bpf/libbpf_internal.h10
-rw-r--r--tools/lib/bpf/libbpf_utils.c72
-rw-r--r--tools/lib/bpf/linker.c1
-rw-r--r--tools/lib/bpf/relo_core.c1
-rw-r--r--tools/lib/bpf/ringbuf.c1
-rw-r--r--tools/lib/bpf/str_error.c80
-rw-r--r--tools/lib/bpf/str_error.h15
-rw-r--r--tools/lib/bpf/usdt.c1
15 files changed, 84 insertions, 107 deletions
diff --git a/tools/lib/bpf/Build b/tools/lib/bpf/Build
index c30927135fd6..c80204bb72a2 100644
--- a/tools/lib/bpf/Build
+++ b/tools/lib/bpf/Build
@@ -1,4 +1,4 @@
-libbpf-y := libbpf.o bpf.o nlattr.o btf.o libbpf_utils.o str_error.o \
+libbpf-y := libbpf.o bpf.o nlattr.o btf.o libbpf_utils.o \
netlink.o bpf_prog_linfo.o libbpf_probes.o hashmap.o \
btf_dump.o ringbuf.o strset.o linker.o gen_loader.o relo_core.o \
usdt.o zip.o elf.o features.o btf_iter.o btf_relocate.o
diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
index 37682908cb0f..18907f0fcf9f 100644
--- a/tools/lib/bpf/btf.c
+++ b/tools/lib/bpf/btf.c
@@ -23,7 +23,6 @@
#include "libbpf_internal.h"
#include "hashmap.h"
#include "strset.h"
-#include "str_error.h"
#define BTF_MAX_NR_TYPES 0x7fffffffU
#define BTF_MAX_STR_OFFSET 0x7fffffffU
diff --git a/tools/lib/bpf/btf_dump.c b/tools/lib/bpf/btf_dump.c
index f09f25eccf3c..6388392f49a0 100644
--- a/tools/lib/bpf/btf_dump.c
+++ b/tools/lib/bpf/btf_dump.c
@@ -21,7 +21,6 @@
#include "hashmap.h"
#include "libbpf.h"
#include "libbpf_internal.h"
-#include "str_error.h"
static const char PREFIXES[] = "\t\t\t\t\t\t\t\t\t\t\t\t\t";
static const size_t PREFIX_CNT = sizeof(PREFIXES) - 1;
diff --git a/tools/lib/bpf/elf.c b/tools/lib/bpf/elf.c
index 823f83ad819c..295dbda24580 100644
--- a/tools/lib/bpf/elf.c
+++ b/tools/lib/bpf/elf.c
@@ -9,7 +9,6 @@
#include <linux/kernel.h>
#include "libbpf_internal.h"
-#include "str_error.h"
/* A SHT_GNU_versym section holds 16-bit words. This bit is set if
* the symbol is hidden and can only be seen when referenced using an
diff --git a/tools/lib/bpf/features.c b/tools/lib/bpf/features.c
index 760657f5224c..b842b83e2480 100644
--- a/tools/lib/bpf/features.c
+++ b/tools/lib/bpf/features.c
@@ -6,7 +6,6 @@
#include "libbpf.h"
#include "libbpf_common.h"
#include "libbpf_internal.h"
-#include "str_error.h"
static inline __u64 ptr_to_u64(const void *ptr)
{
diff --git a/tools/lib/bpf/gen_loader.c b/tools/lib/bpf/gen_loader.c
index 6945dd99a846..cd5c2543f54d 100644
--- a/tools/lib/bpf/gen_loader.c
+++ b/tools/lib/bpf/gen_loader.c
@@ -4,6 +4,7 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
+#include <asm/byteorder.h>
#include <linux/filter.h>
#include <sys/param.h>
#include "btf.h"
@@ -13,8 +14,6 @@
#include "hashmap.h"
#include "bpf_gen_internal.h"
#include "skel_internal.h"
-#include <asm/byteorder.h>
-#include "str_error.h"
#define MAX_USED_MAPS 64
#define MAX_USED_PROGS 32
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index c21bc61f5ff4..6d19e0db492c 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -51,7 +51,6 @@
#include "libbpf.h"
#include "bpf.h"
#include "btf.h"
-#include "str_error.h"
#include "libbpf_internal.h"
#include "hashmap.h"
#include "bpf_gen_internal.h"
diff --git a/tools/lib/bpf/libbpf_internal.h b/tools/lib/bpf/libbpf_internal.h
index c93797dcaf5b..a8f204139371 100644
--- a/tools/lib/bpf/libbpf_internal.h
+++ b/tools/lib/bpf/libbpf_internal.h
@@ -172,6 +172,16 @@ do { \
#define pr_info(fmt, ...) __pr(LIBBPF_INFO, fmt, ##__VA_ARGS__)
#define pr_debug(fmt, ...) __pr(LIBBPF_DEBUG, fmt, ##__VA_ARGS__)
+/**
+ * @brief **libbpf_errstr()** returns string corresponding to numeric errno
+ * @param err negative numeric errno
+ * @return pointer to string representation of the errno, that is invalidated
+ * upon the next call.
+ */
+const char *libbpf_errstr(int err);
+
+#define errstr(err) libbpf_errstr(err)
+
#ifndef __has_builtin
#define __has_builtin(x) 0
#endif
diff --git a/tools/lib/bpf/libbpf_utils.c b/tools/lib/bpf/libbpf_utils.c
index 6b180172ec6b..ee3013e9b77c 100644
--- a/tools/lib/bpf/libbpf_utils.c
+++ b/tools/lib/bpf/libbpf_utils.c
@@ -10,10 +10,15 @@
#undef _GNU_SOURCE
#include <stdio.h>
#include <string.h>
+#include <errno.h>
#include "libbpf.h"
#include "libbpf_internal.h"
+#ifndef ENOTSUPP
+#define ENOTSUPP 524
+#endif
+
/* make sure libbpf doesn't use kernel-only integer typedefs */
#pragma GCC poison u8 u16 u32 u64 s8 s16 s32 s64
@@ -73,3 +78,70 @@ int libbpf_strerror(int err, char *buf, size_t size)
return libbpf_err(-ERANGE);
return libbpf_err(-ENOENT);
}
+
+const char *libbpf_errstr(int err)
+{
+ static __thread char buf[12];
+
+ if (err > 0)
+ err = -err;
+
+ switch (err) {
+ case -E2BIG: return "-E2BIG";
+ case -EACCES: return "-EACCES";
+ case -EADDRINUSE: return "-EADDRINUSE";
+ case -EADDRNOTAVAIL: return "-EADDRNOTAVAIL";
+ case -EAGAIN: return "-EAGAIN";
+ case -EALREADY: return "-EALREADY";
+ case -EBADF: return "-EBADF";
+ case -EBADFD: return "-EBADFD";
+ case -EBUSY: return "-EBUSY";
+ case -ECANCELED: return "-ECANCELED";
+ case -ECHILD: return "-ECHILD";
+ case -EDEADLK: return "-EDEADLK";
+ case -EDOM: return "-EDOM";
+ case -EEXIST: return "-EEXIST";
+ case -EFAULT: return "-EFAULT";
+ case -EFBIG: return "-EFBIG";
+ case -EILSEQ: return "-EILSEQ";
+ case -EINPROGRESS: return "-EINPROGRESS";
+ case -EINTR: return "-EINTR";
+ case -EINVAL: return "-EINVAL";
+ case -EIO: return "-EIO";
+ case -EISDIR: return "-EISDIR";
+ case -ELOOP: return "-ELOOP";
+ case -EMFILE: return "-EMFILE";
+ case -EMLINK: return "-EMLINK";
+ case -EMSGSIZE: return "-EMSGSIZE";
+ case -ENAMETOOLONG: return "-ENAMETOOLONG";
+ case -ENFILE: return "-ENFILE";
+ case -ENODATA: return "-ENODATA";
+ case -ENODEV: return "-ENODEV";
+ case -ENOENT: return "-ENOENT";
+ case -ENOEXEC: return "-ENOEXEC";
+ case -ENOLINK: return "-ENOLINK";
+ case -ENOMEM: return "-ENOMEM";
+ case -ENOSPC: return "-ENOSPC";
+ case -ENOTBLK: return "-ENOTBLK";
+ case -ENOTDIR: return "-ENOTDIR";
+ case -ENOTSUPP: return "-ENOTSUPP";
+ case -ENOTTY: return "-ENOTTY";
+ case -ENXIO: return "-ENXIO";
+ case -EOPNOTSUPP: return "-EOPNOTSUPP";
+ case -EOVERFLOW: return "-EOVERFLOW";
+ case -EPERM: return "-EPERM";
+ case -EPIPE: return "-EPIPE";
+ case -EPROTO: return "-EPROTO";
+ case -EPROTONOSUPPORT: return "-EPROTONOSUPPORT";
+ case -ERANGE: return "-ERANGE";
+ case -EROFS: return "-EROFS";
+ case -ESPIPE: return "-ESPIPE";
+ case -ESRCH: return "-ESRCH";
+ case -ETXTBSY: return "-ETXTBSY";
+ case -EUCLEAN: return "-EUCLEAN";
+ case -EXDEV: return "-EXDEV";
+ default:
+ snprintf(buf, sizeof(buf), "%d", err);
+ return buf;
+ }
+}
diff --git a/tools/lib/bpf/linker.c b/tools/lib/bpf/linker.c
index a469e5d4fee7..56ae77047bc3 100644
--- a/tools/lib/bpf/linker.c
+++ b/tools/lib/bpf/linker.c
@@ -25,7 +25,6 @@
#include "btf.h"
#include "libbpf_internal.h"
#include "strset.h"
-#include "str_error.h"
#define BTF_EXTERN_SEC ".extern"
diff --git a/tools/lib/bpf/relo_core.c b/tools/lib/bpf/relo_core.c
index 2b83c98a1137..6eea5edba58a 100644
--- a/tools/lib/bpf/relo_core.c
+++ b/tools/lib/bpf/relo_core.c
@@ -64,7 +64,6 @@ enum libbpf_print_level {
#include "libbpf.h"
#include "bpf.h"
#include "btf.h"
-#include "str_error.h"
#include "libbpf_internal.h"
#endif
diff --git a/tools/lib/bpf/ringbuf.c b/tools/lib/bpf/ringbuf.c
index 9702b70da444..00ec4837a06d 100644
--- a/tools/lib/bpf/ringbuf.c
+++ b/tools/lib/bpf/ringbuf.c
@@ -21,7 +21,6 @@
#include "libbpf.h"
#include "libbpf_internal.h"
#include "bpf.h"
-#include "str_error.h"
struct ring {
ring_buffer_sample_fn sample_cb;
diff --git a/tools/lib/bpf/str_error.c b/tools/lib/bpf/str_error.c
deleted file mode 100644
index 92dbd801102f..000000000000
--- a/tools/lib/bpf/str_error.c
+++ /dev/null
@@ -1,80 +0,0 @@
-// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
-#undef _GNU_SOURCE
-#include <string.h>
-#include <stdio.h>
-#include <errno.h>
-#include "str_error.h"
-
-#ifndef ENOTSUPP
-#define ENOTSUPP 524
-#endif
-
-/* make sure libbpf doesn't use kernel-only integer typedefs */
-#pragma GCC poison u8 u16 u32 u64 s8 s16 s32 s64
-
-const char *libbpf_errstr(int err)
-{
- static __thread char buf[12];
-
- if (err > 0)
- err = -err;
-
- switch (err) {
- case -E2BIG: return "-E2BIG";
- case -EACCES: return "-EACCES";
- case -EADDRINUSE: return "-EADDRINUSE";
- case -EADDRNOTAVAIL: return "-EADDRNOTAVAIL";
- case -EAGAIN: return "-EAGAIN";
- case -EALREADY: return "-EALREADY";
- case -EBADF: return "-EBADF";
- case -EBADFD: return "-EBADFD";
- case -EBUSY: return "-EBUSY";
- case -ECANCELED: return "-ECANCELED";
- case -ECHILD: return "-ECHILD";
- case -EDEADLK: return "-EDEADLK";
- case -EDOM: return "-EDOM";
- case -EEXIST: return "-EEXIST";
- case -EFAULT: return "-EFAULT";
- case -EFBIG: return "-EFBIG";
- case -EILSEQ: return "-EILSEQ";
- case -EINPROGRESS: return "-EINPROGRESS";
- case -EINTR: return "-EINTR";
- case -EINVAL: return "-EINVAL";
- case -EIO: return "-EIO";
- case -EISDIR: return "-EISDIR";
- case -ELOOP: return "-ELOOP";
- case -EMFILE: return "-EMFILE";
- case -EMLINK: return "-EMLINK";
- case -EMSGSIZE: return "-EMSGSIZE";
- case -ENAMETOOLONG: return "-ENAMETOOLONG";
- case -ENFILE: return "-ENFILE";
- case -ENODATA: return "-ENODATA";
- case -ENODEV: return "-ENODEV";
- case -ENOENT: return "-ENOENT";
- case -ENOEXEC: return "-ENOEXEC";
- case -ENOLINK: return "-ENOLINK";
- case -ENOMEM: return "-ENOMEM";
- case -ENOSPC: return "-ENOSPC";
- case -ENOTBLK: return "-ENOTBLK";
- case -ENOTDIR: return "-ENOTDIR";
- case -ENOTSUPP: return "-ENOTSUPP";
- case -ENOTTY: return "-ENOTTY";
- case -ENXIO: return "-ENXIO";
- case -EOPNOTSUPP: return "-EOPNOTSUPP";
- case -EOVERFLOW: return "-EOVERFLOW";
- case -EPERM: return "-EPERM";
- case -EPIPE: return "-EPIPE";
- case -EPROTO: return "-EPROTO";
- case -EPROTONOSUPPORT: return "-EPROTONOSUPPORT";
- case -ERANGE: return "-ERANGE";
- case -EROFS: return "-EROFS";
- case -ESPIPE: return "-ESPIPE";
- case -ESRCH: return "-ESRCH";
- case -ETXTBSY: return "-ETXTBSY";
- case -EUCLEAN: return "-EUCLEAN";
- case -EXDEV: return "-EXDEV";
- default:
- snprintf(buf, sizeof(buf), "%d", err);
- return buf;
- }
-}
diff --git a/tools/lib/bpf/str_error.h b/tools/lib/bpf/str_error.h
deleted file mode 100644
index d4c82eec034d..000000000000
--- a/tools/lib/bpf/str_error.h
+++ /dev/null
@@ -1,15 +0,0 @@
-/* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */
-#ifndef __LIBBPF_STR_ERROR_H
-#define __LIBBPF_STR_ERROR_H
-
-/**
- * @brief **libbpf_errstr()** returns string corresponding to numeric errno
- * @param err negative numeric errno
- * @return pointer to string representation of the errno, that is invalidated
- * upon the next call.
- */
-const char *libbpf_errstr(int err);
-
-#define errstr(err) libbpf_errstr(err)
-
-#endif /* __LIBBPF_STR_ERROR_H */
diff --git a/tools/lib/bpf/usdt.c b/tools/lib/bpf/usdt.c
index fc2785eecc17..c174b4086673 100644
--- a/tools/lib/bpf/usdt.c
+++ b/tools/lib/bpf/usdt.c
@@ -20,7 +20,6 @@
#include "libbpf_common.h"
#include "libbpf_internal.h"
#include "hashmap.h"
-#include "str_error.h"
/* libbpf's USDT support consists of BPF-side state/code and user-space
* state/code working together in concert. BPF-side parts are defined in