diff mbox series

[bpf-next,v3,2/6] libbpf: Use __BYTE_ORDER__

Message ID 20211026010831.748682-3-iii@linux.ibm.com (mailing list archive)
State Accepted
Delegated to: BPF
Headers show
Series core_reloc fixes for s390 | expand

Checks

Context Check Description
bpf/vmtest-bpf-next-PR success PR summary
bpf/vmtest-bpf-next success VM_Test
netdev/cover_letter success Series has a cover letter
netdev/fixes_present success Fixes tag not required for -next series
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for bpf-next
netdev/subject_prefix success Link
netdev/cc_maintainers warning 7 maintainers not CCed: john.fastabend@gmail.com yhs@fb.com netdev@vger.kernel.org songliubraving@fb.com kafai@fb.com kpsingh@kernel.org andrii@kernel.org
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success No Fixes tag
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 86 lines checked
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/header_inline success No static functions without inline keyword in header files

Commit Message

Ilya Leoshkevich Oct. 26, 2021, 1:08 a.m. UTC
Use the compiler-defined __BYTE_ORDER__ instead of the libc-defined
__BYTE_ORDER for consistency.

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
---
 tools/lib/bpf/btf.c       |  4 ++--
 tools/lib/bpf/btf_dump.c  |  8 ++++----
 tools/lib/bpf/libbpf.c    |  4 ++--
 tools/lib/bpf/linker.c    | 12 ++++++------
 tools/lib/bpf/relo_core.c |  2 +-
 5 files changed, 15 insertions(+), 15 deletions(-)

Comments

Arnaldo Carvalho de Melo Oct. 27, 2021, 7:05 p.m. UTC | #1
Em Tue, Oct 26, 2021 at 03:08:27AM +0200, Ilya Leoshkevich escreveu:
> Use the compiler-defined __BYTE_ORDER__ instead of the libc-defined
> __BYTE_ORDER for consistency.

There are some in tools/perf/:

⬢[acme@toolbox perf]$ find tools/perf -name "*.[ch]" | xargs grep -w __BYTE_ORDER
tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.c:#if __BYTE_ORDER == __BIG_ENDIAN
tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c:#if __BYTE_ORDER == __BIG_ENDIAN
tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.c:#if __BYTE_ORDER == __BIG_ENDIAN
tools/perf/util/genelf.h:#if __BYTE_ORDER == __BIG_ENDIAN
tools/perf/util/intel-bts.c:#if __BYTE_ORDER == __BIG_ENDIAN
tools/perf/util/s390-cpumsf.c:#if __BYTE_ORDER == __LITTLE_ENDIAN
tools/perf/util/s390-cpumsf.c:#if __BYTE_ORDER == __LITTLE_ENDIAN
tools/perf/util/s390-cpumsf.c:#if __BYTE_ORDER == __LITTLE_ENDIAN
tools/perf/util/s390-cpumsf.c:#if __BYTE_ORDER == __LITTLE_ENDIAN
tools/perf/util/data-convert-bt.c:#if __BYTE_ORDER == __BIG_ENDIAN
⬢[acme@toolbox perf]$

Please consider submitting a patch for those as well, please :-)

- Arnaldo
 
> Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
> ---
>  tools/lib/bpf/btf.c       |  4 ++--
>  tools/lib/bpf/btf_dump.c  |  8 ++++----
>  tools/lib/bpf/libbpf.c    |  4 ++--
>  tools/lib/bpf/linker.c    | 12 ++++++------
>  tools/lib/bpf/relo_core.c |  2 +-
>  5 files changed, 15 insertions(+), 15 deletions(-)
> 
> diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
> index ef924fc2c911..0c628c33e23b 100644
> --- a/tools/lib/bpf/btf.c
> +++ b/tools/lib/bpf/btf.c
> @@ -538,9 +538,9 @@ int btf__set_pointer_size(struct btf *btf, size_t ptr_sz)
>  
>  static bool is_host_big_endian(void)
>  {
> -#if __BYTE_ORDER == __LITTLE_ENDIAN
> +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
>  	return false;
> -#elif __BYTE_ORDER == __BIG_ENDIAN
> +#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
>  	return true;
>  #else
>  # error "Unrecognized __BYTE_ORDER__"
> diff --git a/tools/lib/bpf/btf_dump.c b/tools/lib/bpf/btf_dump.c
> index 8e05ab44c22a..17db62b5002e 100644
> --- a/tools/lib/bpf/btf_dump.c
> +++ b/tools/lib/bpf/btf_dump.c
> @@ -1576,11 +1576,11 @@ static int btf_dump_get_bitfield_value(struct btf_dump *d,
>  	/* Bitfield value retrieval is done in two steps; first relevant bytes are
>  	 * stored in num, then we left/right shift num to eliminate irrelevant bits.
>  	 */
> -#if __BYTE_ORDER == __LITTLE_ENDIAN
> +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
>  	for (i = t->size - 1; i >= 0; i--)
>  		num = num * 256 + bytes[i];
>  	nr_copy_bits = bit_sz + bits_offset;
> -#elif __BYTE_ORDER == __BIG_ENDIAN
> +#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
>  	for (i = 0; i < t->size; i++)
>  		num = num * 256 + bytes[i];
>  	nr_copy_bits = t->size * 8 - bits_offset;
> @@ -1700,10 +1700,10 @@ static int btf_dump_int_data(struct btf_dump *d,
>  		/* avoid use of __int128 as some 32-bit platforms do not
>  		 * support it.
>  		 */
> -#if __BYTE_ORDER == __LITTLE_ENDIAN
> +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
>  		lsi = ints[0];
>  		msi = ints[1];
> -#elif __BYTE_ORDER == __BIG_ENDIAN
> +#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
>  		lsi = ints[1];
>  		msi = ints[0];
>  #else
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index 604abe00785f..cd6132c5a416 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -1299,10 +1299,10 @@ static int bpf_object__elf_init(struct bpf_object *obj)
>  
>  static int bpf_object__check_endianness(struct bpf_object *obj)
>  {
> -#if __BYTE_ORDER == __LITTLE_ENDIAN
> +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
>  	if (obj->efile.ehdr->e_ident[EI_DATA] == ELFDATA2LSB)
>  		return 0;
> -#elif __BYTE_ORDER == __BIG_ENDIAN
> +#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
>  	if (obj->efile.ehdr->e_ident[EI_DATA] == ELFDATA2MSB)
>  		return 0;
>  #else
> diff --git a/tools/lib/bpf/linker.c b/tools/lib/bpf/linker.c
> index 7bf658fbda80..ce0800e61dc7 100644
> --- a/tools/lib/bpf/linker.c
> +++ b/tools/lib/bpf/linker.c
> @@ -323,12 +323,12 @@ static int init_output_elf(struct bpf_linker *linker, const char *file)
>  
>  	linker->elf_hdr->e_machine = EM_BPF;
>  	linker->elf_hdr->e_type = ET_REL;
> -#if __BYTE_ORDER == __LITTLE_ENDIAN
> +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
>  	linker->elf_hdr->e_ident[EI_DATA] = ELFDATA2LSB;
> -#elif __BYTE_ORDER == __BIG_ENDIAN
> +#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
>  	linker->elf_hdr->e_ident[EI_DATA] = ELFDATA2MSB;
>  #else
> -#error "Unknown __BYTE_ORDER"
> +#error "Unknown __BYTE_ORDER__"
>  #endif
>  
>  	/* STRTAB */
> @@ -538,12 +538,12 @@ static int linker_load_obj_file(struct bpf_linker *linker, const char *filename,
>  				const struct bpf_linker_file_opts *opts,
>  				struct src_obj *obj)
>  {
> -#if __BYTE_ORDER == __LITTLE_ENDIAN
> +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
>  	const int host_endianness = ELFDATA2LSB;
> -#elif __BYTE_ORDER == __BIG_ENDIAN
> +#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
>  	const int host_endianness = ELFDATA2MSB;
>  #else
> -#error "Unknown __BYTE_ORDER"
> +#error "Unknown __BYTE_ORDER__"
>  #endif
>  	int err = 0;
>  	Elf_Scn *scn;
> diff --git a/tools/lib/bpf/relo_core.c b/tools/lib/bpf/relo_core.c
> index 4016ed492d0c..b5b8956a1be8 100644
> --- a/tools/lib/bpf/relo_core.c
> +++ b/tools/lib/bpf/relo_core.c
> @@ -662,7 +662,7 @@ static int bpf_core_calc_field_relo(const char *prog_name,
>  			*validate = true; /* signedness is never ambiguous */
>  		break;
>  	case BPF_FIELD_LSHIFT_U64:
> -#if __BYTE_ORDER == __LITTLE_ENDIAN
> +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
>  		*val = 64 - (bit_off + bit_sz - byte_off  * 8);
>  #else
>  		*val = (8 - byte_sz) * 8 + (bit_off - byte_off * 8);
> -- 
> 2.31.1
diff mbox series

Patch

diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
index ef924fc2c911..0c628c33e23b 100644
--- a/tools/lib/bpf/btf.c
+++ b/tools/lib/bpf/btf.c
@@ -538,9 +538,9 @@  int btf__set_pointer_size(struct btf *btf, size_t ptr_sz)
 
 static bool is_host_big_endian(void)
 {
-#if __BYTE_ORDER == __LITTLE_ENDIAN
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
 	return false;
-#elif __BYTE_ORDER == __BIG_ENDIAN
+#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
 	return true;
 #else
 # error "Unrecognized __BYTE_ORDER__"
diff --git a/tools/lib/bpf/btf_dump.c b/tools/lib/bpf/btf_dump.c
index 8e05ab44c22a..17db62b5002e 100644
--- a/tools/lib/bpf/btf_dump.c
+++ b/tools/lib/bpf/btf_dump.c
@@ -1576,11 +1576,11 @@  static int btf_dump_get_bitfield_value(struct btf_dump *d,
 	/* Bitfield value retrieval is done in two steps; first relevant bytes are
 	 * stored in num, then we left/right shift num to eliminate irrelevant bits.
 	 */
-#if __BYTE_ORDER == __LITTLE_ENDIAN
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
 	for (i = t->size - 1; i >= 0; i--)
 		num = num * 256 + bytes[i];
 	nr_copy_bits = bit_sz + bits_offset;
-#elif __BYTE_ORDER == __BIG_ENDIAN
+#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
 	for (i = 0; i < t->size; i++)
 		num = num * 256 + bytes[i];
 	nr_copy_bits = t->size * 8 - bits_offset;
@@ -1700,10 +1700,10 @@  static int btf_dump_int_data(struct btf_dump *d,
 		/* avoid use of __int128 as some 32-bit platforms do not
 		 * support it.
 		 */
-#if __BYTE_ORDER == __LITTLE_ENDIAN
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
 		lsi = ints[0];
 		msi = ints[1];
-#elif __BYTE_ORDER == __BIG_ENDIAN
+#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
 		lsi = ints[1];
 		msi = ints[0];
 #else
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 604abe00785f..cd6132c5a416 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -1299,10 +1299,10 @@  static int bpf_object__elf_init(struct bpf_object *obj)
 
 static int bpf_object__check_endianness(struct bpf_object *obj)
 {
-#if __BYTE_ORDER == __LITTLE_ENDIAN
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
 	if (obj->efile.ehdr->e_ident[EI_DATA] == ELFDATA2LSB)
 		return 0;
-#elif __BYTE_ORDER == __BIG_ENDIAN
+#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
 	if (obj->efile.ehdr->e_ident[EI_DATA] == ELFDATA2MSB)
 		return 0;
 #else
diff --git a/tools/lib/bpf/linker.c b/tools/lib/bpf/linker.c
index 7bf658fbda80..ce0800e61dc7 100644
--- a/tools/lib/bpf/linker.c
+++ b/tools/lib/bpf/linker.c
@@ -323,12 +323,12 @@  static int init_output_elf(struct bpf_linker *linker, const char *file)
 
 	linker->elf_hdr->e_machine = EM_BPF;
 	linker->elf_hdr->e_type = ET_REL;
-#if __BYTE_ORDER == __LITTLE_ENDIAN
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
 	linker->elf_hdr->e_ident[EI_DATA] = ELFDATA2LSB;
-#elif __BYTE_ORDER == __BIG_ENDIAN
+#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
 	linker->elf_hdr->e_ident[EI_DATA] = ELFDATA2MSB;
 #else
-#error "Unknown __BYTE_ORDER"
+#error "Unknown __BYTE_ORDER__"
 #endif
 
 	/* STRTAB */
@@ -538,12 +538,12 @@  static int linker_load_obj_file(struct bpf_linker *linker, const char *filename,
 				const struct bpf_linker_file_opts *opts,
 				struct src_obj *obj)
 {
-#if __BYTE_ORDER == __LITTLE_ENDIAN
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
 	const int host_endianness = ELFDATA2LSB;
-#elif __BYTE_ORDER == __BIG_ENDIAN
+#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
 	const int host_endianness = ELFDATA2MSB;
 #else
-#error "Unknown __BYTE_ORDER"
+#error "Unknown __BYTE_ORDER__"
 #endif
 	int err = 0;
 	Elf_Scn *scn;
diff --git a/tools/lib/bpf/relo_core.c b/tools/lib/bpf/relo_core.c
index 4016ed492d0c..b5b8956a1be8 100644
--- a/tools/lib/bpf/relo_core.c
+++ b/tools/lib/bpf/relo_core.c
@@ -662,7 +662,7 @@  static int bpf_core_calc_field_relo(const char *prog_name,
 			*validate = true; /* signedness is never ambiguous */
 		break;
 	case BPF_FIELD_LSHIFT_U64:
-#if __BYTE_ORDER == __LITTLE_ENDIAN
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
 		*val = 64 - (bit_off + bit_sz - byte_off  * 8);
 #else
 		*val = (8 - byte_sz) * 8 + (bit_off - byte_off * 8);