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

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