Skip to content

Commit 52890d2

Browse files
committed
Merge branch 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Thomas writes: "- Provide a strerror_r wrapper so lib/bpf can be built on systems without _GNU_SOURCE - Unbreak the man page generator when building out of tree" * 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: perf Documentation: Fix out-of-tree asciidoctor man page generation tools lib bpf: Provide wrapper for strerror_r to build in !_GNU_SOURCE systems
2 parents ea09267 + 5d05dfd commit 52890d2

File tree

5 files changed

+36
-12
lines changed

5 files changed

+36
-12
lines changed

tools/lib/bpf/Build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
libbpf-y := libbpf.o bpf.o nlattr.o btf.o libbpf_errno.o
1+
libbpf-y := libbpf.o bpf.o nlattr.o btf.o libbpf_errno.o str_error.o

tools/lib/bpf/libbpf.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#include "libbpf.h"
5151
#include "bpf.h"
5252
#include "btf.h"
53+
#include "str_error.h"
5354

5455
#ifndef EM_BPF
5556
#define EM_BPF 247
@@ -469,7 +470,7 @@ static int bpf_object__elf_init(struct bpf_object *obj)
469470
obj->efile.fd = open(obj->path, O_RDONLY);
470471
if (obj->efile.fd < 0) {
471472
char errmsg[STRERR_BUFSIZE];
472-
char *cp = strerror_r(errno, errmsg, sizeof(errmsg));
473+
char *cp = str_error(errno, errmsg, sizeof(errmsg));
473474

474475
pr_warning("failed to open %s: %s\n", obj->path, cp);
475476
return -errno;
@@ -810,8 +811,7 @@ static int bpf_object__elf_collect(struct bpf_object *obj)
810811
data->d_size, name, idx);
811812
if (err) {
812813
char errmsg[STRERR_BUFSIZE];
813-
char *cp = strerror_r(-err, errmsg,
814-
sizeof(errmsg));
814+
char *cp = str_error(-err, errmsg, sizeof(errmsg));
815815

816816
pr_warning("failed to alloc program %s (%s): %s",
817817
name, obj->path, cp);
@@ -1140,7 +1140,7 @@ bpf_object__create_maps(struct bpf_object *obj)
11401140

11411141
*pfd = bpf_create_map_xattr(&create_attr);
11421142
if (*pfd < 0 && create_attr.btf_key_type_id) {
1143-
cp = strerror_r(errno, errmsg, sizeof(errmsg));
1143+
cp = str_error(errno, errmsg, sizeof(errmsg));
11441144
pr_warning("Error in bpf_create_map_xattr(%s):%s(%d). Retrying without BTF.\n",
11451145
map->name, cp, errno);
11461146
create_attr.btf_fd = 0;
@@ -1155,7 +1155,7 @@ bpf_object__create_maps(struct bpf_object *obj)
11551155
size_t j;
11561156

11571157
err = *pfd;
1158-
cp = strerror_r(errno, errmsg, sizeof(errmsg));
1158+
cp = str_error(errno, errmsg, sizeof(errmsg));
11591159
pr_warning("failed to create map (name: '%s'): %s\n",
11601160
map->name, cp);
11611161
for (j = 0; j < i; j++)
@@ -1339,7 +1339,7 @@ load_program(enum bpf_prog_type type, enum bpf_attach_type expected_attach_type,
13391339
}
13401340

13411341
ret = -LIBBPF_ERRNO__LOAD;
1342-
cp = strerror_r(errno, errmsg, sizeof(errmsg));
1342+
cp = str_error(errno, errmsg, sizeof(errmsg));
13431343
pr_warning("load bpf program failed: %s\n", cp);
13441344

13451345
if (log_buf && log_buf[0] != '\0') {
@@ -1654,7 +1654,7 @@ static int check_path(const char *path)
16541654

16551655
dir = dirname(dname);
16561656
if (statfs(dir, &st_fs)) {
1657-
cp = strerror_r(errno, errmsg, sizeof(errmsg));
1657+
cp = str_error(errno, errmsg, sizeof(errmsg));
16581658
pr_warning("failed to statfs %s: %s\n", dir, cp);
16591659
err = -errno;
16601660
}
@@ -1690,7 +1690,7 @@ int bpf_program__pin_instance(struct bpf_program *prog, const char *path,
16901690
}
16911691

16921692
if (bpf_obj_pin(prog->instances.fds[instance], path)) {
1693-
cp = strerror_r(errno, errmsg, sizeof(errmsg));
1693+
cp = str_error(errno, errmsg, sizeof(errmsg));
16941694
pr_warning("failed to pin program: %s\n", cp);
16951695
return -errno;
16961696
}
@@ -1708,7 +1708,7 @@ static int make_dir(const char *path)
17081708
err = -errno;
17091709

17101710
if (err) {
1711-
cp = strerror_r(-err, errmsg, sizeof(errmsg));
1711+
cp = str_error(-err, errmsg, sizeof(errmsg));
17121712
pr_warning("failed to mkdir %s: %s\n", path, cp);
17131713
}
17141714
return err;
@@ -1770,7 +1770,7 @@ int bpf_map__pin(struct bpf_map *map, const char *path)
17701770
}
17711771

17721772
if (bpf_obj_pin(map->fd, path)) {
1773-
cp = strerror_r(errno, errmsg, sizeof(errmsg));
1773+
cp = str_error(errno, errmsg, sizeof(errmsg));
17741774
pr_warning("failed to pin map: %s\n", cp);
17751775
return -errno;
17761776
}

tools/lib/bpf/str_error.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// SPDX-License-Identifier: LGPL-2.1
2+
#undef _GNU_SOURCE
3+
#include <string.h>
4+
#include <stdio.h>
5+
#include "str_error.h"
6+
7+
/*
8+
* Wrapper to allow for building in non-GNU systems such as Alpine Linux's musl
9+
* libc, while checking strerror_r() return to avoid having to check this in
10+
* all places calling it.
11+
*/
12+
char *str_error(int err, char *dst, int len)
13+
{
14+
int ret = strerror_r(err, dst, len);
15+
if (ret)
16+
snprintf(dst, len, "ERROR: strerror_r(%d)=%d", err, ret);
17+
return dst;
18+
}

tools/lib/bpf/str_error.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// SPDX-License-Identifier: LGPL-2.1
2+
#ifndef BPF_STR_ERROR
3+
#define BPF_STR_ERROR
4+
5+
char *str_error(int err, char *dst, int len);
6+
#endif // BPF_STR_ERROR

tools/perf/Documentation/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ $(MAN_HTML): $(OUTPUT)%.html : %.txt
280280
mv $@+ $@
281281

282282
ifdef USE_ASCIIDOCTOR
283-
$(OUTPUT)%.1 $(OUTPUT)%.5 $(OUTPUT)%.7 : $(OUTPUT)%.txt
283+
$(OUTPUT)%.1 $(OUTPUT)%.5 $(OUTPUT)%.7 : %.txt
284284
$(QUIET_ASCIIDOC)$(RM) $@+ $@ && \
285285
$(ASCIIDOC) -b manpage -d manpage \
286286
$(ASCIIDOC_EXTRA) -aperf_version=$(PERF_VERSION) -o $@+ $< && \

0 commit comments

Comments
 (0)