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

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