Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

libbpf: Use __BYTE_ORDER__

Use the compiler-defined __BYTE_ORDER__ instead of the libc-defined
__BYTE_ORDER for consistency.

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20211026010831.748682-3-iii@linux.ibm.com

authored by

Ilya Leoshkevich and committed by
Andrii Nakryiko
3930198d 45f2bebc

+15 -15
+2 -2
tools/lib/bpf/btf.c
··· 538 538 539 539 static bool is_host_big_endian(void) 540 540 { 541 - #if __BYTE_ORDER == __LITTLE_ENDIAN 541 + #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 542 542 return false; 543 - #elif __BYTE_ORDER == __BIG_ENDIAN 543 + #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ 544 544 return true; 545 545 #else 546 546 # error "Unrecognized __BYTE_ORDER__"
+4 -4
tools/lib/bpf/btf_dump.c
··· 1576 1576 /* Bitfield value retrieval is done in two steps; first relevant bytes are 1577 1577 * stored in num, then we left/right shift num to eliminate irrelevant bits. 1578 1578 */ 1579 - #if __BYTE_ORDER == __LITTLE_ENDIAN 1579 + #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 1580 1580 for (i = t->size - 1; i >= 0; i--) 1581 1581 num = num * 256 + bytes[i]; 1582 1582 nr_copy_bits = bit_sz + bits_offset; 1583 - #elif __BYTE_ORDER == __BIG_ENDIAN 1583 + #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ 1584 1584 for (i = 0; i < t->size; i++) 1585 1585 num = num * 256 + bytes[i]; 1586 1586 nr_copy_bits = t->size * 8 - bits_offset; ··· 1700 1700 /* avoid use of __int128 as some 32-bit platforms do not 1701 1701 * support it. 1702 1702 */ 1703 - #if __BYTE_ORDER == __LITTLE_ENDIAN 1703 + #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 1704 1704 lsi = ints[0]; 1705 1705 msi = ints[1]; 1706 - #elif __BYTE_ORDER == __BIG_ENDIAN 1706 + #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ 1707 1707 lsi = ints[1]; 1708 1708 msi = ints[0]; 1709 1709 #else
+2 -2
tools/lib/bpf/libbpf.c
··· 1299 1299 1300 1300 static int bpf_object__check_endianness(struct bpf_object *obj) 1301 1301 { 1302 - #if __BYTE_ORDER == __LITTLE_ENDIAN 1302 + #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 1303 1303 if (obj->efile.ehdr->e_ident[EI_DATA] == ELFDATA2LSB) 1304 1304 return 0; 1305 - #elif __BYTE_ORDER == __BIG_ENDIAN 1305 + #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ 1306 1306 if (obj->efile.ehdr->e_ident[EI_DATA] == ELFDATA2MSB) 1307 1307 return 0; 1308 1308 #else
+6 -6
tools/lib/bpf/linker.c
··· 323 323 324 324 linker->elf_hdr->e_machine = EM_BPF; 325 325 linker->elf_hdr->e_type = ET_REL; 326 - #if __BYTE_ORDER == __LITTLE_ENDIAN 326 + #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 327 327 linker->elf_hdr->e_ident[EI_DATA] = ELFDATA2LSB; 328 - #elif __BYTE_ORDER == __BIG_ENDIAN 328 + #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ 329 329 linker->elf_hdr->e_ident[EI_DATA] = ELFDATA2MSB; 330 330 #else 331 - #error "Unknown __BYTE_ORDER" 331 + #error "Unknown __BYTE_ORDER__" 332 332 #endif 333 333 334 334 /* STRTAB */ ··· 538 538 const struct bpf_linker_file_opts *opts, 539 539 struct src_obj *obj) 540 540 { 541 - #if __BYTE_ORDER == __LITTLE_ENDIAN 541 + #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 542 542 const int host_endianness = ELFDATA2LSB; 543 - #elif __BYTE_ORDER == __BIG_ENDIAN 543 + #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ 544 544 const int host_endianness = ELFDATA2MSB; 545 545 #else 546 - #error "Unknown __BYTE_ORDER" 546 + #error "Unknown __BYTE_ORDER__" 547 547 #endif 548 548 int err = 0; 549 549 Elf_Scn *scn;
+1 -1
tools/lib/bpf/relo_core.c
··· 662 662 *validate = true; /* signedness is never ambiguous */ 663 663 break; 664 664 case BPF_FIELD_LSHIFT_U64: 665 - #if __BYTE_ORDER == __LITTLE_ENDIAN 665 + #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 666 666 *val = 64 - (bit_off + bit_sz - byte_off * 8); 667 667 #else 668 668 *val = (8 - byte_sz) * 8 + (bit_off - byte_off * 8);