On Thu, Jan 04, 2024 at 12:04:17AM -0300, Arnaldo Carvalho de Melo wrote: > The header with the prototype for basename() is missing in the gen.c > file, which breaks the build in distros where that header doesn't get > include by some of the other includes present in gen.c, by luck, fix it. > > Noticed when build perf on the Alpine Linux edge. > > Signed-off-by: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx> > > --- > > diff --git a/tools/bpf/bpftool/gen.c b/tools/bpf/bpftool/gen.c > index ee3ce2b8000d75d2..0e50722588b48fa0 100644 > --- a/tools/bpf/bpftool/gen.c > +++ b/tools/bpf/bpftool/gen.c > @@ -7,6 +7,7 @@ > #include <ctype.h> > #include <errno.h> > #include <fcntl.h> > +#include <libgen.h> > #include <linux/err.h> > #include <stdbool.h> > #include <stdio.h> hi, this gives me compile warning on fedora: gen.c: In function ‘get_obj_name’: gen.c:61:32: warning: passing argument 1 of ‘__xpg_basename’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers] 61 | strncpy(name, basename(file), MAX_OBJ_NAME_LEN - 1); | ^~~~ In file included from gen.c:10: /usr/include/libgen.h:34:36: note: expected ‘char *’ but argument is of type ‘const char *’ 34 | extern char *__xpg_basename (char *__path) __THROW; | ~~~~~~^~~~~~ looks like there are 2 versions of basename (man 3 basename): VERSIONS There are two different versions of basename() - the POSIX version described above, and the GNU version, which one gets after #define _GNU_SOURCE /* See feature_test_macros(7) */ #include <string.h> The GNU version never modifies its argument, and returns the empty string when path has a trailing slash, and in particular also when it is "/". There is no GNU version of dirname(). With glibc, one gets the POSIX version of basename() when <libgen.h> is included, and the GNU version otherwise. I think we want to keep the GNU version declaration, but not sure how to fix the bpftool on Alpine Linux edge, what's the exact build error? jirka