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

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