From dc9b2a57403262cf6df9d150ea3a118a7d765ad8 Mon Sep 17 00:00:00 2001 From: Dandan Bi Date: Mon, 26 Feb 2018 11:55:15 +0800 Subject: [PATCH] MdePkg/BaseSafeIntLib: Fix VS2015 IA32 NOOPT build failure v2: Add [LibraryClasses] section in INF file and refine coding style. There are VS2015 NOOPT IA32 build failure like below in BaseSafeIntLib. XXX.lib(XXX.obj): error LNK2001: unresolved external symbol __allmul XXX.lib(XXX.obj): error LNK2001: unresolved external symbol __allshl XXX.lib(XXX.obj): error LNK2001: unresolved external symbol __aullshr This patch replaces direct shift/multiplication of 64-bit integer with related function call to fix these failure. Cc: Laszlo Ersek Cc: Liming Gao Cc: Michael Kinney Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Dandan Bi Reviewed-by: Liming Gao Reviewed-by: Laszlo Ersek --- MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf | 3 +++ MdePkg/Library/BaseSafeIntLib/SafeIntLib.c | 9 +++++---- MdePkg/Library/BaseSafeIntLib/SafeIntLib32.c | 3 ++- 3 files changed, 10 insertions(+), 5 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 c5f13d7e08..e96327d134 100644 --- a/MdePkg/Library/BaseSafeIntLib/SafeIntLib.c +++ b/MdePkg/Library/BaseSafeIntLib/SafeIntLib.c @@ -28,6 +28,7 @@ #include #include +#include // @@ -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,7 @@ 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 // @@ -4075,7 +4076,7 @@ SafeInt32Mult ( OUT INT32 *Result ) { - return SafeInt64ToInt32 (((INT64)Multiplicand) *((INT64)Multiplier), Result); + return SafeInt64ToInt32 (MultS64x64 (Multiplicand, Multiplier), Result); } /** diff --git a/MdePkg/Library/BaseSafeIntLib/SafeIntLib32.c b/MdePkg/Library/BaseSafeIntLib/SafeIntLib32.c index 18bfb9e413..ce66a92293 100644 --- a/MdePkg/Library/BaseSafeIntLib/SafeIntLib32.c +++ b/MdePkg/Library/BaseSafeIntLib/SafeIntLib32.c @@ -28,6 +28,7 @@ #include #include +#include /** INT32 -> UINTN conversion @@ -549,6 +550,6 @@ SafeIntnMult ( OUT INTN *Result ) { - return SafeInt64ToIntn (((INT64)Multiplicand) *((INT64)Multiplier), Result); + return SafeInt64ToIntn (MultS64x64 (Multiplicand, Multiplier), Result); } -- 2.39.2