Blame SOURCES/0006-Move-memcpy-memset-definition-to-global-init.c.patch

67650e
From b1d426ce67cbeaa1a8ec7d9b8d0d8071ae4563b4 Mon Sep 17 00:00:00 2001
67650e
From: Nigel Croxon <ncroxon@redhat.com>
67650e
Date: Mon, 6 Nov 2017 09:38:38 -0500
67650e
Subject: [PATCH 06/25] Move memcpy/memset definition to global init.c
67650e
67650e
Following up on previous patch, I think we should move
67650e
memcpy/memset definitions to the global init.c, since MSVC does
67650e
also inserts calls to memset/memcpy for the x86_32 platform,
67650e
even when disabling standard libraries and intrinsics.
67650e
67650e
All in all, it looks like, for all platforms, we should assume
67650e
that a compiler may still insert these calls regardless.
67650e
67650e
Signed-off-by: Pete Batard <pete@akeo.ie>
67650e
Signed-off-by: Nigel Croxon <ncroxon@redhat.com>
67650e
---
67650e
 lib/aarch64/initplat.c  | 29 -----------------------------
67650e
 lib/arm/initplat.c      | 33 ++-------------------------------
67650e
 lib/init.c              | 47 ++++++++++++++++++++++++++++++++++++++---------
67650e
 lib/mips64el/initplat.c | 25 -------------------------
67650e
 4 files changed, 40 insertions(+), 94 deletions(-)
67650e
67650e
diff --git a/lib/aarch64/initplat.c b/lib/aarch64/initplat.c
67650e
index 25207f42c8f..6c5e1fa5217 100644
67650e
--- a/lib/aarch64/initplat.c
67650e
+++ b/lib/aarch64/initplat.c
67650e
@@ -24,32 +24,3 @@ InitializeLibPlatform (
67650e
     )
67650e
 {
67650e
 }
67650e
-
67650e
-#ifndef __SIZE_TYPE__
67650e
-#define __SIZE_TYPE__ UINTN
67650e
-#endif
67650e
-
67650e
-/*
67650e
- * Calls to these functions may be emitted implicitly by GCC even when
67650e
- * -ffreestanding is in effect.
67650e
- */
67650e
-void *memset(void *s, int c, __SIZE_TYPE__ n)
67650e
-{
67650e
-    unsigned char *p = s;
67650e
-
67650e
-    while (n--)
67650e
-        *p++ = c;
67650e
-
67650e
-    return s;
67650e
-}
67650e
-
67650e
-void *memcpy(void *dest, const void *src, __SIZE_TYPE__ n)
67650e
-{
67650e
-    const unsigned char *q = src;
67650e
-    unsigned char *p = dest;
67650e
-
67650e
-    while (n--)
67650e
-        *p++ = *q++;
67650e
-
67650e
-    return dest;
67650e
-}
67650e
diff --git a/lib/arm/initplat.c b/lib/arm/initplat.c
67650e
index c77d26d9045..135a649210a 100644
67650e
--- a/lib/arm/initplat.c
67650e
+++ b/lib/arm/initplat.c
67650e
@@ -25,39 +25,10 @@ InitializeLibPlatform (
67650e
 {
67650e
 }
67650e
 
67650e
-#ifndef __SIZE_TYPE__
67650e
-#define __SIZE_TYPE__ UINTN
67650e
-#endif
67650e
-
67650e
-/*
67650e
- * Calls to these functions may be emitted implicitly by GCC even when
67650e
- * -ffreestanding is in effect.
67650e
- */
67650e
-void *memset(void *s, int c, __SIZE_TYPE__ n)
67650e
-{
67650e
-    unsigned char *p = s;
67650e
-
67650e
-    while (n--)
67650e
-        *p++ = c;
67650e
-
67650e
-    return s;
67650e
-}
67650e
-
67650e
-void *memcpy(void *dest, const void *src, __SIZE_TYPE__ n)
67650e
-{
67650e
-    unsigned char *p = dest;
67650e
-    unsigned char const *q = src;
67650e
-
67650e
-    while (n--)
67650e
-        *p++ = *q++;
67650e
-
67650e
-    return dest;
67650e
-}
67650e
-
67650e
 #ifdef __GNUC__
67650e
 void __div0(void)
67650e
 {
67650e
-	// TODO handle divide by zero fault
67650e
-	while (1);
67650e
+    // TODO handle divide by zero fault
67650e
+    while (1);
67650e
 }
67650e
 #endif
67650e
diff --git a/lib/init.c b/lib/init.c
67650e
index 4225d314b7a..4f238c0a2cc 100644
67650e
--- a/lib/init.c
67650e
+++ b/lib/init.c
67650e
@@ -49,7 +49,7 @@ Returns:
67650e
     if (!LibInitialized) {
67650e
         LibInitialized = TRUE;
67650e
         LibFwInstance = FALSE;
67650e
-	LibImageHandle = ImageHandle;
67650e
+        LibImageHandle = ImageHandle;
67650e
 
67650e
 
67650e
         //
67650e
@@ -71,17 +71,16 @@ Returns:
67650e
 
67650e
         if (ImageHandle) {
67650e
             Status = uefi_call_wrapper(
67650e
-			    BS->HandleProtocol,
67650e
-				3,
67650e
-                            ImageHandle, 
67650e
-                            &LoadedImageProtocol,
67650e
-                            (VOID*)&LoadedImage
67650e
-                            );
67650e
+                BS->HandleProtocol,
67650e
+                3,
67650e
+                ImageHandle, 
67650e
+                &LoadedImageProtocol,
67650e
+                (VOID*)&LoadedImage
67650e
+            );
67650e
 
67650e
             if (!EFI_ERROR(Status)) {
67650e
                 PoolAllocationType = LoadedImage->ImageDataType;
67650e
             }
67650e
-            
67650e
             EFIDebugVariable ();
67650e
         }
67650e
 
67650e
@@ -181,5 +180,35 @@ EFIDebugVariable (
67650e
     Status = uefi_call_wrapper(RT->GetVariable, 5, L"EFIDebug", &EfiGlobalVariable, &Attributes, &DataSize, &NewEFIDebug);
67650e
     if (!EFI_ERROR(Status)) {
67650e
         EFIDebug = NewEFIDebug;
67650e
-    } 
67650e
+    }
67650e
+}
67650e
+
67650e
+/*
67650e
+ * Calls to memset/memcpy may be emitted implicitly by GCC or MSVC
67650e
+ * even when -ffreestanding or /NODEFAULTLIB are in effect.
67650e
+ */
67650e
+
67650e
+#ifndef __SIZE_TYPE__
67650e
+#define __SIZE_TYPE__ UINTN
67650e
+#endif
67650e
+
67650e
+void *memset(void *s, int c, __SIZE_TYPE__ n)
67650e
+{
67650e
+    unsigned char *p = s;
67650e
+
67650e
+    while (n--)
67650e
+        *p++ = c;
67650e
+
67650e
+    return s;
67650e
+}
67650e
+
67650e
+void *memcpy(void *dest, const void *src, __SIZE_TYPE__ n)
67650e
+{
67650e
+    const unsigned char *q = src;
67650e
+    unsigned char *p = dest;
67650e
+
67650e
+    while (n--)
67650e
+        *p++ = *q++;
67650e
+
67650e
+    return dest;
67650e
 }
67650e
diff --git a/lib/mips64el/initplat.c b/lib/mips64el/initplat.c
67650e
index 4b118656d7c..6c5e1fa5217 100644
67650e
--- a/lib/mips64el/initplat.c
67650e
+++ b/lib/mips64el/initplat.c
67650e
@@ -24,28 +24,3 @@ InitializeLibPlatform (
67650e
     )
67650e
 {
67650e
 }
67650e
-
67650e
-/*
67650e
- * Calls to these functions may be emitted implicitly by GCC even when
67650e
- * -ffreestanding is in effect.
67650e
- */
67650e
-void *memset(void *s, int c, __SIZE_TYPE__ n)
67650e
-{
67650e
-    unsigned char *p = s;
67650e
-
67650e
-    while (n--)
67650e
-        *p++ = c;
67650e
-
67650e
-    return s;
67650e
-}
67650e
-
67650e
-void *memcpy(void *dest, const void *src, __SIZE_TYPE__ n)
67650e
-{
67650e
-    const unsigned char *q = src;
67650e
-    unsigned char *p = dest;
67650e
-
67650e
-    while (n--)
67650e
-        *p++ = *q++;
67650e
-
67650e
-    return dest;
67650e
-}
67650e
-- 
67650e
2.15.0
67650e