提交 6d49ff90 编写于 作者: I Ilya Leoshkevich 提交者: Zheng Zengkai

libbpf: Use __BYTE_ORDER__

mainline inclusion
from mainline-5.16-rc1
commit 3930198d
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I5EUVD
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=3930198dc9a0720a2b6561c67e55859ec51b73f9

-------------------------------------------------

Use the compiler-defined __BYTE_ORDER__ instead of the libc-defined
__BYTE_ORDER for consistency.
Signed-off-by: NIlya Leoshkevich <iii@linux.ibm.com>
Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20211026010831.748682-3-iii@linux.ibm.com
(cherry picked from commit 3930198d)
Signed-off-by: NWang Yufen <wangyufen@huawei.com>

Conflicts:
	tools/lib/bpf/btf_dump.c
Signed-off-by: NWang Yufen <wangyufen@huawei.com>
上级 ab6530c3
...@@ -533,9 +533,9 @@ int btf__set_pointer_size(struct btf *btf, size_t ptr_sz) ...@@ -533,9 +533,9 @@ int btf__set_pointer_size(struct btf *btf, size_t ptr_sz)
static bool is_host_big_endian(void) static bool is_host_big_endian(void)
{ {
#if __BYTE_ORDER == __LITTLE_ENDIAN #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
return false; return false;
#elif __BYTE_ORDER == __BIG_ENDIAN #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
return true; return true;
#else #else
# error "Unrecognized __BYTE_ORDER__" # error "Unrecognized __BYTE_ORDER__"
......
...@@ -1584,10 +1584,10 @@ static int btf_dump_get_bitfield_value(struct btf_dump *d, ...@@ -1584,10 +1584,10 @@ static int btf_dump_get_bitfield_value(struct btf_dump *d,
*/ */
nr_copy_bits = bit_sz + bits_offset; nr_copy_bits = bit_sz + bits_offset;
nr_copy_bytes = t->size; nr_copy_bytes = t->size;
#if __BYTE_ORDER == __LITTLE_ENDIAN #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
for (i = nr_copy_bytes - 1; i >= 0; i--) for (i = nr_copy_bytes - 1; i >= 0; i--)
num = num * 256 + bytes[i]; num = num * 256 + bytes[i];
#elif __BYTE_ORDER == __BIG_ENDIAN #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
for (i = 0; i < nr_copy_bytes; i++) for (i = 0; i < nr_copy_bytes; i++)
num = num * 256 + bytes[i]; num = num * 256 + bytes[i];
#else #else
...@@ -1697,10 +1697,10 @@ static int btf_dump_int_data(struct btf_dump *d, ...@@ -1697,10 +1697,10 @@ static int btf_dump_int_data(struct btf_dump *d,
/* avoid use of __int128 as some 32-bit platforms do not /* avoid use of __int128 as some 32-bit platforms do not
* support it. * support it.
*/ */
#if __BYTE_ORDER == __LITTLE_ENDIAN #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
lsi = ints[0]; lsi = ints[0];
msi = ints[1]; msi = ints[1];
#elif __BYTE_ORDER == __BIG_ENDIAN #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
lsi = ints[1]; lsi = ints[1];
msi = ints[0]; msi = ints[0];
#else #else
......
...@@ -1270,10 +1270,10 @@ static int bpf_object__elf_init(struct bpf_object *obj) ...@@ -1270,10 +1270,10 @@ static int bpf_object__elf_init(struct bpf_object *obj)
static int bpf_object__check_endianness(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) if (obj->efile.ehdr->e_ident[EI_DATA] == ELFDATA2LSB)
return 0; return 0;
#elif __BYTE_ORDER == __BIG_ENDIAN #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
if (obj->efile.ehdr->e_ident[EI_DATA] == ELFDATA2MSB) if (obj->efile.ehdr->e_ident[EI_DATA] == ELFDATA2MSB)
return 0; return 0;
#else #else
......
...@@ -323,12 +323,12 @@ static int init_output_elf(struct bpf_linker *linker, const char *file) ...@@ -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_machine = EM_BPF;
linker->elf_hdr->e_type = ET_REL; 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; 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; linker->elf_hdr->e_ident[EI_DATA] = ELFDATA2MSB;
#else #else
#error "Unknown __BYTE_ORDER" #error "Unknown __BYTE_ORDER__"
#endif #endif
/* STRTAB */ /* STRTAB */
...@@ -538,12 +538,12 @@ static int linker_load_obj_file(struct bpf_linker *linker, const char *filename, ...@@ -538,12 +538,12 @@ static int linker_load_obj_file(struct bpf_linker *linker, const char *filename,
const struct bpf_linker_file_opts *opts, const struct bpf_linker_file_opts *opts,
struct src_obj *obj) struct src_obj *obj)
{ {
#if __BYTE_ORDER == __LITTLE_ENDIAN #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
const int host_endianness = ELFDATA2LSB; const int host_endianness = ELFDATA2LSB;
#elif __BYTE_ORDER == __BIG_ENDIAN #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
const int host_endianness = ELFDATA2MSB; const int host_endianness = ELFDATA2MSB;
#else #else
#error "Unknown __BYTE_ORDER" #error "Unknown __BYTE_ORDER__"
#endif #endif
int err = 0; int err = 0;
Elf_Scn *scn; Elf_Scn *scn;
......
...@@ -662,7 +662,7 @@ static int bpf_core_calc_field_relo(const char *prog_name, ...@@ -662,7 +662,7 @@ static int bpf_core_calc_field_relo(const char *prog_name,
*validate = true; /* signedness is never ambiguous */ *validate = true; /* signedness is never ambiguous */
break; break;
case BPF_FIELD_LSHIFT_U64: 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); *val = 64 - (bit_off + bit_sz - byte_off * 8);
#else #else
*val = (8 - byte_sz) * 8 + (bit_off - byte_off * 8); *val = (8 - byte_sz) * 8 + (bit_off - byte_off * 8);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册