All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf] libbpf: Fix compile error in libbpf_attach_type_by_name
@ 2018-10-31 19:57 Andrey Ignatov
  2018-10-31 20:49 ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 3+ messages in thread
From: Andrey Ignatov @ 2018-10-31 19:57 UTC (permalink / raw)
  To: netdev; +Cc: Andrey Ignatov, ast, daniel, kernel-team, acme

Arnaldo Carvalho de Melo reported build error in libbpf when clang
version 3.8.1-24 (tags/RELEASE_381/final) is used:

libbpf.c:2201:36: error: comparison of constant -22 with expression of
type 'const enum bpf_attach_type' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
                if (section_names[i].attach_type == -EINVAL)
                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^  ~~~~~~~
1 error generated.

Fix the error by keeping "is_attachable" property of a program in a
separate struct field instead of trying to use attach_type itself.

Fixes: commit 956b620fcf0b ("libbpf: Introduce libbpf_attach_type_by_name")
Reported-by: Arnaldo Carvalho de Melo <acme@kernel.org>
Signed-off-by: Andrey Ignatov <rdna@fb.com>
---
 tools/lib/bpf/libbpf.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index b607be7236d3..d6e62e90e8d4 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -2084,19 +2084,19 @@ void bpf_program__set_expected_attach_type(struct bpf_program *prog,
 	prog->expected_attach_type = type;
 }
 
-#define BPF_PROG_SEC_IMPL(string, ptype, eatype, atype) \
-	{ string, sizeof(string) - 1, ptype, eatype, atype }
+#define BPF_PROG_SEC_IMPL(string, ptype, eatype, is_attachable, atype) \
+	{ string, sizeof(string) - 1, ptype, eatype, is_attachable, atype }
 
 /* Programs that can NOT be attached. */
-#define BPF_PROG_SEC(string, ptype) BPF_PROG_SEC_IMPL(string, ptype, 0, -EINVAL)
+#define BPF_PROG_SEC(string, ptype) BPF_PROG_SEC_IMPL(string, ptype, 0, 0, 0)
 
 /* Programs that can be attached. */
 #define BPF_APROG_SEC(string, ptype, atype) \
-	BPF_PROG_SEC_IMPL(string, ptype, 0, atype)
+	BPF_PROG_SEC_IMPL(string, ptype, 0, 1, atype)
 
 /* Programs that must specify expected attach type at load time. */
 #define BPF_EAPROG_SEC(string, ptype, eatype) \
-	BPF_PROG_SEC_IMPL(string, ptype, eatype, eatype)
+	BPF_PROG_SEC_IMPL(string, ptype, eatype, 1, eatype)
 
 /* Programs that can be attached but attach type can't be identified by section
  * name. Kept for backward compatibility.
@@ -2108,6 +2108,7 @@ static const struct {
 	size_t len;
 	enum bpf_prog_type prog_type;
 	enum bpf_attach_type expected_attach_type;
+	int is_attachable;
 	enum bpf_attach_type attach_type;
 } section_names[] = {
 	BPF_PROG_SEC("socket",			BPF_PROG_TYPE_SOCKET_FILTER),
@@ -2198,7 +2199,7 @@ int libbpf_attach_type_by_name(const char *name,
 	for (i = 0; i < ARRAY_SIZE(section_names); i++) {
 		if (strncmp(name, section_names[i].sec, section_names[i].len))
 			continue;
-		if (section_names[i].attach_type == -EINVAL)
+		if (!section_names[i].is_attachable)
 			return -EINVAL;
 		*attach_type = section_names[i].attach_type;
 		return 0;
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH bpf] libbpf: Fix compile error in libbpf_attach_type_by_name
  2018-10-31 19:57 [PATCH bpf] libbpf: Fix compile error in libbpf_attach_type_by_name Andrey Ignatov
@ 2018-10-31 20:49 ` Arnaldo Carvalho de Melo
  2018-10-31 22:08   ` Daniel Borkmann
  0 siblings, 1 reply; 3+ messages in thread
From: Arnaldo Carvalho de Melo @ 2018-10-31 20:49 UTC (permalink / raw)
  To: Andrey Ignatov; +Cc: netdev, ast, daniel, kernel-team

Em Wed, Oct 31, 2018 at 12:57:18PM -0700, Andrey Ignatov escreveu:
> Arnaldo Carvalho de Melo reported build error in libbpf when clang
> version 3.8.1-24 (tags/RELEASE_381/final) is used:
> 
> libbpf.c:2201:36: error: comparison of constant -22 with expression of
> type 'const enum bpf_attach_type' is always false
> [-Werror,-Wtautological-constant-out-of-range-compare]
>                 if (section_names[i].attach_type == -EINVAL)
>                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^  ~~~~~~~
> 1 error generated.
> 
> Fix the error by keeping "is_attachable" property of a program in a
> separate struct field instead of trying to use attach_type itself.

Thanks, now it builds in all the previously failing systems:

# export PERF_TARBALL=http://192.168.86.4/perf/perf-4.19.0.tar.xz
# dm debian:9 fedora:25 fedora:26 fedora:27 ubuntu:16.04 ubuntu:17.10
   1 debian:9        : Ok   gcc (Debian 6.3.0-18+deb9u1) 6.3.0 20170516          clang version 3.8.1-24 (tags/RELEASE_381/final)
   2 fedora:25       : Ok   gcc (GCC) 6.4.1 20170727 (Red Hat 6.4.1-1)           clang version 3.9.1 (tags/RELEASE_391/final)
   3 fedora:26       : Ok   gcc (GCC) 7.3.1 20180130 (Red Hat 7.3.1-2)           clang version 4.0.1 (tags/RELEASE_401/final)
   4 fedora:27       : Ok   gcc (GCC) 7.3.1 20180712 (Red Hat 7.3.1-6)           clang version 5.0.2 (tags/RELEASE_502/final)
   5 ubuntu:16.04    : Ok   gcc (Ubuntu 5.4.0-6ubuntu1~16.04.10) 5.4.0 20160609  clang version 3.8.0-2ubuntu4 (tags/RELEASE_380/final)
   6 ubuntu:17.10    : Ok   gcc (Ubuntu 7.2.0-8ubuntu3.2) 7.2.0                  clang version 4.0.1-6 (tags/RELEASE_401/final)
#

Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>

I also have it tentatively applied to my perf/urgent branch, that I'll
push upstream soon.

- Arnaldo
 
> Fixes: commit 956b620fcf0b ("libbpf: Introduce libbpf_attach_type_by_name")
> Reported-by: Arnaldo Carvalho de Melo <acme@kernel.org>
> Signed-off-by: Andrey Ignatov <rdna@fb.com>
> ---
>  tools/lib/bpf/libbpf.c | 13 +++++++------
>  1 file changed, 7 insertions(+), 6 deletions(-)
> 
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index b607be7236d3..d6e62e90e8d4 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -2084,19 +2084,19 @@ void bpf_program__set_expected_attach_type(struct bpf_program *prog,
>  	prog->expected_attach_type = type;
>  }
>  
> -#define BPF_PROG_SEC_IMPL(string, ptype, eatype, atype) \
> -	{ string, sizeof(string) - 1, ptype, eatype, atype }
> +#define BPF_PROG_SEC_IMPL(string, ptype, eatype, is_attachable, atype) \
> +	{ string, sizeof(string) - 1, ptype, eatype, is_attachable, atype }
>  
>  /* Programs that can NOT be attached. */
> -#define BPF_PROG_SEC(string, ptype) BPF_PROG_SEC_IMPL(string, ptype, 0, -EINVAL)
> +#define BPF_PROG_SEC(string, ptype) BPF_PROG_SEC_IMPL(string, ptype, 0, 0, 0)
>  
>  /* Programs that can be attached. */
>  #define BPF_APROG_SEC(string, ptype, atype) \
> -	BPF_PROG_SEC_IMPL(string, ptype, 0, atype)
> +	BPF_PROG_SEC_IMPL(string, ptype, 0, 1, atype)
>  
>  /* Programs that must specify expected attach type at load time. */
>  #define BPF_EAPROG_SEC(string, ptype, eatype) \
> -	BPF_PROG_SEC_IMPL(string, ptype, eatype, eatype)
> +	BPF_PROG_SEC_IMPL(string, ptype, eatype, 1, eatype)
>  
>  /* Programs that can be attached but attach type can't be identified by section
>   * name. Kept for backward compatibility.
> @@ -2108,6 +2108,7 @@ static const struct {
>  	size_t len;
>  	enum bpf_prog_type prog_type;
>  	enum bpf_attach_type expected_attach_type;
> +	int is_attachable;
>  	enum bpf_attach_type attach_type;
>  } section_names[] = {
>  	BPF_PROG_SEC("socket",			BPF_PROG_TYPE_SOCKET_FILTER),
> @@ -2198,7 +2199,7 @@ int libbpf_attach_type_by_name(const char *name,
>  	for (i = 0; i < ARRAY_SIZE(section_names); i++) {
>  		if (strncmp(name, section_names[i].sec, section_names[i].len))
>  			continue;
> -		if (section_names[i].attach_type == -EINVAL)
> +		if (!section_names[i].is_attachable)
>  			return -EINVAL;
>  		*attach_type = section_names[i].attach_type;
>  		return 0;
> -- 
> 2.17.1

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH bpf] libbpf: Fix compile error in libbpf_attach_type_by_name
  2018-10-31 20:49 ` Arnaldo Carvalho de Melo
@ 2018-10-31 22:08   ` Daniel Borkmann
  0 siblings, 0 replies; 3+ messages in thread
From: Daniel Borkmann @ 2018-10-31 22:08 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Andrey Ignatov; +Cc: netdev, ast, kernel-team

On 10/31/2018 09:49 PM, Arnaldo Carvalho de Melo wrote:
> Em Wed, Oct 31, 2018 at 12:57:18PM -0700, Andrey Ignatov escreveu:
>> Arnaldo Carvalho de Melo reported build error in libbpf when clang
>> version 3.8.1-24 (tags/RELEASE_381/final) is used:
>>
>> libbpf.c:2201:36: error: comparison of constant -22 with expression of
>> type 'const enum bpf_attach_type' is always false
>> [-Werror,-Wtautological-constant-out-of-range-compare]
>>                 if (section_names[i].attach_type == -EINVAL)
>>                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^  ~~~~~~~
>> 1 error generated.
>>
>> Fix the error by keeping "is_attachable" property of a program in a
>> separate struct field instead of trying to use attach_type itself.
> 
> Thanks, now it builds in all the previously failing systems:
> 
> # export PERF_TARBALL=http://192.168.86.4/perf/perf-4.19.0.tar.xz
> # dm debian:9 fedora:25 fedora:26 fedora:27 ubuntu:16.04 ubuntu:17.10
>    1 debian:9        : Ok   gcc (Debian 6.3.0-18+deb9u1) 6.3.0 20170516          clang version 3.8.1-24 (tags/RELEASE_381/final)
>    2 fedora:25       : Ok   gcc (GCC) 6.4.1 20170727 (Red Hat 6.4.1-1)           clang version 3.9.1 (tags/RELEASE_391/final)
>    3 fedora:26       : Ok   gcc (GCC) 7.3.1 20180130 (Red Hat 7.3.1-2)           clang version 4.0.1 (tags/RELEASE_401/final)
>    4 fedora:27       : Ok   gcc (GCC) 7.3.1 20180712 (Red Hat 7.3.1-6)           clang version 5.0.2 (tags/RELEASE_502/final)
>    5 ubuntu:16.04    : Ok   gcc (Ubuntu 5.4.0-6ubuntu1~16.04.10) 5.4.0 20160609  clang version 3.8.0-2ubuntu4 (tags/RELEASE_380/final)
>    6 ubuntu:17.10    : Ok   gcc (Ubuntu 7.2.0-8ubuntu3.2) 7.2.0                  clang version 4.0.1-6 (tags/RELEASE_401/final)
> #
> 
> Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Thanks everyone, applied to bpf tree.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-11-01  7:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-31 19:57 [PATCH bpf] libbpf: Fix compile error in libbpf_attach_type_by_name Andrey Ignatov
2018-10-31 20:49 ` Arnaldo Carvalho de Melo
2018-10-31 22:08   ` Daniel Borkmann

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.