public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH] MdePkg/BaseSafeIntLib: Fix VS IA32 NOOPT target build failure
@ 2018-02-13  2:08 Hao Wu
  2018-02-27 19:32 ` Bret Barkelew
  0 siblings, 1 reply; 2+ messages in thread
From: Hao Wu @ 2018-02-13  2:08 UTC (permalink / raw)
  To: edk2-devel; +Cc: Hao Wu, Michael D Kinney, Sean Brogan, Jiewen Yao, Liming Gao

The commit resolve the VS IA32 NOOPT target build failure for modules
that use the BaseSafeIntLib.

More specifically, corresponding BaseLib APIs should be used when
performing shift & mulitiplication operations with signed/unsigned
64-bit operands.

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Sean Brogan <sean.brogan@microsoft.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
---
 MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf |  3 +++
 MdePkg/Library/BaseSafeIntLib/SafeIntLib.c       | 13 +++++++++----
 MdePkg/Library/BaseSafeIntLib/SafeIntLib32.c     |  3 ++-
 MdePkg/Library/BaseSafeIntLib/SafeIntLibEbc.c    |  3 ++-
 4 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf b/MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf
index 20a83ed97b..8fbdafe748 100644
--- a/MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf
+++ b/MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf
@@ -56,3 +56,6 @@
 
 [Packages]
   MdePkg/MdePkg.dec
+
+[LibraryClasses]
+  BaseLib
diff --git a/MdePkg/Library/BaseSafeIntLib/SafeIntLib.c b/MdePkg/Library/BaseSafeIntLib/SafeIntLib.c
index d846160ba0..64b8bc4ad8 100644
--- a/MdePkg/Library/BaseSafeIntLib/SafeIntLib.c
+++ b/MdePkg/Library/BaseSafeIntLib/SafeIntLib.c
@@ -28,6 +28,7 @@
 
 #include <Base.h>
 #include <Library/SafeIntLib.h>
+#include <Library/BaseLib.h>
 
 
 //
@@ -3373,8 +3374,8 @@ SafeUint64Mult (
   // b * c must be less than 2^32 or there would be bits in the high 64-bits
   // then there must be no overflow of the resulting values summed up.
   //
-  DwordA = (UINT32)(Multiplicand >> 32);
-  DwordC = (UINT32)(Multiplier >> 32);
+  DwordA = (UINT32)RShiftU64 (Multiplicand, 32);
+  DwordC = (UINT32)RShiftU64 (Multiplier, 32);
 
   //
   // common case -- if high dwords are both zero, no chance for overflow
@@ -3409,7 +3410,11 @@ SafeUint64Mult (
           // now sum them all up checking for overflow.
           // shifting is safe because we already checked for overflow above
           //
-          if (!RETURN_ERROR (SafeUint64Add (ProductBC << 32, ProductAD << 32, &UnsignedResult))) {
+          if (!RETURN_ERROR (SafeUint64Add (
+                               LShiftU64 (ProductBC, 32),
+                               LShiftU64 (ProductAD, 32),
+                               &UnsignedResult
+                               ))) {
             //
             // b * d
             //
@@ -4011,7 +4016,7 @@ SafeInt32Mult (
   OUT INT32  *Result
   )
 {
-  return SafeInt64ToInt32 (((INT64)Multiplicand) *((INT64)Multiplier), Result);
+  return SafeInt64ToInt32 (MultS64x64 ((INT64)Multiplicand, (INT64)Multiplier), Result);
 }
 
 /**
diff --git a/MdePkg/Library/BaseSafeIntLib/SafeIntLib32.c b/MdePkg/Library/BaseSafeIntLib/SafeIntLib32.c
index 18bfb9e413..b3b7b802a1 100644
--- a/MdePkg/Library/BaseSafeIntLib/SafeIntLib32.c
+++ b/MdePkg/Library/BaseSafeIntLib/SafeIntLib32.c
@@ -28,6 +28,7 @@
 
 #include <Base.h>
 #include <Library/SafeIntLib.h>
+#include <Library/BaseLib.h>
 
 /**
   INT32 -> UINTN conversion
@@ -549,6 +550,6 @@ SafeIntnMult (
   OUT INTN  *Result
   )
 {
-  return SafeInt64ToIntn (((INT64)Multiplicand) *((INT64)Multiplier), Result);
+  return SafeInt64ToIntn (MultS64x64 ((INT64)Multiplicand, (INT64)Multiplier), Result);
 }
 
diff --git a/MdePkg/Library/BaseSafeIntLib/SafeIntLibEbc.c b/MdePkg/Library/BaseSafeIntLib/SafeIntLibEbc.c
index 4478957b7e..e810ba59ef 100644
--- a/MdePkg/Library/BaseSafeIntLib/SafeIntLibEbc.c
+++ b/MdePkg/Library/BaseSafeIntLib/SafeIntLibEbc.c
@@ -28,6 +28,7 @@
 
 #include <Base.h>
 #include <Library/SafeIntLib.h>
+#include <Library/BaseLib.h>
 
 /**
   INT32 -> UINTN conversion
@@ -607,7 +608,7 @@ SafeIntnMult (
   )
 {
   if (sizeof (UINTN) == sizeof (UINT32)) {
-    return SafeInt64ToIntn (((INT64)Multiplicand) *((INT64)Multiplier), Result);
+    return SafeInt64ToIntn (MultS64x64 ((INT64)Multiplicand, (INT64)Multiplier), Result);
   }
   return SafeInt64Mult ((INT64)Multiplicand, (INT64)Multiplier, (INT64 *)Result);
 }
-- 
2.12.0.windows.1



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

* Re: [PATCH] MdePkg/BaseSafeIntLib: Fix VS IA32 NOOPT target build failure
  2018-02-13  2:08 [PATCH] MdePkg/BaseSafeIntLib: Fix VS IA32 NOOPT target build failure Hao Wu
@ 2018-02-27 19:32 ` Bret Barkelew
  0 siblings, 0 replies; 2+ messages in thread
From: Bret Barkelew @ 2018-02-27 19:32 UTC (permalink / raw)
  To: Hao Wu, edk2-devel@lists.01.org
  Cc: Hao Wu, Michael D Kinney, Jiewen Yao, Liming Gao

Reviewed-By: Bret Barkelew Bret.Barkelew@microsoft.com

- Bret

From: Hao Wu<mailto:hao.a.wu@intel.com>
Sent: Monday, February 12, 2018 6:09 PM
To: edk2-devel@lists.01.org<mailto:edk2-devel@lists.01.org>
Cc: Hao Wu<mailto:hao.a.wu@intel.com>; Michael D Kinney<mailto:michael.d.kinney@intel.com>; Jiewen Yao<mailto:jiewen.yao@intel.com>; Liming Gao<mailto:liming.gao@intel.com>
Subject: [edk2] [PATCH] MdePkg/BaseSafeIntLib: Fix VS IA32 NOOPT target build failure

The commit resolve the VS IA32 NOOPT target build failure for modules
that use the BaseSafeIntLib.

More specifically, corresponding BaseLib APIs should be used when
performing shift & mulitiplication operations with signed/unsigned
64-bit operands.

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Sean Brogan <sean.brogan@microsoft.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
---
 MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf |  3 +++
 MdePkg/Library/BaseSafeIntLib/SafeIntLib.c       | 13 +++++++++----
 MdePkg/Library/BaseSafeIntLib/SafeIntLib32.c     |  3 ++-
 MdePkg/Library/BaseSafeIntLib/SafeIntLibEbc.c    |  3 ++-
 4 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf b/MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf
index 20a83ed97b..8fbdafe748 100644
--- a/MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf
+++ b/MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf
@@ -56,3 +56,6 @@

 [Packages]
   MdePkg/MdePkg.dec
+
+[LibraryClasses]
+  BaseLib
diff --git a/MdePkg/Library/BaseSafeIntLib/SafeIntLib.c b/MdePkg/Library/BaseSafeIntLib/SafeIntLib.c
index d846160ba0..64b8bc4ad8 100644
--- a/MdePkg/Library/BaseSafeIntLib/SafeIntLib.c
+++ b/MdePkg/Library/BaseSafeIntLib/SafeIntLib.c
@@ -28,6 +28,7 @@

 #include <Base.h>
 #include <Library/SafeIntLib.h>
+#include <Library/BaseLib.h>


 //
@@ -3373,8 +3374,8 @@ SafeUint64Mult (
   // b * c must be less than 2^32 or there would be bits in the high 64-bits
   // then there must be no overflow of the resulting values summed up.
   //
-  DwordA = (UINT32)(Multiplicand >> 32);
-  DwordC = (UINT32)(Multiplier >> 32);
+  DwordA = (UINT32)RShiftU64 (Multiplicand, 32);
+  DwordC = (UINT32)RShiftU64 (Multiplier, 32);

   //
   // common case -- if high dwords are both zero, no chance for overflow
@@ -3409,7 +3410,11 @@ SafeUint64Mult (
           // now sum them all up checking for overflow.
           // shifting is safe because we already checked for overflow above
           //
-          if (!RETURN_ERROR (SafeUint64Add (ProductBC << 32, ProductAD << 32, &UnsignedResult))) {
+          if (!RETURN_ERROR (SafeUint64Add (
+                               LShiftU64 (ProductBC, 32),
+                               LShiftU64 (ProductAD, 32),
+                               &UnsignedResult
+                               ))) {
             //
             // b * d
             //
@@ -4011,7 +4016,7 @@ SafeInt32Mult (
   OUT INT32  *Result
   )
 {
-  return SafeInt64ToInt32 (((INT64)Multiplicand) *((INT64)Multiplier), Result);
+  return SafeInt64ToInt32 (MultS64x64 ((INT64)Multiplicand, (INT64)Multiplier), Result);
 }

 /**
diff --git a/MdePkg/Library/BaseSafeIntLib/SafeIntLib32.c b/MdePkg/Library/BaseSafeIntLib/SafeIntLib32.c
index 18bfb9e413..b3b7b802a1 100644
--- a/MdePkg/Library/BaseSafeIntLib/SafeIntLib32.c
+++ b/MdePkg/Library/BaseSafeIntLib/SafeIntLib32.c
@@ -28,6 +28,7 @@

 #include <Base.h>
 #include <Library/SafeIntLib.h>
+#include <Library/BaseLib.h>

 /**
   INT32 -> UINTN conversion
@@ -549,6 +550,6 @@ SafeIntnMult (
   OUT INTN  *Result
   )
 {
-  return SafeInt64ToIntn (((INT64)Multiplicand) *((INT64)Multiplier), Result);
+  return SafeInt64ToIntn (MultS64x64 ((INT64)Multiplicand, (INT64)Multiplier), Result);
 }

diff --git a/MdePkg/Library/BaseSafeIntLib/SafeIntLibEbc.c b/MdePkg/Library/BaseSafeIntLib/SafeIntLibEbc.c
index 4478957b7e..e810ba59ef 100644
--- a/MdePkg/Library/BaseSafeIntLib/SafeIntLibEbc.c
+++ b/MdePkg/Library/BaseSafeIntLib/SafeIntLibEbc.c
@@ -28,6 +28,7 @@

 #include <Base.h>
 #include <Library/SafeIntLib.h>
+#include <Library/BaseLib.h>

 /**
   INT32 -> UINTN conversion
@@ -607,7 +608,7 @@ SafeIntnMult (
   )
 {
   if (sizeof (UINTN) == sizeof (UINT32)) {
-    return SafeInt64ToIntn (((INT64)Multiplicand) *((INT64)Multiplier), Result);
+    return SafeInt64ToIntn (MultS64x64 ((INT64)Multiplicand, (INT64)Multiplier), Result);
   }
   return SafeInt64Mult ((INT64)Multiplicand, (INT64)Multiplier, (INT64 *)Result);
 }
--
2.12.0.windows.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.01.org%2Fmailman%2Flistinfo%2Fedk2-devel&data=04%7C01%7CBret.Barkelew%40microsoft.com%7Cd8ac84da07d848841ffe08d57286c19b%7Cee3303d7fb734b0c8589bcd847f1c277%7C1%7C0%7C636540845483912177%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwifQ%3D%3D%7C-1&sdata=b5dnMPDn1LjKQ19GWQdr8c4aAbrCWcp%2BjLPmbYApkG8%3D&reserved=0



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

end of thread, other threads:[~2018-02-27 19:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-02-13  2:08 [PATCH] MdePkg/BaseSafeIntLib: Fix VS IA32 NOOPT target build failure Hao Wu
2018-02-27 19:32 ` Bret Barkelew

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox