libbpf build fixes
Subsystems (4)
Hi Daniel,
Please consider pulling or applying from the patches, if someone
has any issues, please holler,
- Arnaldo
Arnaldo Carvalho de Melo (2):
libbpf: Fix endianness macro usage for some compilers
libbpf: Avoid designated initializers for unnamed union members
tools/lib/bpf/btf.c | 5 +++-- tools/lib/bpf/libbpf.c | 19 ++++++++++--------- 2 files changed, 13 insertions(+), 11 deletions(-)
Signature · 22 lines
2.21.0
The following changes since commit 9b3d15e6b05e0b916be5fbd915f90300a403098b:
bnxt_en: Fix VNIC accounting when enabling aRFS on 57500 chips. (2019-07-18 16:33:27 -0700)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git libbpf
for you to fetch changes up to 5443fc23eb80e7cd03f9111fb16fb9aaa76fedc9:
libbpf: Avoid designated initializers for unnamed union members (2019-07-19 11:21:33 -0300)
----------------------------------------------------------------
Arnaldo Carvalho de Melo (2):
libbpf: Fix endianness macro usage for some compilers
libbpf: Avoid designated initializers for unnamed union members
tools/lib/bpf/btf.c | 5 +++--
tools/lib/bpf/libbpf.c | 19 ++++++++++---------
2 files changed, 13 insertions(+), 11 deletions(-)PATCH 1/2 libbpf: Fix endianness macro usage for some compilers
From: Arnaldo Carvalho de Melo <[email protected]>
Using endian.h and its endianness macros makes this code build in a wider range of compilers, as some don't have those macros (__BYTE_ORDER__, __ORDER_LITTLE_ENDIAN__, __ORDER_BIG_ENDIAN__), so use instead endian.h's macros (__BYTE_ORDER, __LITTLE_ENDIAN, __BIG_ENDIAN) which makes this code even shorter :-)
--- tools/lib/bpf/btf.c | 5 +++-- tools/lib/bpf/libbpf.c | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-)
tools/lib/bpf/btf.c +3 -2
@@ -1,6 +1,7 @@// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) /* Copyright (c) 2018 Facebook */ +#include <endian.h> #include <stdio.h> #include <stdlib.h> #include <string.h>
@@ -419,9 +420,9 @@ struct btf *btf__new(__u8 *data, __u32 size)static bool btf_check_endianness (const GElf_Ehdr *ehdr) { -#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ +#if __BYTE_ORDER == __LITTLE_ENDIANreturn ehdr->e_ident[EI_DATA ] ==ELFDATA2LSB ; -#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ +#elif __BYTE_ORDER == __BIG_ENDIANreturn ehdr->e_ident[EI_DATA ] ==ELFDATA2MSB ;#else # error "Unrecognized __BYTE_ORDER__"
tools/lib/bpf/libbpf.c +3 -2
@@ -20,6 +20,7 @@#include <inttypes.h> #include <string.h> #include <unistd.h> +#include <endian.h> #include <fcntl.h> #include <errno.h> #include <asm/unistd.h>
@@ -612,10 +613,10 @@ static int bpf_object__elf_init(struct bpf_object *obj)static int bpf_object__check_endianness (struct bpf_object *obj) { -#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ +#if __BYTE_ORDER == __LITTLE_ENDIANif (obj->efile.ehdr.e_ident[EI_DATA ] ==ELFDATA2LSB )return 0 ; -#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ +#elif __BYTE_ORDER == __BIG_ENDIANif (obj->efile.ehdr.e_ident[EI_DATA ] ==ELFDATA2MSB )return 0 ;#else
Signature · 1 line
2.21.0
Re: [PATCH 1/2] libbpf: Fix endianness macro usage for some compilers
Quoted 8 lines · Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo <[email protected]>
Using
endian.hand its endianness macros makes this code build in a wider range of compilers, as some don't have those macros (__BYTE_ORDER__,__ORDER_LITTLE_ENDIAN__,__ORDER_BIG_ENDIAN__), so use instead endian.h's macros (__BYTE_ORDER,__LITTLE_ENDIAN,__BIG_ENDIAN) which makes this code even shorter :-)
gcc 4.6.0 starts to support __BYTE_ORDER__, __ORDER_LITTLE_ENDIAN__, etc. I guess those platforms with failing compilation have gcc < 4.6.0. Agree that for libbpf, which will be used outside kernel bpf selftest should try to compile with lower versions of gcc.
Quoted 68 lines
Acked-by Andrii Nakryiko <[email protected]>Cc Adrian Hunter <[email protected]>Cc Alexei Starovoitov <[email protected]>Cc Daniel Borkmann <[email protected]>Cc Jiri Olsa <[email protected]>Cc Namhyung Kim <[email protected]>Fixes 12ef5634a855 ("libbpf: simplify endianness check")Fixes e6c64855fd7a ("libbpf: add btf__parse_elf API to load .BTF and .BTF.ext")Signed-off-by Arnaldo Carvalho de Melo <[email protected]>--- tools/lib/bpf/btf.c | 5 +++-- tools/lib/bpf/libbpf.c | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-)tools/lib/bpf/btf.c +3
-2@@ -1,6 +1,7 @@// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) /* Copyright (c) 2018 Facebook */ +#include <endian.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -419,9 +420,9 @@ struct btf *btf__new(__u8 *data, __u32 size)static bool btf_check_endianness (const GElf_Ehdr *ehdr) { -#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ +#if __BYTE_ORDER == __LITTLE_ENDIANreturn ehdr->e_ident[EI_DATA ] ==ELFDATA2LSB ; -#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ +#elif __BYTE_ORDER == __BIG_ENDIANreturn ehdr->e_ident[EI_DATA ] ==ELFDATA2MSB ;#else # error "Unrecognized __BYTE_ORDER__"tools/lib/bpf/libbpf.c +3
-3@@ -20,6 +20,7 @@#include <inttypes.h> #include <string.h> #include <unistd.h> +#include <endian.h> #include <fcntl.h> #include <errno.h> #include <asm/unistd.h> @@ -612,10 +613,10 @@ static int bpf_object__elf_init(struct bpf_object *obj)static int bpf_object__check_endianness (struct bpf_object *obj) { -#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ +#if __BYTE_ORDER == __LITTLE_ENDIANif (obj->efile.ehdr.e_ident[EI_DATA ] ==ELFDATA2LSB )return 0 ; -#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ +#elif __BYTE_ORDER == __BIG_ENDIANif (obj->efile.ehdr.e_ident[EI_DATA ] ==ELFDATA2MSB )return 0 ;#else --2.21.0
Re: [PATCH 1/2] libbpf: Fix endianness macro usage for some compilers
Em Fri, Jul 19, 2019 at 09:25:07AM -0700, Y Song escreveu:
Quoted 11 lines · Arnaldo Carvalho de Melo
Quoted 5 lines
Using
endian.hand its endianness macros makes this code build in a wider range of compilers, as some don't have those macros (__BYTE_ORDER__,__ORDER_LITTLE_ENDIAN__,__ORDER_BIG_ENDIAN__), so use instead endian.h's macros (__BYTE_ORDER,__LITTLE_ENDIAN,__BIG_ENDIAN) which makes this code even shorter :-)gcc 4.6.0 starts to support
__BYTE_ORDER__,__ORDER_LITTLE_ENDIAN__, etc. I guess those platforms with failing compilation have gcc < 4.6.0. Agree that for libbpf, which will be used outside kernel bpf selftest should try to compile with lower versions of gcc.
Yeah, I wouldn't mind at all if the answer to this patch was hey, the minimal version for building libbpf is X.Y, no problem, its just that in this case there is an alternative that works everywhere and the resulting source code is even more compact :-)
- Arnaldo
Quoted 67 lines
Quoted 67 lines
Acked-by Andrii Nakryiko <[email protected]>Cc Adrian Hunter <[email protected]>Cc Alexei Starovoitov <[email protected]>Cc Daniel Borkmann <[email protected]>Cc Jiri Olsa <[email protected]>Cc Namhyung Kim <[email protected]>Fixes 12ef5634a855 ("libbpf: simplify endianness check")Fixes e6c64855fd7a ("libbpf: add btf__parse_elf API to load .BTF and .BTF.ext")Signed-off-by Arnaldo Carvalho de Melo <[email protected]>--- tools/lib/bpf/btf.c | 5 +++-- tools/lib/bpf/libbpf.c | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-)tools/lib/bpf/btf.c +3
-2@@ -1,6 +1,7 @@// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) /* Copyright (c) 2018 Facebook */ +#include <endian.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -419,9 +420,9 @@ struct btf *btf__new(__u8 *data, __u32 size)static bool btf_check_endianness (const GElf_Ehdr *ehdr) { -#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ +#if __BYTE_ORDER == __LITTLE_ENDIANreturn ehdr->e_ident[EI_DATA ] ==ELFDATA2LSB ; -#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ +#elif __BYTE_ORDER == __BIG_ENDIANreturn ehdr->e_ident[EI_DATA ] ==ELFDATA2MSB ;#else # error "Unrecognized __BYTE_ORDER__"tools/lib/bpf/libbpf.c +3
-3@@ -20,6 +20,7 @@#include <inttypes.h> #include <string.h> #include <unistd.h> +#include <endian.h> #include <fcntl.h> #include <errno.h> #include <asm/unistd.h> @@ -612,10 +613,10 @@ static int bpf_object__elf_init(struct bpf_object *obj)static int bpf_object__check_endianness (struct bpf_object *obj) { -#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ +#if __BYTE_ORDER == __LITTLE_ENDIANif (obj->efile.ehdr.e_ident[EI_DATA ] ==ELFDATA2LSB )return 0 ; -#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ +#elif __BYTE_ORDER == __BIG_ENDIANif (obj->efile.ehdr.e_ident[EI_DATA ] ==ELFDATA2MSB )return 0 ;#else --2.21.0
Signature · 1 line
- Arnaldo
PATCH 2/2 libbpf: Avoid designated initializers for unnamed union members
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
As it fails to build in some systems with:
libbpf.c: In function 'perf_buffer__new':
libbpf.c:4515: error: unknown field 'sample_period' specified in initializer libbpf.c:4516: error: unknown field 'wakeup_events' specified in initializer
Doing as:
attr.sample_period = 1;
I.e. not as a designated initializer makes it build everywhere.
--- tools/lib/bpf/libbpf.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
tools/lib/bpf/libbpf.c +7 -7
@@ -4508,13 +4508,13 @@ struct perf_buffer *perf_buffer__new(int map_fd, size_t page_cnt, const struct perf_buffer_opts *opts) {struct perf_buffer_params p = {}; -struct perf_event_attr attr = { - .config =PERF_COUNT_SW_BPF_OUTPUT , - .type =PERF_TYPE_SOFTWARE , - .sample_type =PERF_SAMPLE_RAW , - .sample_period =1 , - .wakeup_events =1 , - }; +struct perf_event_attr attr = {0 , }; + + attr.config =PERF_COUNT_SW_BPF_OUTPUT , + attr.type =PERF_TYPE_SOFTWARE ; + attr.sample_type =PERF_SAMPLE_RAW ; + attr.sample_period =1 ; + attr.wakeup_events =1 ; p.attr = &attr; p.sample_cb = opts ? opts->sample_cb :NULL ;
Signature · 1 line
2.21.0
Re: [PATCH 2/2] libbpf: Avoid designated initializers for unnamed union members
Quoted 23 lines · Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo <[email protected]>
As it fails to build in some systems with:
libbpf.c: In function 'perf_buffer__new':
libbpf.c:4515: error: unknown field 'sample_period' specified in initializer libbpf.c:4516: error: unknown field 'wakeup_events' specified in initializerDoing as:
attr.sample_period = 1;I.e. not as a designated initializer makes it build everywhere.
Cc Andrii Nakryiko <[email protected]>Cc Adrian Hunter <[email protected]>Cc Daniel Borkmann <[email protected]>Cc Jiri Olsa <[email protected]>Cc Namhyung Kim <[email protected]>Fixes fb84b8224655 ("libbpf: add perf buffer API")Signed-off-by Arnaldo Carvalho de Melo <[email protected]>
Quoted 1 line
---
Thanks, Arnaldo!
Quoted 31 lines
tools/lib/bpf/libbpf.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)tools/lib/bpf/libbpf.c +7
-8@@ -4508,13 +4508,13 @@ struct perf_buffer *perf_buffer__new(int map_fd, size_t page_cnt, const struct perf_buffer_opts *opts) {struct perf_buffer_params p = {}; -struct perf_event_attr attr = { - .config =PERF_COUNT_SW_BPF_OUTPUT , - .type =PERF_TYPE_SOFTWARE , - .sample_type =PERF_SAMPLE_RAW , - .sample_period =1 , - .wakeup_events =1 , - }; +struct perf_event_attr attr = {0 , }; + + attr.config =PERF_COUNT_SW_BPF_OUTPUT , + attr.type =PERF_TYPE_SOFTWARE ; + attr.sample_type =PERF_SAMPLE_RAW ; + attr.sample_period =1 ; + attr.wakeup_events =1 ; p.attr = &attr; p.sample_cb = opts ? opts->sample_cb :NULL ; --2.21.0
Quoted 7 lines · Arnaldo Carvalho de Melo
Hi Daniel,
Please consider pulling or applying from the patches, if someone
has any issues, please holler,- Arnaldo
Quoted 8 lines
Arnaldo Carvalho de Melo (2):
libbpf: Fix endianness macro usage for some compilers
libbpf: Avoid designated initializers for unnamed union memberstools/lib/bpf/btf.c | 5 +++-- tools/lib/bpf/libbpf.c | 19 ++++++++++--------- 2 files changed, 13 insertions(+), 11 deletions(-)
Applied, thanks!