1 From 84391b08e9245df80dd976f6179f42710ae2fc9a Mon Sep 17 00:00:00 2001
2 From: rofl0r <rofl0r@users.noreply.github.com>
3 Date: Thu, 17 Mar 2022 01:45:34 +0000
4 Subject: [PATCH] newlib 4.1.0 compat fixes for gcc < 5
7 newlib/libc/include/sys/_intsup.h | 27 +++++++++++++++++++++++++++
8 newlib/libc/stdlib/mallocr.c | 9 +++++++++
9 newlib/libc/stdlib/nano-mallocr.c | 10 ++++++++++
10 newlib/libc/stdlib/reallocarray.c | 10 ++++++++++
11 4 files changed, 56 insertions(+)
13 diff --git a/newlib/libc/include/sys/_intsup.h b/newlib/libc/include/sys/_intsup.h
14 index 993121b..af3a683 100644
15 --- a/newlib/libc/include/sys/_intsup.h
16 +++ b/newlib/libc/include/sys/_intsup.h
18 #error "Unable to determine type definition of int32_t"
21 +#ifndef __INT64_TYPE__
22 +#define __INT64_TYPE__ long long
23 +#define __UINT64_TYPE__ unsigned long long
25 +#ifndef __INT_FAST32_TYPE__
27 +#define __INT_FAST64_TYPE__ long long
28 +#define __INT_FAST32_TYPE__ int
29 +#define __INT_FAST16_TYPE__ int
30 +#define __INT_FAST8_TYPE__ signed char
32 +#define __UINT_FAST64_TYPE__ unsigned long long
33 +#define __UINT_FAST32_TYPE__ unsigned int
34 +#define __UINT_FAST16_TYPE__ unsigned int
35 +#define __UINT_FAST8_TYPE__ unsigned char
37 +#define __INT_LEAST8_TYPE__ signed char
38 +#define __INT_LEAST16_TYPE__ signed short
39 +#define __INT_LEAST32_TYPE__ int
40 +#define __INT_LEAST64_TYPE__ long long
42 +#define __UINT_LEAST8_TYPE__ unsigned char
43 +#define __UINT_LEAST16_TYPE__ unsigned short
44 +#define __UINT_LEAST32_TYPE__ unsigned int
45 +#define __UINT_LEAST64_TYPE__ unsigned long long
48 #if (__INT8_TYPE__ == 0)
50 #elif (__INT8_TYPE__ == 1 || __INT8_TYPE__ == 3)
51 diff --git a/newlib/libc/stdlib/mallocr.c b/newlib/libc/stdlib/mallocr.c
52 index 13d014c..0f58f45 100644
53 --- a/newlib/libc/stdlib/mallocr.c
54 +++ b/newlib/libc/stdlib/mallocr.c
55 @@ -3182,6 +3182,15 @@ Void_t* pvALLOc(RARG bytes) RDECL size_t bytes;
57 #endif /* DEFINE_PVALLOC */
60 +static inline int __builtin_mul_overflow(INTERNAL_SIZE_T a, INTERNAL_SIZE_T b,
61 + INTERNAL_SIZE_T *res) {
63 + if(*res < a || *res < b) return 1;
71 diff --git a/newlib/libc/stdlib/nano-mallocr.c b/newlib/libc/stdlib/nano-mallocr.c
72 index 1e07039..0ccfd3b 100644
73 --- a/newlib/libc/stdlib/nano-mallocr.c
74 +++ b/newlib/libc/stdlib/nano-mallocr.c
75 @@ -443,6 +443,16 @@ void nano_cfree(RARG void * ptr)
76 #endif /* DEFINE_CFREE */
81 +static inline int __builtin_mul_overflow(INTERNAL_SIZE_T a, INTERNAL_SIZE_T b,
82 + INTERNAL_SIZE_T *res) {
84 + if(*res < a || *res < b) return 1;
89 /* Function nano_calloc
90 * Implement calloc simply by calling malloc and set zero */
91 void * nano_calloc(RARG malloc_size_t n, malloc_size_t elem)
92 diff --git a/newlib/libc/stdlib/reallocarray.c b/newlib/libc/stdlib/reallocarray.c
93 index d1f63c6..62b4060 100644
94 --- a/newlib/libc/stdlib/reallocarray.c
95 +++ b/newlib/libc/stdlib/reallocarray.c
100 +#if __GNUC__ + 0 < 5
101 +static inline int __builtin_mul_overflow(size_t a, size_t b,
104 + if(*res < a || *res < b) return 1;
111 reallocarray(void *optr, size_t nmemb, size_t size)