diff options
author | Andrey Ignatov <rdna@fb.com> | 2018-10-31 15:57:18 -0400 |
---|---|---|
committer | Daniel Borkmann <daniel@iogearbox.net> | 2018-10-31 18:06:17 -0400 |
commit | 3615353218744bb60f55170c620ce4dce1a008c7 (patch) | |
tree | fd8df6356914077abfcfe6434ae664de3ba32b1a /tools/lib/bpf | |
parent | deee2cae27d1914850195e3fb219cc611e953560 (diff) |
libbpf: Fix compile error in libbpf_attach_type_by_name
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: 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>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Diffstat (limited to 'tools/lib/bpf')
-rw-r--r-- | tools/lib/bpf/libbpf.c | 13 |
1 files 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, | |||
2084 | prog->expected_attach_type = type; | 2084 | prog->expected_attach_type = type; |
2085 | } | 2085 | } |
2086 | 2086 | ||
2087 | #define BPF_PROG_SEC_IMPL(string, ptype, eatype, atype) \ | 2087 | #define BPF_PROG_SEC_IMPL(string, ptype, eatype, is_attachable, atype) \ |
2088 | { string, sizeof(string) - 1, ptype, eatype, atype } | 2088 | { string, sizeof(string) - 1, ptype, eatype, is_attachable, atype } |
2089 | 2089 | ||
2090 | /* Programs that can NOT be attached. */ | 2090 | /* Programs that can NOT be attached. */ |
2091 | #define BPF_PROG_SEC(string, ptype) BPF_PROG_SEC_IMPL(string, ptype, 0, -EINVAL) | 2091 | #define BPF_PROG_SEC(string, ptype) BPF_PROG_SEC_IMPL(string, ptype, 0, 0, 0) |
2092 | 2092 | ||
2093 | /* Programs that can be attached. */ | 2093 | /* Programs that can be attached. */ |
2094 | #define BPF_APROG_SEC(string, ptype, atype) \ | 2094 | #define BPF_APROG_SEC(string, ptype, atype) \ |
2095 | BPF_PROG_SEC_IMPL(string, ptype, 0, atype) | 2095 | BPF_PROG_SEC_IMPL(string, ptype, 0, 1, atype) |
2096 | 2096 | ||
2097 | /* Programs that must specify expected attach type at load time. */ | 2097 | /* Programs that must specify expected attach type at load time. */ |
2098 | #define BPF_EAPROG_SEC(string, ptype, eatype) \ | 2098 | #define BPF_EAPROG_SEC(string, ptype, eatype) \ |
2099 | BPF_PROG_SEC_IMPL(string, ptype, eatype, eatype) | 2099 | BPF_PROG_SEC_IMPL(string, ptype, eatype, 1, eatype) |
2100 | 2100 | ||
2101 | /* Programs that can be attached but attach type can't be identified by section | 2101 | /* Programs that can be attached but attach type can't be identified by section |
2102 | * name. Kept for backward compatibility. | 2102 | * name. Kept for backward compatibility. |
@@ -2108,6 +2108,7 @@ static const struct { | |||
2108 | size_t len; | 2108 | size_t len; |
2109 | enum bpf_prog_type prog_type; | 2109 | enum bpf_prog_type prog_type; |
2110 | enum bpf_attach_type expected_attach_type; | 2110 | enum bpf_attach_type expected_attach_type; |
2111 | int is_attachable; | ||
2111 | enum bpf_attach_type attach_type; | 2112 | enum bpf_attach_type attach_type; |
2112 | } section_names[] = { | 2113 | } section_names[] = { |
2113 | BPF_PROG_SEC("socket", BPF_PROG_TYPE_SOCKET_FILTER), | 2114 | BPF_PROG_SEC("socket", BPF_PROG_TYPE_SOCKET_FILTER), |
@@ -2198,7 +2199,7 @@ int libbpf_attach_type_by_name(const char *name, | |||
2198 | for (i = 0; i < ARRAY_SIZE(section_names); i++) { | 2199 | for (i = 0; i < ARRAY_SIZE(section_names); i++) { |
2199 | if (strncmp(name, section_names[i].sec, section_names[i].len)) | 2200 | if (strncmp(name, section_names[i].sec, section_names[i].len)) |
2200 | continue; | 2201 | continue; |
2201 | if (section_names[i].attach_type == -EINVAL) | 2202 | if (!section_names[i].is_attachable) |
2202 | return -EINVAL; | 2203 | return -EINVAL; |
2203 | *attach_type = section_names[i].attach_type; | 2204 | *attach_type = section_names[i].attach_type; |
2204 | return 0; | 2205 | return 0; |