mirror of
https://git.proxmox.com/git/mirror_ubuntu-kernels.git
synced 2025-12-02 14:47:09 +00:00
Some architectures like powerpc support both endianness, it's therefore not possible to fix the endianness via arch/endianness.h because there is no easy way to get the target endianness at build time. Use the endianness recorded in the file objtool is working on. Tested-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com> Reviewed-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com> Acked-by: Josh Poimboeuf <jpoimboe@kernel.org> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org> Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Link: https://lore.kernel.org/r/20221114175754.1131267-10-sv@linux.ibm.com
39 lines
1.1 KiB
C
39 lines
1.1 KiB
C
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
#ifndef _OBJTOOL_ENDIANNESS_H
|
|
#define _OBJTOOL_ENDIANNESS_H
|
|
|
|
#include <linux/kernel.h>
|
|
#include <endian.h>
|
|
#include <objtool/elf.h>
|
|
|
|
/*
|
|
* Does a byte swap if target file endianness doesn't match the host, i.e. cross
|
|
* compilation for little endian on big endian and vice versa.
|
|
* To be used for multi-byte values conversion, which are read from / about
|
|
* to be written to a target native endianness ELF file.
|
|
*/
|
|
static inline bool need_bswap(struct elf *elf)
|
|
{
|
|
return (__BYTE_ORDER == __LITTLE_ENDIAN) ^
|
|
(elf->ehdr.e_ident[EI_DATA] == ELFDATA2LSB);
|
|
}
|
|
|
|
#define bswap_if_needed(elf, val) \
|
|
({ \
|
|
__typeof__(val) __ret; \
|
|
bool __need_bswap = need_bswap(elf); \
|
|
switch (sizeof(val)) { \
|
|
case 8: \
|
|
__ret = __need_bswap ? bswap_64(val) : (val); break; \
|
|
case 4: \
|
|
__ret = __need_bswap ? bswap_32(val) : (val); break; \
|
|
case 2: \
|
|
__ret = __need_bswap ? bswap_16(val) : (val); break; \
|
|
default: \
|
|
BUILD_BUG(); break; \
|
|
} \
|
|
__ret; \
|
|
})
|
|
|
|
#endif /* _OBJTOOL_ENDIANNESS_H */
|