public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* (no subject)
@ 2021-04-14  7:41 unlvsur unlvsur
  2021-04-14  7:42 ` FW: [PATCH] Fix intrinsics mm_malloc.h in freestanding [PR100057] unlvsur unlvsur
  0 siblings, 1 reply; 2+ messages in thread
From: unlvsur unlvsur @ 2021-04-14  7:41 UTC (permalink / raw)
  To: gcc-patches List

From b1774ab1c8aad82b7a5d975ef90c6d3f633780ee Mon Sep 17 00:00:00 2001
From: expnkx <unlvsur@live.com>
Date: Wed, 14 Apr 2021 03:14:28 -0400
Subject: [PATCH] Fix intrinsics mm_malloc.h in freestanding [PR100057]

C does not have stdlib.h and C++ cstdint in freestanding does not malloc either. This leads
to fail of compilation even with -ffrestanding flag

Only gmm_malloc checks errno, everything else does not. So we remove the errno
in gmm_malloc too. There is no reason freestanding should behave differently with hosted.

gcc/ChangeLog
   PR/100057:
      gcc/config/i386/gmm_malloc.h: use __builtin_malloc and __builtin_free instead
      gcc/config/i386/pmm_malloc.h: use __builtin_malloc and __builtin_free instead
      gcc/config/rs6000/mm_malloc.h: use __builtin_malloc and __builtin_free instead

---
gcc/config/i386/gmm_malloc.h  | 13 ++++---------
gcc/config/i386/pmm_malloc.h  | 13 +++++++++----
gcc/config/rs6000/mm_malloc.h | 13 +++++++++----
3 files changed, 22 insertions(+), 17 deletions(-)

diff --git a/gcc/config/i386/gmm_malloc.h b/gcc/config/i386/gmm_malloc.h
index 70b38ab557b..276a5f50023 100644
--- a/gcc/config/i386/gmm_malloc.h
+++ b/gcc/config/i386/gmm_malloc.h
@@ -24,10 +24,7 @@
#ifndef _MM_MALLOC_H_INCLUDED
#define _MM_MALLOC_H_INCLUDED
-#include <stdlib.h>
-#if __STDC_HOSTED__
-#include <errno.h>
-#endif
+#include <stddef.h>
 static __inline__ void *
 _mm_malloc (size_t __size, size_t __align)
@@ -38,9 +35,6 @@ _mm_malloc (size_t __size, size_t __align)
   /* Error if align is not a power of two.  */
   if (__align & (__align - 1))
     {
-#if __STDC_HOSTED__
-      errno = EINVAL;
-#endif
       return ((void *) 0);
     }
@@ -54,7 +48,7 @@ _mm_malloc (size_t __size, size_t __align)
     if (__align < 2 * sizeof (void *))
       __align = 2 * sizeof (void *);
-  __malloc_ptr = malloc (__size + __align);
+  __malloc_ptr = __builtin_malloc (__size + __align);
   if (!__malloc_ptr)
     return ((void *) 0);
@@ -72,7 +66,8 @@ static __inline__ void
_mm_free (void *__aligned_ptr)
{
   if (__aligned_ptr)
-    free (((void **) __aligned_ptr)[-1]);
+    __builtin_free (((void **) __aligned_ptr)[-1]);
}
+
#endif /* _MM_MALLOC_H_INCLUDED */
diff --git a/gcc/config/i386/pmm_malloc.h b/gcc/config/i386/pmm_malloc.h
index 1b0bfe37852..3b97107ccfc 100644
--- a/gcc/config/i386/pmm_malloc.h
+++ b/gcc/config/i386/pmm_malloc.h
@@ -24,14 +24,19 @@
#ifndef _MM_MALLOC_H_INCLUDED
#define _MM_MALLOC_H_INCLUDED
-#include <stdlib.h>
+#include <stddef.h>
 /* We can't depend on <stdlib.h> since the prototype of posix_memalign
    may not be visible.  */
#ifndef __cplusplus
extern int posix_memalign (void **, size_t, size_t);
#else
-extern "C" int posix_memalign (void **, size_t, size_t) throw ();
+extern "C" int posix_memalign (void **, size_t, size_t)
+#if __cplusplus >= 201103L
+noexcept;
+#else
+throw ();
+#endif
#endif
 static __inline void *
@@ -39,7 +44,7 @@ _mm_malloc (size_t __size, size_t __alignment)
{
   void *__ptr;
   if (__alignment == 1)
-    return malloc (__size);
+    return __builtin_malloc (__size);
   if (__alignment == 2 || (sizeof (void *) == 8 && __alignment == 4))
     __alignment = sizeof (void *);
   if (posix_memalign (&__ptr, __alignment, __size) == 0)
@@ -51,7 +56,7 @@ _mm_malloc (size_t __size, size_t __alignment)
static __inline void
_mm_free (void *__ptr)
{
-  free (__ptr);
+  __builtin_free (__ptr);
}
 #endif /* _MM_MALLOC_H_INCLUDED */
diff --git a/gcc/config/rs6000/mm_malloc.h b/gcc/config/rs6000/mm_malloc.h
index c04348068e0..82aaab411da 100644
--- a/gcc/config/rs6000/mm_malloc.h
+++ b/gcc/config/rs6000/mm_malloc.h
@@ -24,14 +24,19 @@
#ifndef _MM_MALLOC_H_INCLUDED
#define _MM_MALLOC_H_INCLUDED
-#include <stdlib.h>
+#include <stddef.h>
 /* We can't depend on <stdlib.h> since the prototype of posix_memalign
    may not be visible.  */
#ifndef __cplusplus
extern int posix_memalign (void **, size_t, size_t);
#else
-extern "C" int posix_memalign (void **, size_t, size_t) throw ();
+extern "C" int posix_memalign (void **, size_t, size_t)
+#if __cplusplus >= 201103L
+noexcept;
+#else
+throw ();
+#endif
#endif
 static __inline void *
@@ -44,7 +49,7 @@ _mm_malloc (size_t size, size_t alignment)
   void *ptr;
   if (alignment == malloc_align && alignment == vec_align)
-    return malloc (size);
+    return __builtin_malloc (size);
   if (alignment < vec_align)
     alignment = vec_align;
   if (posix_memalign (&ptr, alignment, size) == 0)
@@ -56,7 +61,7 @@ _mm_malloc (size_t size, size_t alignment)
static __inline void
_mm_free (void * ptr)
{
-  free (ptr);
+  __builtin_free (ptr);
}
 #endif /* _MM_MALLOC_H_INCLUDED */
--
2.25.1


Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10


^ permalink raw reply	[flat|nested] 2+ messages in thread

* FW: [PATCH] Fix intrinsics mm_malloc.h in freestanding [PR100057]
  2021-04-14  7:41 unlvsur unlvsur
@ 2021-04-14  7:42 ` unlvsur unlvsur
  0 siblings, 0 replies; 2+ messages in thread
From: unlvsur unlvsur @ 2021-04-14  7:42 UTC (permalink / raw)
  To: gcc-patches List

From b1774ab1c8aad82b7a5d975ef90c6d3f633780ee Mon Sep 17 00:00:00 2001
From: expnkx <unlvsur@live.com>
Date: Wed, 14 Apr 2021 03:14:28 -0400
Subject: [PATCH] Fix intrinsics mm_malloc.h in freestanding [PR100057]

C does not have stdlib.h and C++ cstdint in freestanding does not malloc either. This leads
to fail of compilation even with -ffrestanding flag

Only gmm_malloc checks errno, everything else does not. So we remove the errno
in gmm_malloc too. There is no reason freestanding should behave differently with hosted.

gcc/ChangeLog
   PR/100057:
      gcc/config/i386/gmm_malloc.h: use __builtin_malloc and __builtin_malloc instead
      gcc/config/i386/pmm_malloc.h: use __builtin_malloc and __builtin_malloc instead
      gcc/config/rs6000/mm_malloc.h: use __builtin_malloc and __builtin_malloc instead

---
gcc/config/i386/gmm_malloc.h  | 13 ++++---------
gcc/config/i386/pmm_malloc.h  | 13 +++++++++----
gcc/config/rs6000/mm_malloc.h | 13 +++++++++----
3 files changed, 22 insertions(+), 17 deletions(-)
mode change 100644 => 100755 gcc/config/i386/gmm_malloc.h

diff --git a/gcc/config/i386/gmm_malloc.h b/gcc/config/i386/gmm_malloc.h
old mode 100644
new mode 100755
index 70b38ab557b..276a5f50023
--- a/gcc/config/i386/gmm_malloc.h
+++ b/gcc/config/i386/gmm_malloc.h
@@ -24,10 +24,7 @@
#ifndef _MM_MALLOC_H_INCLUDED
#define _MM_MALLOC_H_INCLUDED
-#include <stdlib.h>
-#if __STDC_HOSTED__
-#include <errno.h>
-#endif
+#include <stddef.h>
 static __inline__ void *
 _mm_malloc (size_t __size, size_t __align)
@@ -38,9 +35,6 @@ _mm_malloc (size_t __size, size_t __align)
   /* Error if align is not a power of two.  */
   if (__align & (__align - 1))
     {
-#if __STDC_HOSTED__
-      errno = EINVAL;
-#endif
       return ((void *) 0);
     }
@@ -54,7 +48,7 @@ _mm_malloc (size_t __size, size_t __align)
     if (__align < 2 * sizeof (void *))
       __align = 2 * sizeof (void *);
-  __malloc_ptr = malloc (__size + __align);
+  __malloc_ptr = __builtin_malloc (__size + __align);
   if (!__malloc_ptr)
     return ((void *) 0);
@@ -72,7 +66,8 @@ static __inline__ void
_mm_free (void *__aligned_ptr)
{
   if (__aligned_ptr)
-    free (((void **) __aligned_ptr)[-1]);
+    __builtin_free (((void **) __aligned_ptr)[-1]);
}
+
#endif /* _MM_MALLOC_H_INCLUDED */
diff --git a/gcc/config/i386/pmm_malloc.h b/gcc/config/i386/pmm_malloc.h
index 1b0bfe37852..3b97107ccfc 100644
--- a/gcc/config/i386/pmm_malloc.h
+++ b/gcc/config/i386/pmm_malloc.h
@@ -24,14 +24,19 @@
#ifndef _MM_MALLOC_H_INCLUDED
#define _MM_MALLOC_H_INCLUDED
-#include <stdlib.h>
+#include <stddef.h>
 /* We can't depend on <stdlib.h> since the prototype of posix_memalign
    may not be visible.  */
#ifndef __cplusplus
extern int posix_memalign (void **, size_t, size_t);
#else
-extern "C" int posix_memalign (void **, size_t, size_t) throw ();
+extern "C" int posix_memalign (void **, size_t, size_t)
+#if __cplusplus >= 201103L
+noexcept;
+#else
+throw ();
+#endif
#endif
 static __inline void *
@@ -39,7 +44,7 @@ _mm_malloc (size_t __size, size_t __alignment)
{
   void *__ptr;
   if (__alignment == 1)
-    return malloc (__size);
+    return __builtin_malloc (__size);
   if (__alignment == 2 || (sizeof (void *) == 8 && __alignment == 4))
     __alignment = sizeof (void *);
   if (posix_memalign (&__ptr, __alignment, __size) == 0)
@@ -51,7 +56,7 @@ _mm_malloc (size_t __size, size_t __alignment)
static __inline void
_mm_free (void *__ptr)
{
-  free (__ptr);
+  __builtin_free (__ptr);
}
 #endif /* _MM_MALLOC_H_INCLUDED */
diff --git a/gcc/config/rs6000/mm_malloc.h b/gcc/config/rs6000/mm_malloc.h
index c04348068e0..82aaab411da 100644
--- a/gcc/config/rs6000/mm_malloc.h
+++ b/gcc/config/rs6000/mm_malloc.h
@@ -24,14 +24,19 @@
#ifndef _MM_MALLOC_H_INCLUDED
#define _MM_MALLOC_H_INCLUDED
-#include <stdlib.h>
+#include <stddef.h>
 /* We can't depend on <stdlib.h> since the prototype of posix_memalign
    may not be visible.  */
#ifndef __cplusplus
extern int posix_memalign (void **, size_t, size_t);
#else
-extern "C" int posix_memalign (void **, size_t, size_t) throw ();
+extern "C" int posix_memalign (void **, size_t, size_t)
+#if __cplusplus >= 201103L
+noexcept;
+#else
+throw ();
+#endif
#endif
 static __inline void *
@@ -44,7 +49,7 @@ _mm_malloc (size_t size, size_t alignment)
   void *ptr;
   if (alignment == malloc_align && alignment == vec_align)
-    return malloc (size);
+    return __builtin_malloc (size);
   if (alignment < vec_align)
     alignment = vec_align;
   if (posix_memalign (&ptr, alignment, size) == 0)
@@ -56,7 +61,7 @@ _mm_malloc (size_t size, size_t alignment)
static __inline void
_mm_free (void * ptr)
{
-  free (ptr);
+  __builtin_free (ptr);
}
 #endif /* _MM_MALLOC_H_INCLUDED */
--
2.25.1

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-04-14  7:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-14  7:41 unlvsur unlvsur
2021-04-14  7:42 ` FW: [PATCH] Fix intrinsics mm_malloc.h in freestanding [PR100057] unlvsur unlvsur

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).