xen/types: Cleanup
cover xen/types: Cleanup
Done both to avoid PPC64 bringing in yet another copy of some antipatterns, and because it fixes the MISRA issue relating to the __signed__ keyword.
https://gitlab.com/xen-project/people/andyhhp/xen/-/pipelines/907638603
Andrew Cooper (2):
xen/types: Drop #ifdefary for __{SIZE,PTRDIFF}_TYPE__ xen/types: Rework stdint vs __{u,s}$N types
xen/arch/arm/include/asm/types.h | 19 --------------- xen/arch/riscv/include/asm/types.h | 19 --------------- xen/arch/x86/include/asm/types.h | 21 ++++++++--------- xen/include/xen/types.h | 37 +++++++++++++++--------------- 4 files changed, 27 insertions(+), 69 deletions(-)
base-commit: 5c84f1f636981dab5341e84aaba8d4dd00bbc2cb
Signature · 1 line
2.30.2
PATCH 1/2 xen/types: Drop #ifdefary for __{SIZE,PTRDIFF}_TYPE__
All supported compilers have these types.
No functional change.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Volodymyr Babchuk <[email protected]>
CC: Bertrand Marquis <[email protected]>
CC: Bob Eshleman <[email protected]>
CC: Alistair Francis <[email protected]>
CC: Connor Davis <[email protected]>
CC: Oleksii Kurochko <[email protected]>
CC: Shawn Anastasio <[email protected]>
CC: Timothy Pearson <[email protected]>
https://godbolt.org/z/Y6PWcd6js
--- xen/include/xen/types.h | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-)
xen/include/xen/types.h +1 -8
@@ -5,18 +5,11 @@#include <asm/types.h> -#if defined(__SIZE_TYPE__)typedef __SIZE_TYPE__ size_t ; -#else -typedef unsigned long size_t ; -#endif +typedef signed long ssize_t ; -#if defined(__PTRDIFF_TYPE__)typedef __PTRDIFF_TYPE__ ptrdiff_t ; -#else -typedef signed long ptrdiff_t ; -#endif #define BITS_TO_LONGS (bits) \ (((bits)+BITS_PER_LONG-1)/BITS_PER_LONG)
Signature · 1 line
2.30.2
Re: [PATCH 1/2] xen/types: Drop #ifdefary for __{SIZE,PTRDIFF}_TYPE__
Quoted 6 lines · Andrew Cooper
All supported compilers have these types.
No functional change.
Signed-off-by Andrew Cooper <[email protected]>
Alistair
Quoted 48 lines
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Volodymyr Babchuk <[email protected]>
CC: Bertrand Marquis <[email protected]>
CC: Bob Eshleman <[email protected]>
CC: Alistair Francis <[email protected]>
CC: Connor Davis <[email protected]>
CC: Oleksii Kurochko <[email protected]>
CC: Shawn Anastasio <[email protected]>
CC: Timothy Pearson <[email protected]>https://godbolt.org/z/Y6PWcd6js
--- xen/include/xen/types.h | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-)xen/include/xen/types.h +1
-9@@ -5,18 +5,11 @@#include <asm/types.h> -#if defined(__SIZE_TYPE__)typedef __SIZE_TYPE__ size_t ; -#else -typedef unsigned long size_t ; -#endif +typedef signed long ssize_t ; -#if defined(__PTRDIFF_TYPE__)typedef __PTRDIFF_TYPE__ ptrdiff_t ; -#else -typedef signed long ptrdiff_t ; -#endif #define BITS_TO_LONGS (bits) \ (((bits)+BITS_PER_LONG-1)/BITS_PER_LONG) --2.30.2
Re: [PATCH 1/2] xen/types: Drop #ifdefary for __{SIZE,PTRDIFF}_TYPE__
In reply to Andrew CooperQuoted 5 lines · Andrew Cooper
All supported compilers have these types.
No functional change.
Signed-off-by Andrew Cooper <[email protected]>
PATCH 2/2 xen/types: Rework stdint vs __{u,s}$N types
In reply to Andrew CooperXen uses the stdint types. Rearrange the types headers to define the compatibility __{u,s}$N types in terms of the stdint types, not the other way around.
All all supported compilers on architectures other than x86 support the stdint __*_TYPE__ macros. Move these into the common types.h to avoid them being duplicated in each architecture.
For x86 on obsolete compilers, synthesize appropriate types.
This cleanup has the side effect of removing all use of the undocumented __signed__ GCC keyword. This is a vestigial remnant of gcc -traditional mode for dialetcs of C prior to the introduction of the signed keyword.
No functional change.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Volodymyr Babchuk <[email protected]>
CC: Bertrand Marquis <[email protected]>
CC: Bob Eshleman <[email protected]>
CC: Alistair Francis <[email protected]>
CC: Connor Davis <[email protected]>
CC: Oleksii Kurochko <[email protected]>
CC: Shawn Anastasio <[email protected]>
CC: Timothy Pearson <[email protected]>
CC: Roberto Bagnara <[email protected]>
I've left the non __ types alone for now. They're complicated mostly by ARM having differing ideas of what a paddr_t is.
A different option would be to sort out the stdint types ahead of including <asm/types.h>, which can either be done by introducing a <asm/stdint.h> or upping the minimum compiler version for x86; a task which is massively overdue.
--- xen/arch/arm/include/asm/types.h | 19 ------------------- xen/arch/riscv/include/asm/types.h | 19 ------------------- xen/arch/x86/include/asm/types.h | 21 +++++++++------------ xen/include/xen/types.h | 28 +++++++++++++++++----------- 4 files changed, 26 insertions(+), 61 deletions(-)
xen/arch/arm/include/asm/types.h +0 -19
@@ -1,25 +1,6 @@#ifndef __ARM_TYPES_H__#define __ARM_TYPES_H__ -typedef __signed__ char __s8; -typedef unsigned char __u8 ; - -typedef __signed__ short __s16 ; -typedef unsigned short __u16 ; - -typedef __signed__ int __s32; -typedef unsigned int __u32 ; - -#if defined(__GNUC__) && !defined(__STRICT_ANSI__) -#if defined(CONFIG_ARM_32 ) -typedef __signed__ long long __s64 ; -typedef unsigned long long __u64 ; -#elif defined (CONFIG_ARM_64 ) -typedef __signed__ long __s64 ; -typedef unsigned long __u64 ; -#endif -#endif -typedef signed char s8 ;typedef unsigned char u8 ;
xen/arch/riscv/include/asm/types.h +0 -19
@@ -1,25 +1,6 @@#ifndef __RISCV_TYPES_H__#define __RISCV_TYPES_H__ -typedef __signed__ char __s8; -typedef unsigned char __u8 ; - -typedef __signed__ short __s16 ; -typedef unsigned short __u16 ; - -typedef __signed__ int __s32; -typedef unsigned int __u32 ; - -#if defined(__GNUC__) && !defined(__STRICT_ANSI__) -#if defined(CONFIG_RISCV_32 ) -typedef __signed__ long long __s64 ; -typedef unsigned long long __u64 ; -#elif defined (CONFIG_RISCV_64 ) -typedef __signed__ long __s64 ; -typedef unsigned long __u64 ; -#endif -#endif -typedef signed char s8 ;typedef unsigned char u8 ;
xen/arch/x86/include/asm/types.h +9 -12
@@ -1,18 +1,15 @@#ifndef __X86_TYPES_H__#define __X86_TYPES_H__ -typedef __signed__ char __s8; -typedef unsigned char __u8 ; - -typedef __signed__ short __s16 ; -typedef unsigned short __u16 ; - -typedef __signed__ int __s32; -typedef unsigned int __u32 ; - -#if defined(__GNUC__) && !defined(__STRICT_ANSI__) -typedef __signed__ long __s64 ; -typedef unsigned long __u64 ; +#ifndef __INT8_TYPE__/* GCC <= 4.4 */ +# define __INT8_TYPE__ signed char +# define __UINT8_TYPE__ unsigned char +# define __INT16_TYPE__ short +# define __UINT16_TYPE__ unsigned short +# define __INT32_TYPE__ int +# define __UINT32_TYPE__ unsigned int +# define __INT64_TYPE__ long +# define __UINT64_TYPE__ unsigned long#endif typedef signed char s8 ;
xen/include/xen/types.h +17 -11
@@ -11,6 +11,15 @@ typedef signed long ssize_t;typedef __PTRDIFF_TYPE__ ptrdiff_t ; +typedef __INT8_TYPE__ int8_t ; +typedef __UINT8_TYPE__ uint8_t ; +typedef __INT16_TYPE__ int16_t ; +typedef __UINT16_TYPE__ uint16_t ; +typedef __INT32_TYPE__ int32_t ; +typedef __UINT32_TYPE__ uint32_t ; +typedef __INT64_TYPE__ int64_t ; +typedef __UINT64_TYPE__ uint64_t ; +#define BITS_TO_LONGS (bits) \ (((bits)+BITS_PER_LONG-1)/BITS_PER_LONG)#define DECLARE_BITMAP (name,bits) \
@@ -39,17 +48,14 @@ typedef __PTRDIFF_TYPE__ ptrdiff_t;#define LONG_MIN (-LONG_MAX - 1)#define ULONG_MAX (~0UL) -typedef __u8 uint8_t ; -typedef __s8 int8_t ; - -typedef __u16 uint16_t ; -typedef __s16 int16_t ; - -typedef __u32 uint32_t ; -typedef __s32 int32_t ; - -typedef __u64 uint64_t ; -typedef __s64 int64_t ; +typedef uint8_t __u8 ; +typedef int8_t __s8 ; +typedef uint16_t __u16 ; +typedef int16_t __s16 ; +typedef uint32_t __u32 ; +typedef int32_t __s32 ; +typedef uint64_t __u64 ; +typedef int64_t __s64 ;typedef __u16 __le16 ;typedef __u16 __be16 ;
Signature · 1 line
2.30.2
Re: [PATCH 2/2] xen/types: Rework stdint vs __{u,s}$N types
Quoted 11 lines · Andrew Cooper
Xen uses the stdint types. Rearrange the types headers to define the compatibility __{u,s}$N types in terms of the stdint types, not the other way around.
All all supported compilers on architectures other than x86 support the stdint __*_TYPE__ macros. Move these into the common
types.hto avoid them being duplicated in each architecture.For x86 on obsolete compilers, synthesize appropriate types.
Quoted 7 lines
This cleanup has the side effect of removing all use of the undocumented
__signed__GCC keyword. This is a vestigial remnant ofgcc -traditionalmode for dialetcs of C prior to the introduction of the signed keyword.No functional change.
Signed-off-by Andrew Cooper <[email protected]>
Alistair
Quoted 172 lines
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Volodymyr Babchuk <[email protected]>
CC: Bertrand Marquis <[email protected]>
CC: Bob Eshleman <[email protected]>
CC: Alistair Francis <[email protected]>
CC: Connor Davis <[email protected]>
CC: Oleksii Kurochko <[email protected]>
CC: Shawn Anastasio <[email protected]>
CC: Timothy Pearson <[email protected]>
CC: Roberto Bagnara <[email protected]>I've left the non __ types alone for now. They're complicated mostly by ARM having differing ideas of what a
paddr_tis.A different option would be to sort out the stdint types ahead of including <
asm/types.h>, which can either be done by introducing a <asm/stdint.h> or upping the minimum compiler version for x86; a task which is massively overdue.--- xen/arch/arm/include/asm/types.h | 19 ------------------- xen/arch/riscv/include/asm/types.h | 19 ------------------- xen/arch/x86/include/asm/types.h | 21 +++++++++------------ xen/include/xen/types.h | 28 +++++++++++++++++----------- 4 files changed, 26 insertions(+), 61 deletions(-)xen/arch/arm/include/asm/types.h +0
-19@@ -1,25 +1,6 @@#ifndef __ARM_TYPES_H__#define __ARM_TYPES_H__ -typedef __signed__ char __s8; -typedef unsigned char __u8 ; - -typedef __signed__ short __s16 ; -typedef unsigned short __u16 ; - -typedef __signed__ int __s32; -typedef unsigned int __u32 ; - -#if defined(__GNUC__) && !defined(__STRICT_ANSI__) -#if defined(CONFIG_ARM_32 ) -typedef __signed__ long long __s64 ; -typedef unsigned long long __u64 ; -#elif defined (CONFIG_ARM_64 ) -typedef __signed__ long __s64 ; -typedef unsigned long __u64 ; -#endif -#endif -typedef signed char s8 ;typedef unsigned char u8 ;xen/arch/riscv/include/asm/types.h +0
-19@@ -1,25 +1,6 @@#ifndef __RISCV_TYPES_H__#define __RISCV_TYPES_H__ -typedef __signed__ char __s8; -typedef unsigned char __u8 ; - -typedef __signed__ short __s16 ; -typedef unsigned short __u16 ; - -typedef __signed__ int __s32; -typedef unsigned int __u32 ; - -#if defined(__GNUC__) && !defined(__STRICT_ANSI__) -#if defined(CONFIG_RISCV_32 ) -typedef __signed__ long long __s64 ; -typedef unsigned long long __u64 ; -#elif defined (CONFIG_RISCV_64 ) -typedef __signed__ long __s64 ; -typedef unsigned long __u64 ; -#endif -#endif -typedef signed char s8 ;typedef unsigned char u8 ;xen/arch/x86/include/asm/types.h +9
-12@@ -1,18 +1,15 @@#ifndef __X86_TYPES_H__#define __X86_TYPES_H__ -typedef __signed__ char __s8; -typedef unsigned char __u8 ; - -typedef __signed__ short __s16 ; -typedef unsigned short __u16 ; - -typedef __signed__ int __s32; -typedef unsigned int __u32 ; - -#if defined(__GNUC__) && !defined(__STRICT_ANSI__) -typedef __signed__ long __s64 ; -typedef unsigned long __u64 ; +#ifndef __INT8_TYPE__/* GCC <= 4.4 */ +# define __INT8_TYPE__ signed char +# define __UINT8_TYPE__ unsigned char +# define __INT16_TYPE__ short +# define __UINT16_TYPE__ unsigned short +# define __INT32_TYPE__ int +# define __UINT32_TYPE__ unsigned int +# define __INT64_TYPE__ long +# define __UINT64_TYPE__ unsigned long#endif typedef signed char s8 ;xen/include/xen/types.h +17
-12@@ -11,6 +11,15 @@ typedef signed long ssize_t;typedef __PTRDIFF_TYPE__ ptrdiff_t ; +typedef __INT8_TYPE__ int8_t ; +typedef __UINT8_TYPE__ uint8_t ; +typedef __INT16_TYPE__ int16_t ; +typedef __UINT16_TYPE__ uint16_t ; +typedef __INT32_TYPE__ int32_t ; +typedef __UINT32_TYPE__ uint32_t ; +typedef __INT64_TYPE__ int64_t ; +typedef __UINT64_TYPE__ uint64_t ; +#define BITS_TO_LONGS (bits) \ (((bits)+BITS_PER_LONG-1)/BITS_PER_LONG)#define DECLARE_BITMAP (name,bits) \@@ -39,17 +48,14 @@ typedef __PTRDIFF_TYPE__ ptrdiff_t;#define LONG_MIN (-LONG_MAX - 1)#define ULONG_MAX (~0UL) -typedef __u8 uint8_t ; -typedef __s8 int8_t ; - -typedef __u16 uint16_t ; -typedef __s16 int16_t ; - -typedef __u32 uint32_t ; -typedef __s32 int32_t ; - -typedef __u64 uint64_t ; -typedef __s64 int64_t ; +typedef uint8_t __u8 ; +typedef int8_t __s8 ; +typedef uint16_t __u16 ; +typedef int16_t __s16 ; +typedef uint32_t __u32 ; +typedef int32_t __s32 ; +typedef uint64_t __u64 ; +typedef int64_t __s64 ;typedef __u16 __le16 ;typedef __u16 __be16 ; --2.30.2
Re: [PATCH 2/2] xen/types: Rework stdint vs __{u,s}$N types
In reply to Andrew CooperQuoted 4 lines · Andrew Cooper
A different option would be to sort out the stdint types ahead of including <
asm/types.h>, which can either be done by introducing a <asm/stdint.h> or upping the minimum compiler version for x86; a task which is massively overdue.
As per my patch moving in this same direction, I strongly think this is the direction we want to take. (I don't see a reason to introduce asm/stdint.h for this - the logic you put in x86'es asm/types.h can well be put in xen/types.h as well, suitably limited by a slightly more involved #if than you have it now.)
Personally I think using "mode" attributes for the fallbacks would be the more widely compatible way, but I'm not going to object to your approach avoiding them. It would feel more safe though if without using that attribute the fallback wasn't tied to __INT8_TYPE__ being defined (but instead directly to being on very old gcc).
As to upping the minimal gcc version for x86: While I'm pretty sure I'm considered the hindering factor here, I continue to think that my "blocking" request isn't unreasonable at all: We want to establish clear criteria, by which we can then also go in the future. And we want to make clear what, if any, baseline requirements are acceptable to put up beyond consideration of just binutils and compilers (basic utilities, make, perl, python, etc).
Jan