diff mbox series

[v2,3/3] xen/types: Rework stdint vs __{u,s}$N types

Message ID 20230627075618.1180248-4-andrew.cooper3@citrix.com (mailing list archive)
State New, archived
Headers show
Series xen/types: Cleanup | expand

Commit Message

Andrew Cooper June 27, 2023, 7:56 a.m. UTC
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 a new xen/stdint.h to avoid them being
duplicated in each architecture.

For the compilers which don't support the __*_TYPE__ macros, synthesize
appropriate alternatives.

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.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>
CC: Roger Pau Monné <roger.pau@citrix.com>
CC: Wei Liu <wl@xen.org>
CC: Stefano Stabellini <sstabellini@kernel.org>
CC: Julien Grall <julien@xen.org>
CC: Volodymyr Babchuk <Volodymyr_Babchuk@epam.com>
CC: Bertrand Marquis <bertrand.marquis@arm.com>
CC: Bob Eshleman <bobbyeshleman@gmail.com>
CC: Alistair Francis <alistair.francis@wdc.com>
CC: Connor Davis <connojdavis@gmail.com>
CC: Oleksii Kurochko <oleksii.kurochko@gmail.com>
CC: Shawn Anastasio <sanastasio@raptorengineering.com>
CC: Timothy Pearson <tpearson@raptorengineering.com>
CC: Roberto Bagnara <roberto.bagnara@bugseng.com>

v2:
 * Introduce xen/stdint.h as discussed at XenSummit
---
 xen/arch/arm/include/asm/types.h   | 19 -----------------
 xen/arch/riscv/include/asm/types.h | 19 -----------------
 xen/arch/x86/include/asm/types.h   | 14 -------------
 xen/include/xen/stdint.h           | 33 ++++++++++++++++++++++++++++++
 xen/include/xen/types.h            | 20 ++++++++----------
 5 files changed, 42 insertions(+), 63 deletions(-)
 create mode 100644 xen/include/xen/stdint.h

Comments

Oleksii K. June 27, 2023, 8:27 a.m. UTC | #1
Reviewed-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>

On Tue, 2023-06-27 at 08:56 +0100, Andrew Cooper wrote:
> 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 a new xen/stdint.h to avoid them
> being
> duplicated in each architecture.
> 
> For the compilers which don't support the __*_TYPE__ macros,
> synthesize
> appropriate alternatives.
> 
> 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.
> 
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
> ---
> CC: Jan Beulich <JBeulich@suse.com>
> CC: Roger Pau Monné <roger.pau@citrix.com>
> CC: Wei Liu <wl@xen.org>
> CC: Stefano Stabellini <sstabellini@kernel.org>
> CC: Julien Grall <julien@xen.org>
> CC: Volodymyr Babchuk <Volodymyr_Babchuk@epam.com>
> CC: Bertrand Marquis <bertrand.marquis@arm.com>
> CC: Bob Eshleman <bobbyeshleman@gmail.com>
> CC: Alistair Francis <alistair.francis@wdc.com>
> CC: Connor Davis <connojdavis@gmail.com>
> CC: Oleksii Kurochko <oleksii.kurochko@gmail.com>
> CC: Shawn Anastasio <sanastasio@raptorengineering.com>
> CC: Timothy Pearson <tpearson@raptorengineering.com>
> CC: Roberto Bagnara <roberto.bagnara@bugseng.com>
> 
> v2:
>  * Introduce xen/stdint.h as discussed at XenSummit
> ---
>  xen/arch/arm/include/asm/types.h   | 19 -----------------
>  xen/arch/riscv/include/asm/types.h | 19 -----------------
>  xen/arch/x86/include/asm/types.h   | 14 -------------
>  xen/include/xen/stdint.h           | 33
> ++++++++++++++++++++++++++++++
>  xen/include/xen/types.h            | 20 ++++++++----------
>  5 files changed, 42 insertions(+), 63 deletions(-)
>  create mode 100644 xen/include/xen/stdint.h
> 
> diff --git a/xen/arch/arm/include/asm/types.h
> b/xen/arch/arm/include/asm/types.h
> index fb6618ef247f..545a5e9d1175 100644
> --- a/xen/arch/arm/include/asm/types.h
> +++ b/xen/arch/arm/include/asm/types.h
> @@ -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;
>  
> diff --git a/xen/arch/riscv/include/asm/types.h
> b/xen/arch/riscv/include/asm/types.h
> index 0c0ce78c8f6e..93a680a8f323 100644
> --- a/xen/arch/riscv/include/asm/types.h
> +++ b/xen/arch/riscv/include/asm/types.h
> @@ -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;
>  
> diff --git a/xen/arch/x86/include/asm/types.h
> b/xen/arch/x86/include/asm/types.h
> index 2d56aed66782..c9d257716551 100644
> --- a/xen/arch/x86/include/asm/types.h
> +++ b/xen/arch/x86/include/asm/types.h
> @@ -1,20 +1,6 @@
>  #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;
> -#endif
> -
>  typedef signed char s8;
>  typedef unsigned char u8;
>  
> diff --git a/xen/include/xen/stdint.h b/xen/include/xen/stdint.h
> new file mode 100644
> index 000000000000..4cf82790f196
> --- /dev/null
> +++ b/xen/include/xen/stdint.h
> @@ -0,0 +1,33 @@
> +/* SPDX-License-Identifier: GPL-2.0-only */
> +#ifndef __XEN_STDINT_H__
> +#define __XEN_STDINT_H__
> +
> +#ifndef __INT8_TYPE__ /* GCC <= 4.4 */
> +
> +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;
> +
> +#else
> +
> +/*
> + * Define the types using GCC internal notation.  Clang understands
> this too.
> + *
> https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html
> + */
> +typedef   signed __attribute__((__mode__(QI)))     int8_t;
> +typedef unsigned __attribute__((__mode__(QI)))    uint8_t;
> +typedef   signed __attribute__((__mode__(HI)))    int16_t;
> +typedef unsigned __attribute__((__mode__(HI)))   uint16_t;
> +typedef   signed __attribute__((__mode__(SI)))    int32_t;
> +typedef unsigned __attribute__((__mode__(SI)))   uint32_t;
> +typedef   signed __attribute__((__mode__(DI)))    int64_t;
> +typedef unsigned __attribute__((__mode__(DI)))   uint64_t;
> +
> +#endif
> +
> +#endif /* __XEN_STDINT_H__ */
> diff --git a/xen/include/xen/types.h b/xen/include/xen/types.h
> index 8b22a02eeaa4..c873c81ccf06 100644
> --- a/xen/include/xen/types.h
> +++ b/xen/include/xen/types.h
> @@ -2,6 +2,7 @@
>  #define __TYPES_H__
>  
>  #include <xen/stdbool.h>
> +#include <xen/stdint.h>
>  
>  #include <asm/types.h>
>  
> @@ -39,17 +40,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;
Roger Pau Monné June 28, 2023, 11:08 a.m. UTC | #2
On Tue, Jun 27, 2023 at 08:56:18AM +0100, Andrew Cooper wrote:
> 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

Duplicated "all".

> diff --git a/xen/include/xen/stdint.h b/xen/include/xen/stdint.h
> new file mode 100644
> index 000000000000..4cf82790f196
> --- /dev/null
> +++ b/xen/include/xen/stdint.h
> @@ -0,0 +1,33 @@
> +/* SPDX-License-Identifier: GPL-2.0-only */
> +#ifndef __XEN_STDINT_H__
> +#define __XEN_STDINT_H__
> +
> +#ifndef __INT8_TYPE__ /* GCC <= 4.4 */

I'm possibly confused, but don't you want to use __INT8_TYPE__ if it's
defined, and hence this should be an ifdef instead of an ifndef?

> +
> +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;

Thanks, Roger.
Andrew Cooper June 28, 2023, 11:28 a.m. UTC | #3
On 28/06/2023 12:08 pm, Roger Pau Monné wrote:
> On Tue, Jun 27, 2023 at 08:56:18AM +0100, Andrew Cooper wrote:
>> 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
> Duplicated "all".

Yeah, already noticed and adjusted.

>
>> diff --git a/xen/include/xen/stdint.h b/xen/include/xen/stdint.h
>> new file mode 100644
>> index 000000000000..4cf82790f196
>> --- /dev/null
>> +++ b/xen/include/xen/stdint.h
>> @@ -0,0 +1,33 @@
>> +/* SPDX-License-Identifier: GPL-2.0-only */
>> +#ifndef __XEN_STDINT_H__
>> +#define __XEN_STDINT_H__
>> +
>> +#ifndef __INT8_TYPE__ /* GCC <= 4.4 */
> I'm possibly confused, but don't you want to use __INT8_TYPE__ if it's
> defined, and hence this should be an ifdef instead of an ifndef?

You're right.  I was too tired while putting this together.

Originally, this was going to be

#ifndef __INT8_TYPE__
#define __INT8_TYPE__ ...
#endif

typedef ...;

but decided to get rid of the intermediate and use a plain if/else. 
I'll fix.

~Andrew
diff mbox series

Patch

diff --git a/xen/arch/arm/include/asm/types.h b/xen/arch/arm/include/asm/types.h
index fb6618ef247f..545a5e9d1175 100644
--- a/xen/arch/arm/include/asm/types.h
+++ b/xen/arch/arm/include/asm/types.h
@@ -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;
 
diff --git a/xen/arch/riscv/include/asm/types.h b/xen/arch/riscv/include/asm/types.h
index 0c0ce78c8f6e..93a680a8f323 100644
--- a/xen/arch/riscv/include/asm/types.h
+++ b/xen/arch/riscv/include/asm/types.h
@@ -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;
 
diff --git a/xen/arch/x86/include/asm/types.h b/xen/arch/x86/include/asm/types.h
index 2d56aed66782..c9d257716551 100644
--- a/xen/arch/x86/include/asm/types.h
+++ b/xen/arch/x86/include/asm/types.h
@@ -1,20 +1,6 @@ 
 #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;
-#endif
-
 typedef signed char s8;
 typedef unsigned char u8;
 
diff --git a/xen/include/xen/stdint.h b/xen/include/xen/stdint.h
new file mode 100644
index 000000000000..4cf82790f196
--- /dev/null
+++ b/xen/include/xen/stdint.h
@@ -0,0 +1,33 @@ 
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef __XEN_STDINT_H__
+#define __XEN_STDINT_H__
+
+#ifndef __INT8_TYPE__ /* GCC <= 4.4 */
+
+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;
+
+#else
+
+/*
+ * Define the types using GCC internal notation.  Clang understands this too.
+ * https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html
+ */
+typedef   signed __attribute__((__mode__(QI)))     int8_t;
+typedef unsigned __attribute__((__mode__(QI)))    uint8_t;
+typedef   signed __attribute__((__mode__(HI)))    int16_t;
+typedef unsigned __attribute__((__mode__(HI)))   uint16_t;
+typedef   signed __attribute__((__mode__(SI)))    int32_t;
+typedef unsigned __attribute__((__mode__(SI)))   uint32_t;
+typedef   signed __attribute__((__mode__(DI)))    int64_t;
+typedef unsigned __attribute__((__mode__(DI)))   uint64_t;
+
+#endif
+
+#endif /* __XEN_STDINT_H__ */
diff --git a/xen/include/xen/types.h b/xen/include/xen/types.h
index 8b22a02eeaa4..c873c81ccf06 100644
--- a/xen/include/xen/types.h
+++ b/xen/include/xen/types.h
@@ -2,6 +2,7 @@ 
 #define __TYPES_H__
 
 #include <xen/stdbool.h>
+#include <xen/stdint.h>
 
 #include <asm/types.h>
 
@@ -39,17 +40,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;