libbpf: Add namespace for errstr making it libbpf_errstr
PATCH v2 1/1 libbpf: Add namespace for errstr making it libbpf_errstr
When statically linking symbols can be replaced with those from other statically linked libraries depending on the link order and the hoped for "multiple definition" error may not appear. To avoid conflicts it is good practice to namespace symbols, this change renames errstr to libbpf_errstr. To avoid churn a #define is used to turn use of errstr(err) to libbpf_errstr(err).
---
v2: Use #define to avoid churn renaming errstr as suggested by Andrii
Nakryiko <[email protected]>.
v1: I feel like this patch shouldn't be strictly necessary, it turned
out for a use-case it was and people who know better than me say the linker is working as intended. The conflicting errstr was
from: https://sourceforge.net/projects/linuxquota/ The fixes tag may not be strictly necessary.
--- tools/lib/bpf/str_error.c | 2 +- tools/lib/bpf/str_error.h | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-)
tools/lib/bpf/str_error.c +1 -1
@@ -36,7 +36,7 @@ char *libbpf_strerror_r(int err, char *dst, int len)return dst; } -const char *errstr (int err) +const char *libbpf_errstr (int err) {static __threadchar buf[12 ];
tools/lib/bpf/str_error.h +5 -2
@@ -7,10 +7,13 @@char *libbpf_strerror_r (int err,char *dst,int len);/** -* @brief **errstr()** returns string corresponding to numeric errno +* @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 *errstr (int err); +const char *libbpf_errstr (int err); + +#define errstr (err) libbpf_errstr(err) +#endif /* __LIBBPF_STR_ERROR_H */
Signature · 1 line
2.49.0.395.g12beb8f557-goog
This patch was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <[email protected]>:
Hello:
This patch was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <[email protected]>:
Quoted 8 lines · On Thu, 20 Mar 2025 15:24:39 -0700 you wrote:
When statically linking symbols can be replaced with those from other statically linked libraries depending on the link order and the hoped for "multiple definition" error may not appear. To avoid conflicts it is good practice to namespace symbols, this change renames errstr to
libbpf_errstr. To avoid churn a #define is used to turn use of errstr(err) tolibbpf_errstr(err).[...]
Here is the summary with links:
- [v2] libbpf: Add namespace for errstr making it libbpf_errstr
https://git.kernel.org/bpf/bpf-next/c/307ef667e945
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html