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

ARM: 7822/1: add workaround for ambiguous C99 stdint.h types

The C99 types uintXX_t that are usually defined in 'stdint.h' are not as
unambiguous on ARM as you would expect. For the types below, there is a
difference on ARM between GCC built for bare metal ARM, GCC built for glibc
and the kernel itself, which results in build errors if you try to build with
-ffreestanding and include 'stdint.h' (such as when you include 'arm_neon.h'
in order to use NEON intrinsics)

As the typedefs for these types in 'stdint.h' are based on builtin defines
supplied by GCC, we can tweak these to align with the kernel's idea of those
types, so 'linux/types.h' and 'stdint.h' can be safely included from the same
source file (provided that -ffreestanding is used).

int32_t uint32_t uintptr_t
bare metal GCC long unsigned long unsigned int
glibc GCC int unsigned int unsigned int
kernel int unsigned int unsigned long

Acked by: Dave Martin <dave.martin@arm.com>

Acked-by: Nicolas Pitre <nico@linaro.org>
Acked-by: Mikael Pettersson <mikpe@it.uu.se>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>

authored by

Ard Biesheuvel and committed by
Russell King
09096f6a 505caa66

+40
+40
arch/arm/include/asm/types.h
··· 1 + #ifndef _ASM_TYPES_H 2 + #define _ASM_TYPES_H 3 + 4 + #include <asm-generic/int-ll64.h> 5 + 6 + /* 7 + * The C99 types uintXX_t that are usually defined in 'stdint.h' are not as 8 + * unambiguous on ARM as you would expect. For the types below, there is a 9 + * difference on ARM between GCC built for bare metal ARM, GCC built for glibc 10 + * and the kernel itself, which results in build errors if you try to build with 11 + * -ffreestanding and include 'stdint.h' (such as when you include 'arm_neon.h' 12 + * in order to use NEON intrinsics) 13 + * 14 + * As the typedefs for these types in 'stdint.h' are based on builtin defines 15 + * supplied by GCC, we can tweak these to align with the kernel's idea of those 16 + * types, so 'linux/types.h' and 'stdint.h' can be safely included from the same 17 + * source file (provided that -ffreestanding is used). 18 + * 19 + * int32_t uint32_t uintptr_t 20 + * bare metal GCC long unsigned long unsigned int 21 + * glibc GCC int unsigned int unsigned int 22 + * kernel int unsigned int unsigned long 23 + */ 24 + 25 + #ifdef __INT32_TYPE__ 26 + #undef __INT32_TYPE__ 27 + #define __INT32_TYPE__ int 28 + #endif 29 + 30 + #ifdef __UINT32_TYPE__ 31 + #undef __UINT32_TYPE__ 32 + #define __UINT32_TYPE__ unsigned int 33 + #endif 34 + 35 + #ifdef __UINTPTR_TYPE__ 36 + #undef __UINTPTR_TYPE__ 37 + #define __UINTPTR_TYPE__ unsigned long 38 + #endif 39 + 40 + #endif /* _ASM_TYPES_H */