diff mbox series

bpftool: Add missing libgen.h for basename()

Message ID ZZYgMYmb_qE94PUB@kernel.org (mailing list archive)
State Changes Requested
Delegated to: BPF
Headers show
Series bpftool: Add missing libgen.h for basename() | expand

Checks

Context Check Description
bpf/vmtest-bpf-next-PR success PR summary
netdev/tree_selection success Not a local patch
bpf/vmtest-bpf-next-VM_Test-7 success Logs for aarch64-gcc / test (test_progs, false, 360) / test_progs on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-11 success Logs for s390x-gcc / build / build for s390x with gcc
bpf/vmtest-bpf-next-VM_Test-19 success Logs for x86_64-gcc / build / build for x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-28 success Logs for x86_64-llvm-17 / build / build for x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-35 success Logs for x86_64-llvm-18 / build / build for x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-18 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-36 success Logs for x86_64-llvm-18 / build-release / build for x86_64 with llvm-18 and -O2 optimization
bpf/vmtest-bpf-next-VM_Test-42 success Logs for x86_64-llvm-18 / veristat
bpf/vmtest-bpf-next-VM_Test-34 success Logs for x86_64-llvm-17 / veristat
bpf/vmtest-bpf-next-VM_Test-20 success Logs for x86_64-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-17 success Logs for s390x-gcc / veristat
bpf/vmtest-bpf-next-VM_Test-29 success Logs for x86_64-llvm-17 / build-release / build for x86_64 with llvm-17 and -O2 optimization
bpf/vmtest-bpf-next-VM_Test-27 success Logs for x86_64-gcc / veristat / veristat on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-23 success Logs for x86_64-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-21 success Logs for x86_64-gcc / test (test_maps, false, 360) / test_maps on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-38 success Logs for x86_64-llvm-18 / test (test_progs, false, 360) / test_progs on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-22 success Logs for x86_64-gcc / test (test_progs, false, 360) / test_progs on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-31 success Logs for x86_64-llvm-17 / test (test_progs, false, 360) / test_progs on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-24 success Logs for x86_64-gcc / test (test_progs_no_alu32_parallel, true, 30) / test_progs_no_alu32_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-32 success Logs for x86_64-llvm-17 / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-41 success Logs for x86_64-llvm-18 / test (test_verifier, false, 360) / test_verifier on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-26 success Logs for x86_64-gcc / test (test_verifier, false, 360) / test_verifier on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-37 success Logs for x86_64-llvm-18 / test (test_maps, false, 360) / test_maps on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-33 success Logs for x86_64-llvm-17 / test (test_verifier, false, 360) / test_verifier on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-25 success Logs for x86_64-gcc / test (test_progs_parallel, true, 30) / test_progs_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-30 success Logs for x86_64-llvm-17 / test (test_maps, false, 360) / test_maps on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-40 success Logs for x86_64-llvm-18 / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-39 success Logs for x86_64-llvm-18 / test (test_progs_cpuv4, false, 360) / test_progs_cpuv4 on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-16 success Logs for s390x-gcc / test (test_verifier, false, 360) / test_verifier on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-14 success Logs for s390x-gcc / test (test_progs, false, 360) / test_progs on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-3 success Logs for Validate matrix.py
bpf/vmtest-bpf-next-VM_Test-0 success Logs for Lint
bpf/vmtest-bpf-next-VM_Test-1 success Logs for ShellCheck
bpf/vmtest-bpf-next-VM_Test-2 success Logs for Unittests
bpf/vmtest-bpf-next-VM_Test-10 success Logs for aarch64-gcc / veristat
bpf/vmtest-bpf-next-VM_Test-5 success Logs for aarch64-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-12 success Logs for s390x-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-4 success Logs for aarch64-gcc / build / build for aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-15 success Logs for x86_64-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-13 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-6 success Logs for aarch64-gcc / test (test_maps, false, 360) / test_maps on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-8 success Logs for aarch64-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-9 success Logs for aarch64-gcc / test (test_verifier, false, 360) / test_verifier on aarch64 with gcc

Commit Message

Arnaldo Carvalho de Melo Jan. 4, 2024, 3:04 a.m. UTC
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@redhat.com>

---

Comments

Jiri Olsa Jan. 4, 2024, 9:33 a.m. UTC | #1
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@redhat.com>
> 
> ---
> 
> 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
Arnaldo Carvalho de Melo Jan. 4, 2024, 12:27 p.m. UTC | #2
Em Thu, Jan 04, 2024 at 10:33:58AM +0100, Jiri Olsa escreveu:
> 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@redhat.com>
> > 
> > ---
> > 
> > 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>

> this gives me compile warning on fedora:

Oh well, I looked at perf files and found:

⬢[acme@toolbox perf-tools-next]$ git grep basename tools/perf
tools/perf/builtin-daemon.c:    base = basename(basen);

And on alpine:edge:

/ $ grep '\<basename(' /usr/include/*.h
/usr/include/libgen.h:char *basename(char *);
/ $ cat /usr/include/libgen.h
#ifndef _LIBGEN_H
#define _LIBGEN_H

#ifdef __cplusplus
extern "C" {
#endif

char *dirname(char *);
char *basename(char *);

#ifdef __cplusplus
}
#endif

#endif
/ $

And in tools/perf/builtin-daemon.c we have:

⬢[acme@toolbox perf-tools-next]$ grep libgen tools/perf/builtin-daemon.c
#include <libgen.h>
⬢[acme@toolbox perf-tools-next]$

And the error on alpine:

gen.c: In function 'get_obj_name':
gen.c:60:23: warning: implicit declaration of function 'basename' [-Wimplicit-function-declaration]
   60 |         strncpy(name, basename(file), MAX_OBJ_NAME_LEN - 1);
      |                       ^~~~~~~~

the libgen.h include wasn't there, looks trivial.

Was late at night, thought about leaving for tomorrow for further tests
but seemed so obvious... duh ;-)
 
> 	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?

BUILD_TARBALL_HEAD=ec5257d99e6894d65fae772ca43c53b3d6855115
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-alpine-linux-musl/13.2.1/lto-wrapper
Target: x86_64-alpine-linux-musl
Configured with: /home/buildozer/aports/main/gcc/src/gcc-13-20231014/configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --build=x86_64-alpine-linux-musl --host=x86_64-alpine-linux-musl --target=x86_64-alpine-linux-musl --enable-checking=release --disable-cet --disable-fixed-point --disable-libstdcxx-pch --disable-multilib --disable-nls --disable-werror --disable-symvers --enable-__cxa_atexit --enable-default-pie --enable-default-ssp --enable-languages=c,c++,d,objc,go,fortran,ada --enable-link-serialization=2 --enable-linker-build-id --disable-libssp --disable-libsanitizer --enable-shared --enable-threads --enable-tls --with-bugurl=https://gitlab.alpinelinux.org/alpine/aports/-/issues --with-system-zlib --with-linker-hash-style=gnu --with-pkgversion='Alpine 13.2.1_git20231014'
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 13.2.1 20231014 (Alpine 13.2.1_git20231014)
+ make 'PYTHON=python3' 'ARCH=' 'CROSS_COMPILE=' 'EXTRA_CFLAGS=' -C tools/perf 'O=/tmp/build/perf'
make: Entering directory '/git/perf-6.7.0-rc6/tools/perf'
  BUILD:   Doing 'make -j28' parallel build
  HOSTCC  /tmp/build/perf/fixdep.o
  HOSTLD  /tmp/build/perf/fixdep-in.o
  LINK    /tmp/build/perf/fixdep
Warning: Skipped check-headers due to missing ../../include
Makefile.config:612: No sys/sdt.h found, no SDT events are defined, please install systemtap-sdt-devel or systemtap-sdt-dev
Makefile.config:1093: No libbabeltrace found, disables 'perf data' CTF format support, please install libbabeltrace-dev[el]/libbabeltrace-ctf-dev
Makefile.config:1127: No alternatives command found, you need to set JDIR= to point to the root of your Java directory
Makefile.config:1158: libpfm4 not found, disables libpfm4 support. Please install libpfm4-dev

Auto-detecting system features:
...                                   dwarf: [ on  ]
...                      dwarf_getlocations: [ on  ]
...                                   glibc: [ OFF ]
...                                  libbfd: [ on  ]
...                          libbfd-buildid: [ on  ]
...                                  libcap: [ on  ]
...                                  libelf: [ on  ]
...                                 libnuma: [ on  ]
...                  numa_num_possible_cpus: [ on  ]
...                                 libperl: [ on  ]
...                               libpython: [ on  ]
...                               libcrypto: [ on  ]
...                               libunwind: [ on  ]
...                      libdw-dwarf-unwind: [ on  ]
...                                    zlib: [ on  ]
...                                    lzma: [ on  ]
...                               get_cpuid: [ on  ]
...                                     bpf: [ on  ]
...                                  libaio: [ on  ]
...                                 libzstd: [ on  ]

  GEN     /tmp/build/perf/common-cmds.h
  PERF_VERSION = 6.7.rc6.gec5257d99e68
  GEN     perf-archive
  GEN     perf-iostat
  CC      /tmp/build/perf/dlfilters/dlfilter-test-api-v2.o
  CC      /tmp/build/perf/dlfilters/dlfilter-test-api-v0.o
  CC      /tmp/build/perf/dlfilters/dlfilter-show-cycles.o
  GEN     /tmp/build/perf/arch/arm64/include/generated/asm/sysreg-defs.h
  INSTALL /tmp/build/perf/libsubcmd/include/subcmd/exec-cmd.h
  INSTALL /tmp/build/perf/libsubcmd/include/subcmd/help.h
  INSTALL /tmp/build/perf/libsubcmd/include/subcmd/pager.h
  INSTALL /tmp/build/perf/libsubcmd/include/subcmd/parse-options.h
  INSTALL /tmp/build/perf/libsubcmd/include/subcmd/run-command.h
  CC      /tmp/build/perf/libsubcmd/exec-cmd.o
  INSTALL libsubcmd_headers
  CC      /tmp/build/perf/libsubcmd/help.o
  CC      /tmp/build/perf/libsubcmd/pager.o
  CC      /tmp/build/perf/libsubcmd/parse-options.o
  CC      /tmp/build/perf/libsubcmd/run-command.o
  CC      /tmp/build/perf/libsubcmd/sigchain.o
  CC      /tmp/build/perf/libsubcmd/subcmd-config.o
  INSTALL /tmp/build/perf/libsymbol/include/symbol/kallsyms.h
  CC      /tmp/build/perf/libsymbol/kallsyms.o
  INSTALL libsymbol_headers
  INSTALL /tmp/build/perf/libperf/include/perf/bpf_perf.h
  INSTALL /tmp/build/perf/libperf/include/perf/core.h
  INSTALL /tmp/build/perf/libperf/include/perf/cpumap.h
  GEN     /tmp/build/perf/libbpf/bpf_helper_defs.h
  INSTALL /tmp/build/perf/libperf/include/perf/threadmap.h
  INSTALL /tmp/build/perf/libbpf/include/bpf/bpf.h
  INSTALL /tmp/build/perf/libperf/include/perf/evlist.h
  INSTALL /tmp/build/perf/libperf/include/perf/evsel.h
  CC      /tmp/build/perf/libperf/core.o
  INSTALL /tmp/build/perf/libperf/include/perf/event.h
  INSTALL /tmp/build/perf/libperf/include/perf/mmap.h
  INSTALL /tmp/build/perf/libbpf/include/bpf/libbpf.h
  INSTALL /tmp/build/perf/libapi/include/api/cpu.h
  CC      /tmp/build/perf/libperf/cpumap.o
  INSTALL /tmp/build/perf/libapi/include/api/debug.h
  INSTALL /tmp/build/perf/libapi/include/api/io.h
  CC      /tmp/build/perf/libperf/threadmap.o
  INSTALL /tmp/build/perf/libapi/include/api/fd/array.h
  MKDIR   /tmp/build/perf/libapi/fd/
  CC      /tmp/build/perf/libperf/evsel.o
  LINK    /tmp/build/perf/dlfilters/dlfilter-show-cycles.so
  CC      /tmp/build/perf/libapi/fd/array.o
  INSTALL /tmp/build/perf/libbpf/include/bpf/btf.h
  INSTALL /tmp/build/perf/libbpf/include/bpf/libbpf_common.h
  MKDIR   /tmp/build/perf/libapi/fs/
  CC      /tmp/build/perf/libapi/fs/fs.o
  INSTALL /tmp/build/perf/libperf/include/internal/cpumap.h
  INSTALL /tmp/build/perf/libperf/include/internal/evlist.h
  CC      /tmp/build/perf/libperf/evlist.o
  INSTALL /tmp/build/perf/libapi/include/api/fs/fs.h
  INSTALL /tmp/build/perf/libperf/include/internal/evsel.h
  CC      /tmp/build/perf/libperf/mmap.o
  INSTALL /tmp/build/perf/libapi/include/api/fs/tracing_path.h
  CC      /tmp/build/perf/libperf/zalloc.o
  INSTALL libapi_headers
  MKDIR   /tmp/build/perf/libapi/fs/
  INSTALL /tmp/build/perf/libperf/include/internal/lib.h
  CC      /tmp/build/perf/libapi/fs/tracing_path.o
  CC      /tmp/build/perf/libapi/fs/cgroup.o
  INSTALL /tmp/build/perf/libperf/include/internal/mmap.h
  INSTALL /tmp/build/perf/libperf/include/internal/rc_check.h
  INSTALL /tmp/build/perf/libperf/include/internal/threadmap.h
  INSTALL /tmp/build/perf/libperf/include/internal/xyarray.h
  INSTALL libperf_headers
  LINK    /tmp/build/perf/dlfilters/dlfilter-test-api-v0.so
  CC      /tmp/build/perf/libperf/xyarray.o
  LINK    /tmp/build/perf/dlfilters/dlfilter-test-api-v2.so
  CC      /tmp/build/perf/libperf/lib.o
  CC      /tmp/build/perf/libapi/cpu.o
  INSTALL /tmp/build/perf/libbpf/include/bpf/libbpf_legacy.h
  INSTALL /tmp/build/perf/libbpf/include/bpf/bpf_helpers.h
  INSTALL /tmp/build/perf/libbpf/include/bpf/bpf_tracing.h
  CC      /tmp/build/perf/libapi/debug.o
  INSTALL /tmp/build/perf/libbpf/include/bpf/bpf_endian.h
  INSTALL /tmp/build/perf/libbpf/include/bpf/bpf_core_read.h
  INSTALL /tmp/build/perf/libbpf/include/bpf/skel_internal.h
  INSTALL /tmp/build/perf/libbpf/include/bpf/libbpf_version.h
  INSTALL /tmp/build/perf/libbpf/include/bpf/usdt.bpf.h
  CC      /tmp/build/perf/libapi/str_error_r.o
  LD      /tmp/build/perf/libapi/fd/libapi-in.o
  INSTALL /tmp/build/perf/libbpf/include/bpf/bpf_helper_defs.h
  INSTALL libbpf_headers
  MKDIR   /tmp/build/perf/libbpf/staticobjs/
  CC      /tmp/build/perf/libbpf/staticobjs/libbpf.o
  MKDIR   /tmp/build/perf/libbpf/staticobjs/
  CC      /tmp/build/perf/libbpf/staticobjs/bpf.o
  CC      /tmp/build/perf/libbpf/staticobjs/nlattr.o
  CC      /tmp/build/perf/libbpf/staticobjs/btf.o
  CC      /tmp/build/perf/libbpf/staticobjs/libbpf_errno.o
  CC      /tmp/build/perf/libbpf/staticobjs/str_error.o
  CC      /tmp/build/perf/libbpf/staticobjs/netlink.o
  CC      /tmp/build/perf/libbpf/staticobjs/bpf_prog_linfo.o
  CC      /tmp/build/perf/libbpf/staticobjs/libbpf_probes.o
  CC      /tmp/build/perf/libbpf/staticobjs/hashmap.o
  CC      /tmp/build/perf/libbpf/staticobjs/btf_dump.o
  CC      /tmp/build/perf/libbpf/staticobjs/ringbuf.o
  CC      /tmp/build/perf/libbpf/staticobjs/strset.o
  CC      /tmp/build/perf/libbpf/staticobjs/linker.o
  LD      /tmp/build/perf/libsymbol/libsymbol-in.o
  AR      /tmp/build/perf/libsymbol/libsymbol.a
  CC      /tmp/build/perf/libbpf/staticobjs/gen_loader.o
  CC      /tmp/build/perf/libbpf/staticobjs/relo_core.o
  CC      /tmp/build/perf/libbpf/staticobjs/usdt.o
  CC      /tmp/build/perf/libbpf/staticobjs/zip.o
  CC      /tmp/build/perf/libbpf/staticobjs/elf.o
  LD      /tmp/build/perf/libapi/fs/libapi-in.o
  LD      /tmp/build/perf/libapi/libapi-in.o
  LD      /tmp/build/perf/libperf/libperf-in.o
  AR      /tmp/build/perf/libapi/libapi.a
  AR      /tmp/build/perf/libperf/libperf.a
  LD      /tmp/build/perf/libsubcmd/libsubcmd-in.o
  AR      /tmp/build/perf/libsubcmd/libsubcmd.a
  GEN     /tmp/build/perf/python/perf.cpython-311-x86_64-linux-musl.so

Auto-detecting system features:
...                         clang-bpf-co-re: [ on  ]
...                                    llvm: [ on  ]
...                                  libcap: [ on  ]
...                                  libbfd: [ on  ]

  MKDIR   /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/include/bpf
  MKDIR   /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/
  MKDIR   /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/
  INSTALL /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/include/bpf/hashmap.h
  INSTALL /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/include/bpf/relo_core.h
  INSTALL /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/include/bpf/libbpf_internal.h
  GEN     /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/bpf_helper_defs.h
  INSTALL /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/include/bpf/bpf.h
  INSTALL /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/include/bpf/libbpf.h
  INSTALL /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/include/bpf/btf.h
  INSTALL /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/include/bpf/libbpf_common.h
  INSTALL /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/include/bpf/libbpf_legacy.h
  INSTALL /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/include/bpf/bpf_helpers.h
  INSTALL /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/include/bpf/bpf_tracing.h
  INSTALL /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/include/bpf/bpf_endian.h
  INSTALL /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/include/bpf/bpf_core_read.h
  INSTALL /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/include/bpf/skel_internal.h
  INSTALL /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/include/bpf/libbpf_version.h
  INSTALL /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/include/bpf/usdt.bpf.h
  INSTALL /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/include/bpf/bpf_helper_defs.h
  INSTALL libbpf_headers
  MKDIR   /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/
  MKDIR   /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/
  CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/libbpf.o
  CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/nlattr.o
  CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/bpf.o
  CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/btf.o
  CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/libbpf_errno.o
  CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/str_error.o
  CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/netlink.o
  CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/bpf_prog_linfo.o
  CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/libbpf_probes.o
  CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/hashmap.o
  CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/btf_dump.o
  CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/ringbuf.o
  CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/strset.o
  CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/linker.o
  CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/gen_loader.o
  CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/relo_core.o
  CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/usdt.o
  CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/zip.o
  CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/elf.o
  LD      /tmp/build/perf/libbpf/staticobjs/libbpf-in.o
  LINK    /tmp/build/perf/libbpf/libbpf.a
  LD      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/libbpf-in.o
  LINK    /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/libbpf.a
  CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/main.o
  CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/common.o
  CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/json_writer.o
  CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/gen.o
  CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/btf.o
  CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/xlated_dumper.o
  CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/btf_dumper.o
  CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/disasm.o
gen.c: In function 'get_obj_name':
gen.c:60:23: warning: implicit declaration of function 'basename' [-Wimplicit-function-declaration]
   60 |         strncpy(name, basename(file), MAX_OBJ_NAME_LEN - 1);
      |                       ^~~~~~~~
gen.c:60:23: warning: passing argument 2 of 'strncpy' makes pointer from integer without a cast [-Wint-conversion]
   60 |         strncpy(name, basename(file), MAX_OBJ_NAME_LEN - 1);
      |                       ^~~~~~~~~~~~~~
      |                       |
      |                       int
In file included from gen.c:13:
/usr/include/fortify/string.h:139:48: note: expected 'const char *' but argument is of type 'int'
  139 |                                    const char *__s, size_t __n)
      |                                    ~~~~~~~~~~~~^~~
  LINK    /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/bpftool
  CLANG   /tmp/build/perf/util/bpf_skel/.tmp/bpf_prog_profiler.bpf.o
  CLANG   /tmp/build/perf/util/bpf_skel/.tmp/bperf_leader.bpf.o
  CLANG   /tmp/build/perf/util/bpf_skel/.tmp/bperf_follower.bpf.o
  CLANG   /tmp/build/perf/util/bpf_skel/.tmp/bperf_cgroup.bpf.o
  CLANG   /tmp/build/perf/util/bpf_skel/.tmp/func_latency.bpf.o
  CLANG   /tmp/build/perf/util/bpf_skel/.tmp/off_cpu.bpf.o
  CLANG   /tmp/build/perf/util/bpf_skel/.tmp/lock_contention.bpf.o
  CLANG   /tmp/build/perf/util/bpf_skel/.tmp/kwork_trace.bpf.o
  CLANG   /tmp/build/perf/util/bpf_skel/.tmp/sample_filter.bpf.o
  CLANG   /tmp/build/perf/util/bpf_skel/.tmp/kwork_top.bpf.o
  CLANG   /tmp/build/perf/util/bpf_skel/.tmp/bench_uprobe.bpf.o
  CLANG   /tmp/build/perf/util/bpf_skel/.tmp/augmented_raw_syscalls.bpf.o
  GENSKEL /tmp/build/perf/util/bpf_skel/bench_uprobe.skel.h
  GENSKEL /tmp/build/perf/util/bpf_skel/func_latency.skel.h
  GENSKEL /tmp/build/perf/util/bpf_skel/bperf_follower.skel.h
  GENSKEL /tmp/build/perf/util/bpf_skel/sample_filter.skel.h
  GENSKEL /tmp/build/perf/util/bpf_skel/augmented_raw_syscalls.skel.h
  GENSKEL /tmp/build/perf/util/bpf_skel/bperf_leader.skel.h
  GENSKEL /tmp/build/perf/util/bpf_skel/kwork_top.skel.h
  GENSKEL /tmp/build/perf/util/bpf_skel/bpf_prog_profiler.skel.h
  GENSKEL /tmp/build/perf/util/bpf_skel/lock_contention.skel.h
  GENSKEL /tmp/build/perf/util/bpf_skel/off_cpu.skel.h
  GENSKEL /tmp/build/perf/util/bpf_skel/bperf_cgroup.skel.h
  GENSKEL /tmp/build/perf/util/bpf_skel/kwork_trace.skel.h
Arnaldo Carvalho de Melo Jan. 4, 2024, 1:01 p.m. UTC | #3
Em Thu, Jan 04, 2024 at 09:27:11AM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Thu, Jan 04, 2024 at 10:33:58AM +0100, Jiri Olsa escreveu:
> > 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@redhat.com>
> > > 
> > > ---
> > > 
> > > 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>
> 
> > this gives me compile warning on fedora:
> 
> Oh well, I looked at perf files and found:
> 
> ⬢[acme@toolbox perf-tools-next]$ git grep basename tools/perf
> tools/perf/builtin-daemon.c:    base = basename(basen);
> 
> And on alpine:edge:
> 
> / $ grep '\<basename(' /usr/include/*.h
> /usr/include/libgen.h:char *basename(char *);
> / $ cat /usr/include/libgen.h
> #ifndef _LIBGEN_H
> #define _LIBGEN_H
> 
> #ifdef __cplusplus
> extern "C" {
> #endif
> 
> char *dirname(char *);
> char *basename(char *);
> 
> #ifdef __cplusplus
> }
> #endif
> 
> #endif
> / $
> 
> And in tools/perf/builtin-daemon.c we have:
> 
> ⬢[acme@toolbox perf-tools-next]$ grep libgen tools/perf/builtin-daemon.c
> #include <libgen.h>
> ⬢[acme@toolbox perf-tools-next]$
> 
> And the error on alpine:
> 
> gen.c: In function 'get_obj_name':
> gen.c:60:23: warning: implicit declaration of function 'basename' [-Wimplicit-function-declaration]
>    60 |         strncpy(name, basename(file), MAX_OBJ_NAME_LEN - 1);
>       |                       ^~~~~~~~
> 
> the libgen.h include wasn't there, looks trivial.
> 
> Was late at night, thought about leaving for tomorrow for further tests
> but seemed so obvious... duh ;-)

And then...

perfbuilder@number:~$ export BUILD_TARBALL=http://192.168.86.5/perf/perf-6.7.0-rc6.tar.xz
perfbuilder@number:~$ time dm
   1    71.62 almalinux:8                   : Ok   gcc (GCC) 8.5.0 20210514 (Red Hat 8.5.0-20) , clang version 16.0.6 (Red Hat 16.0.6-2.module_el8.9.0+3621+df7f7146) flex 2.6.1
   2    71.37 almalinux:9                   : Ok   gcc (GCC) 11.4.1 20230605 (Red Hat 11.4.1-2) , clang version 16.0.6 (Red Hat 16.0.6-1.el9) flex 2.6.4
   3    87.83 alpine:3.15                   : Ok   gcc (Alpine 10.3.1_git20211027) 10.3.1 20211027 , Alpine clang version 12.0.1 flex 2.6.4
   4    83.05 alpine:3.16                   : Ok   gcc (Alpine 11.2.1_git20220219) 11.2.1 20220219 , Alpine clang version 13.0.1 flex 2.6.4
   5    74.18 alpine:3.17                   : Ok   gcc (Alpine 12.2.1_git20220924-r4) 12.2.1 20220924 , Alpine clang version 15.0.7 flex 2.6.4
   6    68.24 alpine:3.18                   : Ok   gcc (Alpine 12.2.1_git20220924-r10) 12.2.1 20220924 , Alpine clang version 16.0.6 flex 2.6.4
   7    71.32 alpine:3.19                   : Ok   gcc (Alpine 13.2.1_git20231014) 13.2.1 20231014 , Alpine clang version 17.0.5 flex 2.6.4
   8     6.91 alpine:edge                   : FAIL gcc version 13.2.1 20231014 (Alpine 13.2.1_git20231014)
       60 |         strncpy(name, basename(file), MAX_OBJ_NAME_LEN - 1);
          |                       ^~~~~~~~~~~~~~
          |                       |
          |                       int
    In file included from gen.c:13:
    /usr/include/fortify/string.h:139:48: note: expected 'const char *' but argument is of type 'int'
      139 |                                    const char *__s, size_t __n)
          |                                    ~~~~~~~~~~~~^~~
      LINK    /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/bpftool
      CLANG   /tmp/build/perf/util/bpf_skel/.tmp/bpf_prog_profiler.bpf.o
      CLANG   /tmp/build/perf/util/bpf_skel/.tmp/bperf_leader.bpf.o
      CLANG   /tmp/build/perf/util/bpf_skel/.tmp/bperf_follower.bpf.o
      CLANG   /tmp/build/perf/util/bpf_skel/.tmp/bperf_cgroup.bpf.o
      CLANG   /tmp/build/perf/util/bpf_skel/.tmp/func_latency.bpf.o
      CLANG   /tmp/build/perf/util/bpf_skel/.tmp/off_cpu.bpf.o
   9    51.66 amazonlinux:2                 : Ok   gcc (GCC) 7.3.1 20180712 (Red Hat 7.3.1-17) , clang version 11.1.0 (Amazon Linux 2 11.1.0-1.amzn2.0.2) flex 2.5.37
  10    60.77 amazonlinux:2023              : Ok   gcc (GCC) 11.4.1 20230605 (Red Hat 11.4.1-2) , clang version 15.0.7 (Amazon Linux 15.0.7-3.amzn2023.0.1) flex 2.6.4
  11    61.29 amazonlinux:devel             : Ok   gcc (GCC) 11.3.1 20221121 (Red Hat 11.3.1-4) , clang version 15.0.6 (Amazon Linux 15.0.6-3.amzn2023.0.2) flex 2.6.4
  12    74.72 archlinux:base                : Ok   gcc (GCC) 13.2.1 20230801 , clang version 16.0.6 flex 2.6.4

/ $ grep -B8 -A2 -w basename /usr/include/string.h
#ifdef _GNU_SOURCE
#define	strdupa(x)	strcpy(alloca(strlen(x)+1),x)
int strverscmp (const char *, const char *);
char *strchrnul(const char *, int);
char *strcasestr(const char *, const char *);
void *memrchr(const void *, int, size_t);
void *mempcpy(void *, const void *, size_t);
#ifndef __cplusplus
char *basename();
#endif
#endif
/ $ cat /etc/os-release
NAME="Alpine Linux"
ID=alpine
VERSION_ID=3.19.0
PRETTY_NAME="Alpine Linux v3.19"
HOME_URL="https://alpinelinux.org/"
BUG_REPORT_URL="https://gitlab.alpinelinux.org/alpine/aports/-/issues"
/ $

Weird, they had it and now removed the _GNU_SOURCE bits (edge is their
devel distro, like rawhide is for fedora, tumbleweed for opensuse, etc).

- Arnaldo
  
> > 	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?
> 
> BUILD_TARBALL_HEAD=ec5257d99e6894d65fae772ca43c53b3d6855115
> Using built-in specs.
> COLLECT_GCC=gcc
> COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-alpine-linux-musl/13.2.1/lto-wrapper
> Target: x86_64-alpine-linux-musl
> Configured with: /home/buildozer/aports/main/gcc/src/gcc-13-20231014/configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --build=x86_64-alpine-linux-musl --host=x86_64-alpine-linux-musl --target=x86_64-alpine-linux-musl --enable-checking=release --disable-cet --disable-fixed-point --disable-libstdcxx-pch --disable-multilib --disable-nls --disable-werror --disable-symvers --enable-__cxa_atexit --enable-default-pie --enable-default-ssp --enable-languages=c,c++,d,objc,go,fortran,ada --enable-link-serialization=2 --enable-linker-build-id --disable-libssp --disable-libsanitizer --enable-shared --enable-threads --enable-tls --with-bugurl=https://gitlab.alpinelinux.org/alpine/aports/-/issues --with-system-zlib --with-linker-hash-style=gnu --with-pkgversion='Alpine 13.2.1_git20231014'
> Thread model: posix
> Supported LTO compression algorithms: zlib
> gcc version 13.2.1 20231014 (Alpine 13.2.1_git20231014)
> + make 'PYTHON=python3' 'ARCH=' 'CROSS_COMPILE=' 'EXTRA_CFLAGS=' -C tools/perf 'O=/tmp/build/perf'
> make: Entering directory '/git/perf-6.7.0-rc6/tools/perf'
>   BUILD:   Doing 'make -j28' parallel build
>   HOSTCC  /tmp/build/perf/fixdep.o
>   HOSTLD  /tmp/build/perf/fixdep-in.o
>   LINK    /tmp/build/perf/fixdep
> Warning: Skipped check-headers due to missing ../../include
> Makefile.config:612: No sys/sdt.h found, no SDT events are defined, please install systemtap-sdt-devel or systemtap-sdt-dev
> Makefile.config:1093: No libbabeltrace found, disables 'perf data' CTF format support, please install libbabeltrace-dev[el]/libbabeltrace-ctf-dev
> Makefile.config:1127: No alternatives command found, you need to set JDIR= to point to the root of your Java directory
> Makefile.config:1158: libpfm4 not found, disables libpfm4 support. Please install libpfm4-dev
> 
> Auto-detecting system features:
> ...                                   dwarf: [ on  ]
> ...                      dwarf_getlocations: [ on  ]
> ...                                   glibc: [ OFF ]
> ...                                  libbfd: [ on  ]
> ...                          libbfd-buildid: [ on  ]
> ...                                  libcap: [ on  ]
> ...                                  libelf: [ on  ]
> ...                                 libnuma: [ on  ]
> ...                  numa_num_possible_cpus: [ on  ]
> ...                                 libperl: [ on  ]
> ...                               libpython: [ on  ]
> ...                               libcrypto: [ on  ]
> ...                               libunwind: [ on  ]
> ...                      libdw-dwarf-unwind: [ on  ]
> ...                                    zlib: [ on  ]
> ...                                    lzma: [ on  ]
> ...                               get_cpuid: [ on  ]
> ...                                     bpf: [ on  ]
> ...                                  libaio: [ on  ]
> ...                                 libzstd: [ on  ]
> 
>   GEN     /tmp/build/perf/common-cmds.h
>   PERF_VERSION = 6.7.rc6.gec5257d99e68
>   GEN     perf-archive
>   GEN     perf-iostat
>   CC      /tmp/build/perf/dlfilters/dlfilter-test-api-v2.o
>   CC      /tmp/build/perf/dlfilters/dlfilter-test-api-v0.o
>   CC      /tmp/build/perf/dlfilters/dlfilter-show-cycles.o
>   GEN     /tmp/build/perf/arch/arm64/include/generated/asm/sysreg-defs.h
>   INSTALL /tmp/build/perf/libsubcmd/include/subcmd/exec-cmd.h
>   INSTALL /tmp/build/perf/libsubcmd/include/subcmd/help.h
>   INSTALL /tmp/build/perf/libsubcmd/include/subcmd/pager.h
>   INSTALL /tmp/build/perf/libsubcmd/include/subcmd/parse-options.h
>   INSTALL /tmp/build/perf/libsubcmd/include/subcmd/run-command.h
>   CC      /tmp/build/perf/libsubcmd/exec-cmd.o
>   INSTALL libsubcmd_headers
>   CC      /tmp/build/perf/libsubcmd/help.o
>   CC      /tmp/build/perf/libsubcmd/pager.o
>   CC      /tmp/build/perf/libsubcmd/parse-options.o
>   CC      /tmp/build/perf/libsubcmd/run-command.o
>   CC      /tmp/build/perf/libsubcmd/sigchain.o
>   CC      /tmp/build/perf/libsubcmd/subcmd-config.o
>   INSTALL /tmp/build/perf/libsymbol/include/symbol/kallsyms.h
>   CC      /tmp/build/perf/libsymbol/kallsyms.o
>   INSTALL libsymbol_headers
>   INSTALL /tmp/build/perf/libperf/include/perf/bpf_perf.h
>   INSTALL /tmp/build/perf/libperf/include/perf/core.h
>   INSTALL /tmp/build/perf/libperf/include/perf/cpumap.h
>   GEN     /tmp/build/perf/libbpf/bpf_helper_defs.h
>   INSTALL /tmp/build/perf/libperf/include/perf/threadmap.h
>   INSTALL /tmp/build/perf/libbpf/include/bpf/bpf.h
>   INSTALL /tmp/build/perf/libperf/include/perf/evlist.h
>   INSTALL /tmp/build/perf/libperf/include/perf/evsel.h
>   CC      /tmp/build/perf/libperf/core.o
>   INSTALL /tmp/build/perf/libperf/include/perf/event.h
>   INSTALL /tmp/build/perf/libperf/include/perf/mmap.h
>   INSTALL /tmp/build/perf/libbpf/include/bpf/libbpf.h
>   INSTALL /tmp/build/perf/libapi/include/api/cpu.h
>   CC      /tmp/build/perf/libperf/cpumap.o
>   INSTALL /tmp/build/perf/libapi/include/api/debug.h
>   INSTALL /tmp/build/perf/libapi/include/api/io.h
>   CC      /tmp/build/perf/libperf/threadmap.o
>   INSTALL /tmp/build/perf/libapi/include/api/fd/array.h
>   MKDIR   /tmp/build/perf/libapi/fd/
>   CC      /tmp/build/perf/libperf/evsel.o
>   LINK    /tmp/build/perf/dlfilters/dlfilter-show-cycles.so
>   CC      /tmp/build/perf/libapi/fd/array.o
>   INSTALL /tmp/build/perf/libbpf/include/bpf/btf.h
>   INSTALL /tmp/build/perf/libbpf/include/bpf/libbpf_common.h
>   MKDIR   /tmp/build/perf/libapi/fs/
>   CC      /tmp/build/perf/libapi/fs/fs.o
>   INSTALL /tmp/build/perf/libperf/include/internal/cpumap.h
>   INSTALL /tmp/build/perf/libperf/include/internal/evlist.h
>   CC      /tmp/build/perf/libperf/evlist.o
>   INSTALL /tmp/build/perf/libapi/include/api/fs/fs.h
>   INSTALL /tmp/build/perf/libperf/include/internal/evsel.h
>   CC      /tmp/build/perf/libperf/mmap.o
>   INSTALL /tmp/build/perf/libapi/include/api/fs/tracing_path.h
>   CC      /tmp/build/perf/libperf/zalloc.o
>   INSTALL libapi_headers
>   MKDIR   /tmp/build/perf/libapi/fs/
>   INSTALL /tmp/build/perf/libperf/include/internal/lib.h
>   CC      /tmp/build/perf/libapi/fs/tracing_path.o
>   CC      /tmp/build/perf/libapi/fs/cgroup.o
>   INSTALL /tmp/build/perf/libperf/include/internal/mmap.h
>   INSTALL /tmp/build/perf/libperf/include/internal/rc_check.h
>   INSTALL /tmp/build/perf/libperf/include/internal/threadmap.h
>   INSTALL /tmp/build/perf/libperf/include/internal/xyarray.h
>   INSTALL libperf_headers
>   LINK    /tmp/build/perf/dlfilters/dlfilter-test-api-v0.so
>   CC      /tmp/build/perf/libperf/xyarray.o
>   LINK    /tmp/build/perf/dlfilters/dlfilter-test-api-v2.so
>   CC      /tmp/build/perf/libperf/lib.o
>   CC      /tmp/build/perf/libapi/cpu.o
>   INSTALL /tmp/build/perf/libbpf/include/bpf/libbpf_legacy.h
>   INSTALL /tmp/build/perf/libbpf/include/bpf/bpf_helpers.h
>   INSTALL /tmp/build/perf/libbpf/include/bpf/bpf_tracing.h
>   CC      /tmp/build/perf/libapi/debug.o
>   INSTALL /tmp/build/perf/libbpf/include/bpf/bpf_endian.h
>   INSTALL /tmp/build/perf/libbpf/include/bpf/bpf_core_read.h
>   INSTALL /tmp/build/perf/libbpf/include/bpf/skel_internal.h
>   INSTALL /tmp/build/perf/libbpf/include/bpf/libbpf_version.h
>   INSTALL /tmp/build/perf/libbpf/include/bpf/usdt.bpf.h
>   CC      /tmp/build/perf/libapi/str_error_r.o
>   LD      /tmp/build/perf/libapi/fd/libapi-in.o
>   INSTALL /tmp/build/perf/libbpf/include/bpf/bpf_helper_defs.h
>   INSTALL libbpf_headers
>   MKDIR   /tmp/build/perf/libbpf/staticobjs/
>   CC      /tmp/build/perf/libbpf/staticobjs/libbpf.o
>   MKDIR   /tmp/build/perf/libbpf/staticobjs/
>   CC      /tmp/build/perf/libbpf/staticobjs/bpf.o
>   CC      /tmp/build/perf/libbpf/staticobjs/nlattr.o
>   CC      /tmp/build/perf/libbpf/staticobjs/btf.o
>   CC      /tmp/build/perf/libbpf/staticobjs/libbpf_errno.o
>   CC      /tmp/build/perf/libbpf/staticobjs/str_error.o
>   CC      /tmp/build/perf/libbpf/staticobjs/netlink.o
>   CC      /tmp/build/perf/libbpf/staticobjs/bpf_prog_linfo.o
>   CC      /tmp/build/perf/libbpf/staticobjs/libbpf_probes.o
>   CC      /tmp/build/perf/libbpf/staticobjs/hashmap.o
>   CC      /tmp/build/perf/libbpf/staticobjs/btf_dump.o
>   CC      /tmp/build/perf/libbpf/staticobjs/ringbuf.o
>   CC      /tmp/build/perf/libbpf/staticobjs/strset.o
>   CC      /tmp/build/perf/libbpf/staticobjs/linker.o
>   LD      /tmp/build/perf/libsymbol/libsymbol-in.o
>   AR      /tmp/build/perf/libsymbol/libsymbol.a
>   CC      /tmp/build/perf/libbpf/staticobjs/gen_loader.o
>   CC      /tmp/build/perf/libbpf/staticobjs/relo_core.o
>   CC      /tmp/build/perf/libbpf/staticobjs/usdt.o
>   CC      /tmp/build/perf/libbpf/staticobjs/zip.o
>   CC      /tmp/build/perf/libbpf/staticobjs/elf.o
>   LD      /tmp/build/perf/libapi/fs/libapi-in.o
>   LD      /tmp/build/perf/libapi/libapi-in.o
>   LD      /tmp/build/perf/libperf/libperf-in.o
>   AR      /tmp/build/perf/libapi/libapi.a
>   AR      /tmp/build/perf/libperf/libperf.a
>   LD      /tmp/build/perf/libsubcmd/libsubcmd-in.o
>   AR      /tmp/build/perf/libsubcmd/libsubcmd.a
>   GEN     /tmp/build/perf/python/perf.cpython-311-x86_64-linux-musl.so
> 
> Auto-detecting system features:
> ...                         clang-bpf-co-re: [ on  ]
> ...                                    llvm: [ on  ]
> ...                                  libcap: [ on  ]
> ...                                  libbfd: [ on  ]
> 
>   MKDIR   /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/include/bpf
>   MKDIR   /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/
>   MKDIR   /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/
>   INSTALL /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/include/bpf/hashmap.h
>   INSTALL /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/include/bpf/relo_core.h
>   INSTALL /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/include/bpf/libbpf_internal.h
>   GEN     /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/bpf_helper_defs.h
>   INSTALL /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/include/bpf/bpf.h
>   INSTALL /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/include/bpf/libbpf.h
>   INSTALL /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/include/bpf/btf.h
>   INSTALL /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/include/bpf/libbpf_common.h
>   INSTALL /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/include/bpf/libbpf_legacy.h
>   INSTALL /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/include/bpf/bpf_helpers.h
>   INSTALL /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/include/bpf/bpf_tracing.h
>   INSTALL /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/include/bpf/bpf_endian.h
>   INSTALL /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/include/bpf/bpf_core_read.h
>   INSTALL /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/include/bpf/skel_internal.h
>   INSTALL /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/include/bpf/libbpf_version.h
>   INSTALL /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/include/bpf/usdt.bpf.h
>   INSTALL /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/include/bpf/bpf_helper_defs.h
>   INSTALL libbpf_headers
>   MKDIR   /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/
>   MKDIR   /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/
>   CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/libbpf.o
>   CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/nlattr.o
>   CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/bpf.o
>   CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/btf.o
>   CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/libbpf_errno.o
>   CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/str_error.o
>   CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/netlink.o
>   CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/bpf_prog_linfo.o
>   CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/libbpf_probes.o
>   CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/hashmap.o
>   CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/btf_dump.o
>   CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/ringbuf.o
>   CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/strset.o
>   CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/linker.o
>   CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/gen_loader.o
>   CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/relo_core.o
>   CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/usdt.o
>   CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/zip.o
>   CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/elf.o
>   LD      /tmp/build/perf/libbpf/staticobjs/libbpf-in.o
>   LINK    /tmp/build/perf/libbpf/libbpf.a
>   LD      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/libbpf-in.o
>   LINK    /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/libbpf.a
>   CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/main.o
>   CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/common.o
>   CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/json_writer.o
>   CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/gen.o
>   CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/btf.o
>   CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/xlated_dumper.o
>   CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/btf_dumper.o
>   CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/disasm.o
> gen.c: In function 'get_obj_name':
> gen.c:60:23: warning: implicit declaration of function 'basename' [-Wimplicit-function-declaration]
>    60 |         strncpy(name, basename(file), MAX_OBJ_NAME_LEN - 1);
>       |                       ^~~~~~~~
> gen.c:60:23: warning: passing argument 2 of 'strncpy' makes pointer from integer without a cast [-Wint-conversion]
>    60 |         strncpy(name, basename(file), MAX_OBJ_NAME_LEN - 1);
>       |                       ^~~~~~~~~~~~~~
>       |                       |
>       |                       int
> In file included from gen.c:13:
> /usr/include/fortify/string.h:139:48: note: expected 'const char *' but argument is of type 'int'
>   139 |                                    const char *__s, size_t __n)
>       |                                    ~~~~~~~~~~~~^~~
>   LINK    /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/bpftool
>   CLANG   /tmp/build/perf/util/bpf_skel/.tmp/bpf_prog_profiler.bpf.o
>   CLANG   /tmp/build/perf/util/bpf_skel/.tmp/bperf_leader.bpf.o
>   CLANG   /tmp/build/perf/util/bpf_skel/.tmp/bperf_follower.bpf.o
>   CLANG   /tmp/build/perf/util/bpf_skel/.tmp/bperf_cgroup.bpf.o
>   CLANG   /tmp/build/perf/util/bpf_skel/.tmp/func_latency.bpf.o
>   CLANG   /tmp/build/perf/util/bpf_skel/.tmp/off_cpu.bpf.o
>   CLANG   /tmp/build/perf/util/bpf_skel/.tmp/lock_contention.bpf.o
>   CLANG   /tmp/build/perf/util/bpf_skel/.tmp/kwork_trace.bpf.o
>   CLANG   /tmp/build/perf/util/bpf_skel/.tmp/sample_filter.bpf.o
>   CLANG   /tmp/build/perf/util/bpf_skel/.tmp/kwork_top.bpf.o
>   CLANG   /tmp/build/perf/util/bpf_skel/.tmp/bench_uprobe.bpf.o
>   CLANG   /tmp/build/perf/util/bpf_skel/.tmp/augmented_raw_syscalls.bpf.o
>   GENSKEL /tmp/build/perf/util/bpf_skel/bench_uprobe.skel.h
>   GENSKEL /tmp/build/perf/util/bpf_skel/func_latency.skel.h
>   GENSKEL /tmp/build/perf/util/bpf_skel/bperf_follower.skel.h
>   GENSKEL /tmp/build/perf/util/bpf_skel/sample_filter.skel.h
>   GENSKEL /tmp/build/perf/util/bpf_skel/augmented_raw_syscalls.skel.h
>   GENSKEL /tmp/build/perf/util/bpf_skel/bperf_leader.skel.h
>   GENSKEL /tmp/build/perf/util/bpf_skel/kwork_top.skel.h
>   GENSKEL /tmp/build/perf/util/bpf_skel/bpf_prog_profiler.skel.h
>   GENSKEL /tmp/build/perf/util/bpf_skel/lock_contention.skel.h
>   GENSKEL /tmp/build/perf/util/bpf_skel/off_cpu.skel.h
>   GENSKEL /tmp/build/perf/util/bpf_skel/bperf_cgroup.skel.h
>   GENSKEL /tmp/build/perf/util/bpf_skel/kwork_trace.skel.h
>
Jiri Olsa Jan. 5, 2024, 8:48 a.m. UTC | #4
On Thu, Jan 04, 2024 at 10:01:35AM -0300, Arnaldo Carvalho de Melo wrote:

SNIP

>    9    51.66 amazonlinux:2                 : Ok   gcc (GCC) 7.3.1 20180712 (Red Hat 7.3.1-17) , clang version 11.1.0 (Amazon Linux 2 11.1.0-1.amzn2.0.2) flex 2.5.37
>   10    60.77 amazonlinux:2023              : Ok   gcc (GCC) 11.4.1 20230605 (Red Hat 11.4.1-2) , clang version 15.0.7 (Amazon Linux 15.0.7-3.amzn2023.0.1) flex 2.6.4
>   11    61.29 amazonlinux:devel             : Ok   gcc (GCC) 11.3.1 20221121 (Red Hat 11.3.1-4) , clang version 15.0.6 (Amazon Linux 15.0.6-3.amzn2023.0.2) flex 2.6.4
>   12    74.72 archlinux:base                : Ok   gcc (GCC) 13.2.1 20230801 , clang version 16.0.6 flex 2.6.4
> 
> / $ grep -B8 -A2 -w basename /usr/include/string.h
> #ifdef _GNU_SOURCE
> #define	strdupa(x)	strcpy(alloca(strlen(x)+1),x)
> int strverscmp (const char *, const char *);
> char *strchrnul(const char *, int);
> char *strcasestr(const char *, const char *);
> void *memrchr(const void *, int, size_t);
> void *mempcpy(void *, const void *, size_t);
> #ifndef __cplusplus
> char *basename();
> #endif
> #endif
> / $ cat /etc/os-release
> NAME="Alpine Linux"
> ID=alpine
> VERSION_ID=3.19.0
> PRETTY_NAME="Alpine Linux v3.19"
> HOME_URL="https://alpinelinux.org/"
> BUG_REPORT_URL="https://gitlab.alpinelinux.org/alpine/aports/-/issues"
> / $
> 
> Weird, they had it and now removed the _GNU_SOURCE bits (edge is their
> devel distro, like rawhide is for fedora, tumbleweed for opensuse, etc).

let's see, I asked them in here: https://gitlab.alpinelinux.org/alpine/aports/-/issues/15643

jirka

> 
> - Arnaldo
>   
> > > 	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?
> > 
> > BUILD_TARBALL_HEAD=ec5257d99e6894d65fae772ca43c53b3d6855115
> > Using built-in specs.
> > COLLECT_GCC=gcc
> > COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-alpine-linux-musl/13.2.1/lto-wrapper
> > Target: x86_64-alpine-linux-musl
> > Configured with: /home/buildozer/aports/main/gcc/src/gcc-13-20231014/configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --build=x86_64-alpine-linux-musl --host=x86_64-alpine-linux-musl --target=x86_64-alpine-linux-musl --enable-checking=release --disable-cet --disable-fixed-point --disable-libstdcxx-pch --disable-multilib --disable-nls --disable-werror --disable-symvers --enable-__cxa_atexit --enable-default-pie --enable-default-ssp --enable-languages=c,c++,d,objc,go,fortran,ada --enable-link-serialization=2 --enable-linker-build-id --disable-libssp --disable-libsanitizer --enable-shared --enable-threads --enable-tls --with-bugurl=https://gitlab.alpinelinux.org/alpine/aports/-/issues --with-system-zlib --with-linker-hash-style=gnu --with-pkgversion='Alpine 13.2.1_git20231014'
> > Thread model: posix
> > Supported LTO compression algorithms: zlib
> > gcc version 13.2.1 20231014 (Alpine 13.2.1_git20231014)
> > + make 'PYTHON=python3' 'ARCH=' 'CROSS_COMPILE=' 'EXTRA_CFLAGS=' -C tools/perf 'O=/tmp/build/perf'
> > make: Entering directory '/git/perf-6.7.0-rc6/tools/perf'
> >   BUILD:   Doing 'make -j28' parallel build
> >   HOSTCC  /tmp/build/perf/fixdep.o
> >   HOSTLD  /tmp/build/perf/fixdep-in.o
> >   LINK    /tmp/build/perf/fixdep
> > Warning: Skipped check-headers due to missing ../../include
> > Makefile.config:612: No sys/sdt.h found, no SDT events are defined, please install systemtap-sdt-devel or systemtap-sdt-dev
> > Makefile.config:1093: No libbabeltrace found, disables 'perf data' CTF format support, please install libbabeltrace-dev[el]/libbabeltrace-ctf-dev
> > Makefile.config:1127: No alternatives command found, you need to set JDIR= to point to the root of your Java directory
> > Makefile.config:1158: libpfm4 not found, disables libpfm4 support. Please install libpfm4-dev
> > 
> > Auto-detecting system features:
> > ...                                   dwarf: [ on  ]
> > ...                      dwarf_getlocations: [ on  ]
> > ...                                   glibc: [ OFF ]
> > ...                                  libbfd: [ on  ]
> > ...                          libbfd-buildid: [ on  ]
> > ...                                  libcap: [ on  ]
> > ...                                  libelf: [ on  ]
> > ...                                 libnuma: [ on  ]
> > ...                  numa_num_possible_cpus: [ on  ]
> > ...                                 libperl: [ on  ]
> > ...                               libpython: [ on  ]
> > ...                               libcrypto: [ on  ]
> > ...                               libunwind: [ on  ]
> > ...                      libdw-dwarf-unwind: [ on  ]
> > ...                                    zlib: [ on  ]
> > ...                                    lzma: [ on  ]
> > ...                               get_cpuid: [ on  ]
> > ...                                     bpf: [ on  ]
> > ...                                  libaio: [ on  ]
> > ...                                 libzstd: [ on  ]
> > 
> >   GEN     /tmp/build/perf/common-cmds.h
> >   PERF_VERSION = 6.7.rc6.gec5257d99e68
> >   GEN     perf-archive
> >   GEN     perf-iostat
> >   CC      /tmp/build/perf/dlfilters/dlfilter-test-api-v2.o
> >   CC      /tmp/build/perf/dlfilters/dlfilter-test-api-v0.o
> >   CC      /tmp/build/perf/dlfilters/dlfilter-show-cycles.o
> >   GEN     /tmp/build/perf/arch/arm64/include/generated/asm/sysreg-defs.h
> >   INSTALL /tmp/build/perf/libsubcmd/include/subcmd/exec-cmd.h
> >   INSTALL /tmp/build/perf/libsubcmd/include/subcmd/help.h
> >   INSTALL /tmp/build/perf/libsubcmd/include/subcmd/pager.h
> >   INSTALL /tmp/build/perf/libsubcmd/include/subcmd/parse-options.h
> >   INSTALL /tmp/build/perf/libsubcmd/include/subcmd/run-command.h
> >   CC      /tmp/build/perf/libsubcmd/exec-cmd.o
> >   INSTALL libsubcmd_headers
> >   CC      /tmp/build/perf/libsubcmd/help.o
> >   CC      /tmp/build/perf/libsubcmd/pager.o
> >   CC      /tmp/build/perf/libsubcmd/parse-options.o
> >   CC      /tmp/build/perf/libsubcmd/run-command.o
> >   CC      /tmp/build/perf/libsubcmd/sigchain.o
> >   CC      /tmp/build/perf/libsubcmd/subcmd-config.o
> >   INSTALL /tmp/build/perf/libsymbol/include/symbol/kallsyms.h
> >   CC      /tmp/build/perf/libsymbol/kallsyms.o
> >   INSTALL libsymbol_headers
> >   INSTALL /tmp/build/perf/libperf/include/perf/bpf_perf.h
> >   INSTALL /tmp/build/perf/libperf/include/perf/core.h
> >   INSTALL /tmp/build/perf/libperf/include/perf/cpumap.h
> >   GEN     /tmp/build/perf/libbpf/bpf_helper_defs.h
> >   INSTALL /tmp/build/perf/libperf/include/perf/threadmap.h
> >   INSTALL /tmp/build/perf/libbpf/include/bpf/bpf.h
> >   INSTALL /tmp/build/perf/libperf/include/perf/evlist.h
> >   INSTALL /tmp/build/perf/libperf/include/perf/evsel.h
> >   CC      /tmp/build/perf/libperf/core.o
> >   INSTALL /tmp/build/perf/libperf/include/perf/event.h
> >   INSTALL /tmp/build/perf/libperf/include/perf/mmap.h
> >   INSTALL /tmp/build/perf/libbpf/include/bpf/libbpf.h
> >   INSTALL /tmp/build/perf/libapi/include/api/cpu.h
> >   CC      /tmp/build/perf/libperf/cpumap.o
> >   INSTALL /tmp/build/perf/libapi/include/api/debug.h
> >   INSTALL /tmp/build/perf/libapi/include/api/io.h
> >   CC      /tmp/build/perf/libperf/threadmap.o
> >   INSTALL /tmp/build/perf/libapi/include/api/fd/array.h
> >   MKDIR   /tmp/build/perf/libapi/fd/
> >   CC      /tmp/build/perf/libperf/evsel.o
> >   LINK    /tmp/build/perf/dlfilters/dlfilter-show-cycles.so
> >   CC      /tmp/build/perf/libapi/fd/array.o
> >   INSTALL /tmp/build/perf/libbpf/include/bpf/btf.h
> >   INSTALL /tmp/build/perf/libbpf/include/bpf/libbpf_common.h
> >   MKDIR   /tmp/build/perf/libapi/fs/
> >   CC      /tmp/build/perf/libapi/fs/fs.o
> >   INSTALL /tmp/build/perf/libperf/include/internal/cpumap.h
> >   INSTALL /tmp/build/perf/libperf/include/internal/evlist.h
> >   CC      /tmp/build/perf/libperf/evlist.o
> >   INSTALL /tmp/build/perf/libapi/include/api/fs/fs.h
> >   INSTALL /tmp/build/perf/libperf/include/internal/evsel.h
> >   CC      /tmp/build/perf/libperf/mmap.o
> >   INSTALL /tmp/build/perf/libapi/include/api/fs/tracing_path.h
> >   CC      /tmp/build/perf/libperf/zalloc.o
> >   INSTALL libapi_headers
> >   MKDIR   /tmp/build/perf/libapi/fs/
> >   INSTALL /tmp/build/perf/libperf/include/internal/lib.h
> >   CC      /tmp/build/perf/libapi/fs/tracing_path.o
> >   CC      /tmp/build/perf/libapi/fs/cgroup.o
> >   INSTALL /tmp/build/perf/libperf/include/internal/mmap.h
> >   INSTALL /tmp/build/perf/libperf/include/internal/rc_check.h
> >   INSTALL /tmp/build/perf/libperf/include/internal/threadmap.h
> >   INSTALL /tmp/build/perf/libperf/include/internal/xyarray.h
> >   INSTALL libperf_headers
> >   LINK    /tmp/build/perf/dlfilters/dlfilter-test-api-v0.so
> >   CC      /tmp/build/perf/libperf/xyarray.o
> >   LINK    /tmp/build/perf/dlfilters/dlfilter-test-api-v2.so
> >   CC      /tmp/build/perf/libperf/lib.o
> >   CC      /tmp/build/perf/libapi/cpu.o
> >   INSTALL /tmp/build/perf/libbpf/include/bpf/libbpf_legacy.h
> >   INSTALL /tmp/build/perf/libbpf/include/bpf/bpf_helpers.h
> >   INSTALL /tmp/build/perf/libbpf/include/bpf/bpf_tracing.h
> >   CC      /tmp/build/perf/libapi/debug.o
> >   INSTALL /tmp/build/perf/libbpf/include/bpf/bpf_endian.h
> >   INSTALL /tmp/build/perf/libbpf/include/bpf/bpf_core_read.h
> >   INSTALL /tmp/build/perf/libbpf/include/bpf/skel_internal.h
> >   INSTALL /tmp/build/perf/libbpf/include/bpf/libbpf_version.h
> >   INSTALL /tmp/build/perf/libbpf/include/bpf/usdt.bpf.h
> >   CC      /tmp/build/perf/libapi/str_error_r.o
> >   LD      /tmp/build/perf/libapi/fd/libapi-in.o
> >   INSTALL /tmp/build/perf/libbpf/include/bpf/bpf_helper_defs.h
> >   INSTALL libbpf_headers
> >   MKDIR   /tmp/build/perf/libbpf/staticobjs/
> >   CC      /tmp/build/perf/libbpf/staticobjs/libbpf.o
> >   MKDIR   /tmp/build/perf/libbpf/staticobjs/
> >   CC      /tmp/build/perf/libbpf/staticobjs/bpf.o
> >   CC      /tmp/build/perf/libbpf/staticobjs/nlattr.o
> >   CC      /tmp/build/perf/libbpf/staticobjs/btf.o
> >   CC      /tmp/build/perf/libbpf/staticobjs/libbpf_errno.o
> >   CC      /tmp/build/perf/libbpf/staticobjs/str_error.o
> >   CC      /tmp/build/perf/libbpf/staticobjs/netlink.o
> >   CC      /tmp/build/perf/libbpf/staticobjs/bpf_prog_linfo.o
> >   CC      /tmp/build/perf/libbpf/staticobjs/libbpf_probes.o
> >   CC      /tmp/build/perf/libbpf/staticobjs/hashmap.o
> >   CC      /tmp/build/perf/libbpf/staticobjs/btf_dump.o
> >   CC      /tmp/build/perf/libbpf/staticobjs/ringbuf.o
> >   CC      /tmp/build/perf/libbpf/staticobjs/strset.o
> >   CC      /tmp/build/perf/libbpf/staticobjs/linker.o
> >   LD      /tmp/build/perf/libsymbol/libsymbol-in.o
> >   AR      /tmp/build/perf/libsymbol/libsymbol.a
> >   CC      /tmp/build/perf/libbpf/staticobjs/gen_loader.o
> >   CC      /tmp/build/perf/libbpf/staticobjs/relo_core.o
> >   CC      /tmp/build/perf/libbpf/staticobjs/usdt.o
> >   CC      /tmp/build/perf/libbpf/staticobjs/zip.o
> >   CC      /tmp/build/perf/libbpf/staticobjs/elf.o
> >   LD      /tmp/build/perf/libapi/fs/libapi-in.o
> >   LD      /tmp/build/perf/libapi/libapi-in.o
> >   LD      /tmp/build/perf/libperf/libperf-in.o
> >   AR      /tmp/build/perf/libapi/libapi.a
> >   AR      /tmp/build/perf/libperf/libperf.a
> >   LD      /tmp/build/perf/libsubcmd/libsubcmd-in.o
> >   AR      /tmp/build/perf/libsubcmd/libsubcmd.a
> >   GEN     /tmp/build/perf/python/perf.cpython-311-x86_64-linux-musl.so
> > 
> > Auto-detecting system features:
> > ...                         clang-bpf-co-re: [ on  ]
> > ...                                    llvm: [ on  ]
> > ...                                  libcap: [ on  ]
> > ...                                  libbfd: [ on  ]
> > 
> >   MKDIR   /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/include/bpf
> >   MKDIR   /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/
> >   MKDIR   /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/
> >   INSTALL /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/include/bpf/hashmap.h
> >   INSTALL /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/include/bpf/relo_core.h
> >   INSTALL /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/include/bpf/libbpf_internal.h
> >   GEN     /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/bpf_helper_defs.h
> >   INSTALL /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/include/bpf/bpf.h
> >   INSTALL /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/include/bpf/libbpf.h
> >   INSTALL /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/include/bpf/btf.h
> >   INSTALL /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/include/bpf/libbpf_common.h
> >   INSTALL /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/include/bpf/libbpf_legacy.h
> >   INSTALL /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/include/bpf/bpf_helpers.h
> >   INSTALL /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/include/bpf/bpf_tracing.h
> >   INSTALL /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/include/bpf/bpf_endian.h
> >   INSTALL /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/include/bpf/bpf_core_read.h
> >   INSTALL /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/include/bpf/skel_internal.h
> >   INSTALL /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/include/bpf/libbpf_version.h
> >   INSTALL /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/include/bpf/usdt.bpf.h
> >   INSTALL /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/include/bpf/bpf_helper_defs.h
> >   INSTALL libbpf_headers
> >   MKDIR   /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/
> >   MKDIR   /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/
> >   CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/libbpf.o
> >   CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/nlattr.o
> >   CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/bpf.o
> >   CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/btf.o
> >   CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/libbpf_errno.o
> >   CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/str_error.o
> >   CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/netlink.o
> >   CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/bpf_prog_linfo.o
> >   CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/libbpf_probes.o
> >   CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/hashmap.o
> >   CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/btf_dump.o
> >   CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/ringbuf.o
> >   CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/strset.o
> >   CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/linker.o
> >   CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/gen_loader.o
> >   CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/relo_core.o
> >   CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/usdt.o
> >   CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/zip.o
> >   CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/elf.o
> >   LD      /tmp/build/perf/libbpf/staticobjs/libbpf-in.o
> >   LINK    /tmp/build/perf/libbpf/libbpf.a
> >   LD      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/staticobjs/libbpf-in.o
> >   LINK    /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/libbpf/libbpf.a
> >   CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/main.o
> >   CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/common.o
> >   CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/json_writer.o
> >   CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/gen.o
> >   CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/btf.o
> >   CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/xlated_dumper.o
> >   CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/btf_dumper.o
> >   CC      /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/disasm.o
> > gen.c: In function 'get_obj_name':
> > gen.c:60:23: warning: implicit declaration of function 'basename' [-Wimplicit-function-declaration]
> >    60 |         strncpy(name, basename(file), MAX_OBJ_NAME_LEN - 1);
> >       |                       ^~~~~~~~
> > gen.c:60:23: warning: passing argument 2 of 'strncpy' makes pointer from integer without a cast [-Wint-conversion]
> >    60 |         strncpy(name, basename(file), MAX_OBJ_NAME_LEN - 1);
> >       |                       ^~~~~~~~~~~~~~
> >       |                       |
> >       |                       int
> > In file included from gen.c:13:
> > /usr/include/fortify/string.h:139:48: note: expected 'const char *' but argument is of type 'int'
> >   139 |                                    const char *__s, size_t __n)
> >       |                                    ~~~~~~~~~~~~^~~
> >   LINK    /tmp/build/perf/util/bpf_skel/.tmp/bootstrap/bpftool
> >   CLANG   /tmp/build/perf/util/bpf_skel/.tmp/bpf_prog_profiler.bpf.o
> >   CLANG   /tmp/build/perf/util/bpf_skel/.tmp/bperf_leader.bpf.o
> >   CLANG   /tmp/build/perf/util/bpf_skel/.tmp/bperf_follower.bpf.o
> >   CLANG   /tmp/build/perf/util/bpf_skel/.tmp/bperf_cgroup.bpf.o
> >   CLANG   /tmp/build/perf/util/bpf_skel/.tmp/func_latency.bpf.o
> >   CLANG   /tmp/build/perf/util/bpf_skel/.tmp/off_cpu.bpf.o
> >   CLANG   /tmp/build/perf/util/bpf_skel/.tmp/lock_contention.bpf.o
> >   CLANG   /tmp/build/perf/util/bpf_skel/.tmp/kwork_trace.bpf.o
> >   CLANG   /tmp/build/perf/util/bpf_skel/.tmp/sample_filter.bpf.o
> >   CLANG   /tmp/build/perf/util/bpf_skel/.tmp/kwork_top.bpf.o
> >   CLANG   /tmp/build/perf/util/bpf_skel/.tmp/bench_uprobe.bpf.o
> >   CLANG   /tmp/build/perf/util/bpf_skel/.tmp/augmented_raw_syscalls.bpf.o
> >   GENSKEL /tmp/build/perf/util/bpf_skel/bench_uprobe.skel.h
> >   GENSKEL /tmp/build/perf/util/bpf_skel/func_latency.skel.h
> >   GENSKEL /tmp/build/perf/util/bpf_skel/bperf_follower.skel.h
> >   GENSKEL /tmp/build/perf/util/bpf_skel/sample_filter.skel.h
> >   GENSKEL /tmp/build/perf/util/bpf_skel/augmented_raw_syscalls.skel.h
> >   GENSKEL /tmp/build/perf/util/bpf_skel/bperf_leader.skel.h
> >   GENSKEL /tmp/build/perf/util/bpf_skel/kwork_top.skel.h
> >   GENSKEL /tmp/build/perf/util/bpf_skel/bpf_prog_profiler.skel.h
> >   GENSKEL /tmp/build/perf/util/bpf_skel/lock_contention.skel.h
> >   GENSKEL /tmp/build/perf/util/bpf_skel/off_cpu.skel.h
> >   GENSKEL /tmp/build/perf/util/bpf_skel/bperf_cgroup.skel.h
> >   GENSKEL /tmp/build/perf/util/bpf_skel/kwork_trace.skel.h
> > 
> 
> -- 
> 
> - Arnaldo
Jiri Olsa Jan. 5, 2024, 3:01 p.m. UTC | #5
On Fri, Jan 05, 2024 at 09:48:31AM +0100, Jiri Olsa wrote:
> On Thu, Jan 04, 2024 at 10:01:35AM -0300, Arnaldo Carvalho de Melo wrote:
> 
> SNIP
> 
> >    9    51.66 amazonlinux:2                 : Ok   gcc (GCC) 7.3.1 20180712 (Red Hat 7.3.1-17) , clang version 11.1.0 (Amazon Linux 2 11.1.0-1.amzn2.0.2) flex 2.5.37
> >   10    60.77 amazonlinux:2023              : Ok   gcc (GCC) 11.4.1 20230605 (Red Hat 11.4.1-2) , clang version 15.0.7 (Amazon Linux 15.0.7-3.amzn2023.0.1) flex 2.6.4
> >   11    61.29 amazonlinux:devel             : Ok   gcc (GCC) 11.3.1 20221121 (Red Hat 11.3.1-4) , clang version 15.0.6 (Amazon Linux 15.0.6-3.amzn2023.0.2) flex 2.6.4
> >   12    74.72 archlinux:base                : Ok   gcc (GCC) 13.2.1 20230801 , clang version 16.0.6 flex 2.6.4
> > 
> > / $ grep -B8 -A2 -w basename /usr/include/string.h
> > #ifdef _GNU_SOURCE
> > #define	strdupa(x)	strcpy(alloca(strlen(x)+1),x)
> > int strverscmp (const char *, const char *);
> > char *strchrnul(const char *, int);
> > char *strcasestr(const char *, const char *);
> > void *memrchr(const void *, int, size_t);
> > void *mempcpy(void *, const void *, size_t);
> > #ifndef __cplusplus
> > char *basename();
> > #endif
> > #endif
> > / $ cat /etc/os-release
> > NAME="Alpine Linux"
> > ID=alpine
> > VERSION_ID=3.19.0
> > PRETTY_NAME="Alpine Linux v3.19"
> > HOME_URL="https://alpinelinux.org/"
> > BUG_REPORT_URL="https://gitlab.alpinelinux.org/alpine/aports/-/issues"
> > / $
> > 
> > Weird, they had it and now removed the _GNU_SOURCE bits (edge is their
> > devel distro, like rawhide is for fedora, tumbleweed for opensuse, etc).
> 
> let's see, I asked them in here: https://gitlab.alpinelinux.org/alpine/aports/-/issues/15643

it got removed in musl libc recently:
  https://git.musl-libc.org/cgit/musl/commit/?id=725e17ed6dff4d0cd22487bb64470881e86a92e7

so perhaps switching to POSIX version of basename is the easiest way out?

jirka
Arnaldo Carvalho de Melo Jan. 5, 2024, 8:53 p.m. UTC | #6
Em Fri, Jan 05, 2024 at 04:01:37PM +0100, Jiri Olsa escreveu:
> On Fri, Jan 05, 2024 at 09:48:31AM +0100, Jiri Olsa wrote:
> > On Thu, Jan 04, 2024 at 10:01:35AM -0300, Arnaldo Carvalho de Melo wrote:
> > 
> > SNIP
> > 
> > >    9    51.66 amazonlinux:2                 : Ok   gcc (GCC) 7.3.1 20180712 (Red Hat 7.3.1-17) , clang version 11.1.0 (Amazon Linux 2 11.1.0-1.amzn2.0.2) flex 2.5.37
> > >   10    60.77 amazonlinux:2023              : Ok   gcc (GCC) 11.4.1 20230605 (Red Hat 11.4.1-2) , clang version 15.0.7 (Amazon Linux 15.0.7-3.amzn2023.0.1) flex 2.6.4
> > >   11    61.29 amazonlinux:devel             : Ok   gcc (GCC) 11.3.1 20221121 (Red Hat 11.3.1-4) , clang version 15.0.6 (Amazon Linux 15.0.6-3.amzn2023.0.2) flex 2.6.4
> > >   12    74.72 archlinux:base                : Ok   gcc (GCC) 13.2.1 20230801 , clang version 16.0.6 flex 2.6.4
> > > 
> > > / $ grep -B8 -A2 -w basename /usr/include/string.h
> > > #ifdef _GNU_SOURCE
> > > #define	strdupa(x)	strcpy(alloca(strlen(x)+1),x)
> > > int strverscmp (const char *, const char *);
> > > char *strchrnul(const char *, int);
> > > char *strcasestr(const char *, const char *);
> > > void *memrchr(const void *, int, size_t);
> > > void *mempcpy(void *, const void *, size_t);
> > > #ifndef __cplusplus
> > > char *basename();
> > > #endif
> > > #endif
> > > / $ cat /etc/os-release
> > > NAME="Alpine Linux"
> > > ID=alpine
> > > VERSION_ID=3.19.0
> > > PRETTY_NAME="Alpine Linux v3.19"
> > > HOME_URL="https://alpinelinux.org/"
> > > BUG_REPORT_URL="https://gitlab.alpinelinux.org/alpine/aports/-/issues"
> > > / $
> > > 
> > > Weird, they had it and now removed the _GNU_SOURCE bits (edge is their
> > > devel distro, like rawhide is for fedora, tumbleweed for opensuse, etc).
> > 
> > let's see, I asked them in here: https://gitlab.alpinelinux.org/alpine/aports/-/issues/15643
> 
> it got removed in musl libc recently:
>   https://git.musl-libc.org/cgit/musl/commit/?id=725e17ed6dff4d0cd22487bb64470881e86a92e7
> 
> so perhaps switching to POSIX version of basename is the easiest way out?

I think so, in all of perf we use the POSIX one, strdup'ing the arg,
etc.

Something like the patch below?

- Arnaldo

diff --git a/tools/bpf/bpftool/gen.c b/tools/bpf/bpftool/gen.c
index ee3ce2b8000d75d2..a5cc5938c3d7951e 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>
@@ -56,9 +57,10 @@ static bool str_has_suffix(const char *str, const char *suffix)
 
 static void get_obj_name(char *name, const char *file)
 {
-	/* Using basename() GNU version which doesn't modify arg. */
-	strncpy(name, basename(file), MAX_OBJ_NAME_LEN - 1);
-	name[MAX_OBJ_NAME_LEN - 1] = '\0';
+	char file_copy[PATH_MAX];
+	/* Using basename() POSIX version to be more portable. */
+	strncpy(file_copy, file, PATH_MAX - 1)[PATH_MAX - 1] = '\0';
+	strncpy(name, basename(file_copy), MAX_OBJ_NAME_LEN - 1)[MAX_OBJ_NAME_LEN - 1] = '\0';
 	if (str_has_suffix(name, ".o"))
 		name[strlen(name) - 2] = '\0';
 	sanitize_identifier(name);
Jiri Olsa Jan. 6, 2024, 8:02 p.m. UTC | #7
On Fri, Jan 05, 2024 at 05:53:18PM -0300, Arnaldo Carvalho de Melo wrote:
> Em Fri, Jan 05, 2024 at 04:01:37PM +0100, Jiri Olsa escreveu:
> > On Fri, Jan 05, 2024 at 09:48:31AM +0100, Jiri Olsa wrote:
> > > On Thu, Jan 04, 2024 at 10:01:35AM -0300, Arnaldo Carvalho de Melo wrote:
> > > 
> > > SNIP
> > > 
> > > >    9    51.66 amazonlinux:2                 : Ok   gcc (GCC) 7.3.1 20180712 (Red Hat 7.3.1-17) , clang version 11.1.0 (Amazon Linux 2 11.1.0-1.amzn2.0.2) flex 2.5.37
> > > >   10    60.77 amazonlinux:2023              : Ok   gcc (GCC) 11.4.1 20230605 (Red Hat 11.4.1-2) , clang version 15.0.7 (Amazon Linux 15.0.7-3.amzn2023.0.1) flex 2.6.4
> > > >   11    61.29 amazonlinux:devel             : Ok   gcc (GCC) 11.3.1 20221121 (Red Hat 11.3.1-4) , clang version 15.0.6 (Amazon Linux 15.0.6-3.amzn2023.0.2) flex 2.6.4
> > > >   12    74.72 archlinux:base                : Ok   gcc (GCC) 13.2.1 20230801 , clang version 16.0.6 flex 2.6.4
> > > > 
> > > > / $ grep -B8 -A2 -w basename /usr/include/string.h
> > > > #ifdef _GNU_SOURCE
> > > > #define	strdupa(x)	strcpy(alloca(strlen(x)+1),x)
> > > > int strverscmp (const char *, const char *);
> > > > char *strchrnul(const char *, int);
> > > > char *strcasestr(const char *, const char *);
> > > > void *memrchr(const void *, int, size_t);
> > > > void *mempcpy(void *, const void *, size_t);
> > > > #ifndef __cplusplus
> > > > char *basename();
> > > > #endif
> > > > #endif
> > > > / $ cat /etc/os-release
> > > > NAME="Alpine Linux"
> > > > ID=alpine
> > > > VERSION_ID=3.19.0
> > > > PRETTY_NAME="Alpine Linux v3.19"
> > > > HOME_URL="https://alpinelinux.org/"
> > > > BUG_REPORT_URL="https://gitlab.alpinelinux.org/alpine/aports/-/issues"
> > > > / $
> > > > 
> > > > Weird, they had it and now removed the _GNU_SOURCE bits (edge is their
> > > > devel distro, like rawhide is for fedora, tumbleweed for opensuse, etc).
> > > 
> > > let's see, I asked them in here: https://gitlab.alpinelinux.org/alpine/aports/-/issues/15643
> > 
> > it got removed in musl libc recently:
> >   https://git.musl-libc.org/cgit/musl/commit/?id=725e17ed6dff4d0cd22487bb64470881e86a92e7
> > 
> > so perhaps switching to POSIX version of basename is the easiest way out?
> 
> I think so, in all of perf we use the POSIX one, strdup'ing the arg,
> etc.
> 
> Something like the patch below?
> 
> - Arnaldo
> 
> diff --git a/tools/bpf/bpftool/gen.c b/tools/bpf/bpftool/gen.c
> index ee3ce2b8000d75d2..a5cc5938c3d7951e 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>
> @@ -56,9 +57,10 @@ static bool str_has_suffix(const char *str, const char *suffix)
>  
>  static void get_obj_name(char *name, const char *file)
>  {
> -	/* Using basename() GNU version which doesn't modify arg. */
> -	strncpy(name, basename(file), MAX_OBJ_NAME_LEN - 1);
> -	name[MAX_OBJ_NAME_LEN - 1] = '\0';
> +	char file_copy[PATH_MAX];

ok, probably better then checking for strdup error

> +	/* Using basename() POSIX version to be more portable. */
> +	strncpy(file_copy, file, PATH_MAX - 1)[PATH_MAX - 1] = '\0';
> +	strncpy(name, basename(file_copy), MAX_OBJ_NAME_LEN - 1)[MAX_OBJ_NAME_LEN - 1] = '\0';

I've never used it like that.. had to zoom in twice ;-)
but extra line with that might be more readable

jirka

>  	if (str_has_suffix(name, ".o"))
>  		name[strlen(name) - 2] = '\0';
>  	sanitize_identifier(name);
kernel test robot Jan. 12, 2024, 2:52 a.m. UTC | #8
Hi Arnaldo,

kernel test robot noticed the following build warnings:

[auto build test WARNING on bpf-next/master]
[also build test WARNING on bpf/master linus/master v6.7 next-20240111]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Arnaldo-Carvalho-de-Melo/bpftool-Add-missing-libgen-h-for-basename/20240104-110542
base:   https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master
patch link:    https://lore.kernel.org/r/ZZYgMYmb_qE94PUB%40kernel.org
patch subject: [PATCH] bpftool: Add missing libgen.h for basename()
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240112/202401121009.hCPmwMe6-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202401121009.hCPmwMe6-lkp@intel.com/

All warnings (new ones prefixed by >>):

   Makefile.config:1153: libpfm4 not found, disables libpfm4 support. Please install libpfm4-dev
     PERF_VERSION = 6.7.rc6.ge6bdf4fd535b
   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;
         |                              ~~~~~~^~~~~~
--
   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;
         |                              ~~~~~~^~~~~~
   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;
         |                              ~~~~~~^~~~~~
   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;
         |                              ~~~~~~^~~~~~
--
   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;
         |                              ~~~~~~^~~~~~
Arnaldo Carvalho de Melo Jan. 26, 2024, 3:53 p.m. UTC | #9
Em Fri, Jan 05, 2024 at 05:53:18PM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Fri, Jan 05, 2024 at 04:01:37PM +0100, Jiri Olsa escreveu:
> > On Fri, Jan 05, 2024 at 09:48:31AM +0100, Jiri Olsa wrote:
> > > On Thu, Jan 04, 2024 at 10:01:35AM -0300, Arnaldo Carvalho de Melo wrote:
> > > 
> > > SNIP
> > > 
> > > >    9    51.66 amazonlinux:2                 : Ok   gcc (GCC) 7.3.1 20180712 (Red Hat 7.3.1-17) , clang version 11.1.0 (Amazon Linux 2 11.1.0-1.amzn2.0.2) flex 2.5.37
> > > >   10    60.77 amazonlinux:2023              : Ok   gcc (GCC) 11.4.1 20230605 (Red Hat 11.4.1-2) , clang version 15.0.7 (Amazon Linux 15.0.7-3.amzn2023.0.1) flex 2.6.4
> > > >   11    61.29 amazonlinux:devel             : Ok   gcc (GCC) 11.3.1 20221121 (Red Hat 11.3.1-4) , clang version 15.0.6 (Amazon Linux 15.0.6-3.amzn2023.0.2) flex 2.6.4
> > > >   12    74.72 archlinux:base                : Ok   gcc (GCC) 13.2.1 20230801 , clang version 16.0.6 flex 2.6.4
> > > > 
> > > > / $ grep -B8 -A2 -w basename /usr/include/string.h
> > > > #ifdef _GNU_SOURCE
> > > > #define	strdupa(x)	strcpy(alloca(strlen(x)+1),x)
> > > > int strverscmp (const char *, const char *);
> > > > char *strchrnul(const char *, int);
> > > > char *strcasestr(const char *, const char *);
> > > > void *memrchr(const void *, int, size_t);
> > > > void *mempcpy(void *, const void *, size_t);
> > > > #ifndef __cplusplus
> > > > char *basename();
> > > > #endif
> > > > #endif
> > > > / $ cat /etc/os-release
> > > > NAME="Alpine Linux"
> > > > ID=alpine
> > > > VERSION_ID=3.19.0
> > > > PRETTY_NAME="Alpine Linux v3.19"
> > > > HOME_URL="https://alpinelinux.org/"
> > > > BUG_REPORT_URL="https://gitlab.alpinelinux.org/alpine/aports/-/issues"
> > > > / $
> > > > 
> > > > Weird, they had it and now removed the _GNU_SOURCE bits (edge is their
> > > > devel distro, like rawhide is for fedora, tumbleweed for opensuse, etc).
> > > 
> > > let's see, I asked them in here: https://gitlab.alpinelinux.org/alpine/aports/-/issues/15643
> > 
> > it got removed in musl libc recently:
> >   https://git.musl-libc.org/cgit/musl/commit/?id=725e17ed6dff4d0cd22487bb64470881e86a92e7
> > 
> > so perhaps switching to POSIX version of basename is the easiest way out?
> 
> I think so, in all of perf we use the POSIX one, strdup'ing the arg,
> etc.
> 
> Something like the patch below?

Quentin, are you ok with this? Then I can send a formal patch.

Jiri, can I have your Acked-by?

- Arnaldo
 
> diff --git a/tools/bpf/bpftool/gen.c b/tools/bpf/bpftool/gen.c
> index ee3ce2b8000d75d2..a5cc5938c3d7951e 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>
> @@ -56,9 +57,10 @@ static bool str_has_suffix(const char *str, const char *suffix)
>  
>  static void get_obj_name(char *name, const char *file)
>  {
> -	/* Using basename() GNU version which doesn't modify arg. */
> -	strncpy(name, basename(file), MAX_OBJ_NAME_LEN - 1);
> -	name[MAX_OBJ_NAME_LEN - 1] = '\0';
> +	char file_copy[PATH_MAX];
> +	/* Using basename() POSIX version to be more portable. */
> +	strncpy(file_copy, file, PATH_MAX - 1)[PATH_MAX - 1] = '\0';
> +	strncpy(name, basename(file_copy), MAX_OBJ_NAME_LEN - 1)[MAX_OBJ_NAME_LEN - 1] = '\0';
>  	if (str_has_suffix(name, ".o"))
>  		name[strlen(name) - 2] = '\0';
>  	sanitize_identifier(name);
Quentin Monnet Jan. 29, 2024, 10:07 a.m. UTC | #10
2024-01-26 15:53 UTC+0000 ~ Arnaldo Carvalho de Melo <acme@kernel.org>
> Em Fri, Jan 05, 2024 at 05:53:18PM -0300, Arnaldo Carvalho de Melo escreveu:
>> Em Fri, Jan 05, 2024 at 04:01:37PM +0100, Jiri Olsa escreveu:
>>> On Fri, Jan 05, 2024 at 09:48:31AM +0100, Jiri Olsa wrote:
>>>> On Thu, Jan 04, 2024 at 10:01:35AM -0300, Arnaldo Carvalho de Melo wrote:
>>>>
>>>> SNIP
>>>>
>>>>>    9    51.66 amazonlinux:2                 : Ok   gcc (GCC) 7.3.1 20180712 (Red Hat 7.3.1-17) , clang version 11.1.0 (Amazon Linux 2 11.1.0-1.amzn2.0.2) flex 2.5.37
>>>>>   10    60.77 amazonlinux:2023              : Ok   gcc (GCC) 11.4.1 20230605 (Red Hat 11.4.1-2) , clang version 15.0.7 (Amazon Linux 15.0.7-3.amzn2023.0.1) flex 2.6.4
>>>>>   11    61.29 amazonlinux:devel             : Ok   gcc (GCC) 11.3.1 20221121 (Red Hat 11.3.1-4) , clang version 15.0.6 (Amazon Linux 15.0.6-3.amzn2023.0.2) flex 2.6.4
>>>>>   12    74.72 archlinux:base                : Ok   gcc (GCC) 13.2.1 20230801 , clang version 16.0.6 flex 2.6.4
>>>>>
>>>>> / $ grep -B8 -A2 -w basename /usr/include/string.h
>>>>> #ifdef _GNU_SOURCE
>>>>> #define	strdupa(x)	strcpy(alloca(strlen(x)+1),x)
>>>>> int strverscmp (const char *, const char *);
>>>>> char *strchrnul(const char *, int);
>>>>> char *strcasestr(const char *, const char *);
>>>>> void *memrchr(const void *, int, size_t);
>>>>> void *mempcpy(void *, const void *, size_t);
>>>>> #ifndef __cplusplus
>>>>> char *basename();
>>>>> #endif
>>>>> #endif
>>>>> / $ cat /etc/os-release
>>>>> NAME="Alpine Linux"
>>>>> ID=alpine
>>>>> VERSION_ID=3.19.0
>>>>> PRETTY_NAME="Alpine Linux v3.19"
>>>>> HOME_URL="https://alpinelinux.org/"
>>>>> BUG_REPORT_URL="https://gitlab.alpinelinux.org/alpine/aports/-/issues"
>>>>> / $
>>>>>
>>>>> Weird, they had it and now removed the _GNU_SOURCE bits (edge is their
>>>>> devel distro, like rawhide is for fedora, tumbleweed for opensuse, etc).
>>>>
>>>> let's see, I asked them in here: https://gitlab.alpinelinux.org/alpine/aports/-/issues/15643
>>>
>>> it got removed in musl libc recently:
>>>   https://git.musl-libc.org/cgit/musl/commit/?id=725e17ed6dff4d0cd22487bb64470881e86a92e7
>>>
>>> so perhaps switching to POSIX version of basename is the easiest way out?
>>
>> I think so, in all of perf we use the POSIX one, strdup'ing the arg,
>> etc.
>>
>> Something like the patch below?
> 
> Quentin, are you ok with this? Then I can send a formal patch.

I'm not aware of any particular drawback about using the POSIX version
(Is there?), so the patch looks good as far as I'm concerned. Thanks
Arnaldo!

Quentin
Jiri Olsa Jan. 29, 2024, 11:23 a.m. UTC | #11
On Fri, Jan 26, 2024 at 12:53:22PM -0300, Arnaldo Carvalho de Melo wrote:
> Em Fri, Jan 05, 2024 at 05:53:18PM -0300, Arnaldo Carvalho de Melo escreveu:
> > Em Fri, Jan 05, 2024 at 04:01:37PM +0100, Jiri Olsa escreveu:
> > > On Fri, Jan 05, 2024 at 09:48:31AM +0100, Jiri Olsa wrote:
> > > > On Thu, Jan 04, 2024 at 10:01:35AM -0300, Arnaldo Carvalho de Melo wrote:
> > > > 
> > > > SNIP
> > > > 
> > > > >    9    51.66 amazonlinux:2                 : Ok   gcc (GCC) 7.3.1 20180712 (Red Hat 7.3.1-17) , clang version 11.1.0 (Amazon Linux 2 11.1.0-1.amzn2.0.2) flex 2.5.37
> > > > >   10    60.77 amazonlinux:2023              : Ok   gcc (GCC) 11.4.1 20230605 (Red Hat 11.4.1-2) , clang version 15.0.7 (Amazon Linux 15.0.7-3.amzn2023.0.1) flex 2.6.4
> > > > >   11    61.29 amazonlinux:devel             : Ok   gcc (GCC) 11.3.1 20221121 (Red Hat 11.3.1-4) , clang version 15.0.6 (Amazon Linux 15.0.6-3.amzn2023.0.2) flex 2.6.4
> > > > >   12    74.72 archlinux:base                : Ok   gcc (GCC) 13.2.1 20230801 , clang version 16.0.6 flex 2.6.4
> > > > > 
> > > > > / $ grep -B8 -A2 -w basename /usr/include/string.h
> > > > > #ifdef _GNU_SOURCE
> > > > > #define	strdupa(x)	strcpy(alloca(strlen(x)+1),x)
> > > > > int strverscmp (const char *, const char *);
> > > > > char *strchrnul(const char *, int);
> > > > > char *strcasestr(const char *, const char *);
> > > > > void *memrchr(const void *, int, size_t);
> > > > > void *mempcpy(void *, const void *, size_t);
> > > > > #ifndef __cplusplus
> > > > > char *basename();
> > > > > #endif
> > > > > #endif
> > > > > / $ cat /etc/os-release
> > > > > NAME="Alpine Linux"
> > > > > ID=alpine
> > > > > VERSION_ID=3.19.0
> > > > > PRETTY_NAME="Alpine Linux v3.19"
> > > > > HOME_URL="https://alpinelinux.org/"
> > > > > BUG_REPORT_URL="https://gitlab.alpinelinux.org/alpine/aports/-/issues"
> > > > > / $
> > > > > 
> > > > > Weird, they had it and now removed the _GNU_SOURCE bits (edge is their
> > > > > devel distro, like rawhide is for fedora, tumbleweed for opensuse, etc).
> > > > 
> > > > let's see, I asked them in here: https://gitlab.alpinelinux.org/alpine/aports/-/issues/15643
> > > 
> > > it got removed in musl libc recently:
> > >   https://git.musl-libc.org/cgit/musl/commit/?id=725e17ed6dff4d0cd22487bb64470881e86a92e7
> > > 
> > > so perhaps switching to POSIX version of basename is the easiest way out?
> > 
> > I think so, in all of perf we use the POSIX one, strdup'ing the arg,
> > etc.
> > 
> > Something like the patch below?
> 
> Quentin, are you ok with this? Then I can send a formal patch.
> 
> Jiri, can I have your Acked-by?

yes, jirka

> 
> - Arnaldo
>  
> > diff --git a/tools/bpf/bpftool/gen.c b/tools/bpf/bpftool/gen.c
> > index ee3ce2b8000d75d2..a5cc5938c3d7951e 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>
> > @@ -56,9 +57,10 @@ static bool str_has_suffix(const char *str, const char *suffix)
> >  
> >  static void get_obj_name(char *name, const char *file)
> >  {
> > -	/* Using basename() GNU version which doesn't modify arg. */
> > -	strncpy(name, basename(file), MAX_OBJ_NAME_LEN - 1);
> > -	name[MAX_OBJ_NAME_LEN - 1] = '\0';
> > +	char file_copy[PATH_MAX];
> > +	/* Using basename() POSIX version to be more portable. */
> > +	strncpy(file_copy, file, PATH_MAX - 1)[PATH_MAX - 1] = '\0';
> > +	strncpy(name, basename(file_copy), MAX_OBJ_NAME_LEN - 1)[MAX_OBJ_NAME_LEN - 1] = '\0';
> >  	if (str_has_suffix(name, ".o"))
> >  		name[strlen(name) - 2] = '\0';
> >  	sanitize_identifier(name);
> 
> -- 
> 
> - Arnaldo
diff mbox series

Patch

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>