BPF List
 help / color / mirror / Atom feed
From: Jiri Olsa <olsajiri@gmail.com>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Quentin Monnet <quentin@isovalent.com>,
	Namhyung Kim <namhyung@kernel.org>,
	Ian Rogers <irogers@google.com>,
	Adrian Hunter <adrian.hunter@intel.com>,
	Andrii Nakryiko <andrii.nakryiko@gmail.com>,
	bpf@vger.kernel.org
Subject: Re: [PATCH] bpftool: Add missing libgen.h for basename()
Date: Thu, 4 Jan 2024 10:33:58 +0100	[thread overview]
Message-ID: <ZZZ7hgqlYjNJOynA@krava> (raw)
In-Reply-To: <ZZYgMYmb_qE94PUB@kernel.org>

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

  reply	other threads:[~2024-01-04  9:34 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-04  3:04 [PATCH] bpftool: Add missing libgen.h for basename() Arnaldo Carvalho de Melo
2024-01-04  9:33 ` Jiri Olsa [this message]
2024-01-04 12:27   ` Arnaldo Carvalho de Melo
2024-01-04 13:01     ` Arnaldo Carvalho de Melo
2024-01-05  8:48       ` Jiri Olsa
2024-01-05 15:01         ` Jiri Olsa
2024-01-05 20:53           ` Arnaldo Carvalho de Melo
2024-01-06 20:02             ` Jiri Olsa
2024-01-26 15:53             ` Arnaldo Carvalho de Melo
2024-01-29 10:07               ` Quentin Monnet
2024-01-29 11:23               ` Jiri Olsa
2024-01-12  2:52 ` kernel test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZZZ7hgqlYjNJOynA@krava \
    --to=olsajiri@gmail.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=andrii.nakryiko@gmail.com \
    --cc=bpf@vger.kernel.org \
    --cc=irogers@google.com \
    --cc=namhyung@kernel.org \
    --cc=quentin@isovalent.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox