From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.65; helo=mga03.intel.com; envelope-from=hao.a.wu@intel.com; receiver=edk2-devel@lists.01.org Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id BBA9B21CF1CE5 for ; Mon, 12 Feb 2018 18:03:10 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Feb 2018 18:09:00 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,505,1511856000"; d="scan'208";a="30272490" Received: from shwdeopenpsi014.ccr.corp.intel.com ([10.239.9.10]) by fmsmga001.fm.intel.com with ESMTP; 12 Feb 2018 18:08:59 -0800 From: Hao Wu To: edk2-devel@lists.01.org Cc: Hao Wu , Michael D Kinney , Sean Brogan , Jiewen Yao , Liming Gao Date: Tue, 13 Feb 2018 10:08:56 +0800 Message-Id: <20180213020856.11328-1-hao.a.wu@intel.com> X-Mailer: git-send-email 2.12.0.windows.1 Subject: [PATCH] MdePkg/BaseSafeIntLib: Fix VS IA32 NOOPT target build failure X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 13 Feb 2018 02:03:11 -0000 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 Cc: Sean Brogan Cc: Jiewen Yao Cc: Liming Gao Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Hao Wu --- 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 #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,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 #include +#include /** 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 #include +#include /** 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