[PATCH] CryptoPkg/FltUsedLib: Add FltUsedLib for float.


 

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2596

OpenSSL requires _fltused to be defined as a constant anywhere floating
point is used.
This is to satisfy the linker, however, it is possible to compile a
module with multiple definitions of fltused. This causes the
MSVC compiler to fail the build.
To solve this problem, the FltUsedLib was created that is one spot
that the global static can exist.

Cc: Jian J Wang <jian.j.wang@...>
Cc: Xiaoyu Lu <xiaoyux.lu@...>
Signed-off-by: Guomin Jiang <guomin.jiang@...>
---
CryptoPkg/CryptoPkg.dsc | 2 ++
.../Library/BaseCryptLib/BaseCryptLib.inf | 1 +
.../Library/BaseCryptLib/PeiCryptLib.inf | 1 +
.../Library/BaseCryptLib/RuntimeCryptLib.inf | 1 +
.../Library/BaseCryptLib/SmmCryptLib.inf | 1 +
CryptoPkg/Library/FltUsedLib/FltUsedLib.c | 14 ++++++++
CryptoPkg/Library/FltUsedLib/FltUsedLib.inf | 33 +++++++++++++++++++
CryptoPkg/Library/TlsLib/TlsLib.inf | 1 +
8 files changed, 54 insertions(+)
create mode 100644 CryptoPkg/Library/FltUsedLib/FltUsedLib.c
create mode 100644 CryptoPkg/Library/FltUsedLib/FltUsedLib.inf

diff --git a/CryptoPkg/CryptoPkg.dsc b/CryptoPkg/CryptoPkg.dsc
index 4cb37b1349..e9854087b5 100644
--- a/CryptoPkg/CryptoPkg.dsc
+++ b/CryptoPkg/CryptoPkg.dsc
@@ -97,6 +97,7 @@
IoLib|MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf =
#???=0D
OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLib.inf=0D
IntrinsicLib|CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf=0D
+ FltUsedLib|CryptoPkg/Library/FltUsedLib/FltUsedLib.inf=0D
SafeIntLib|MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf=0D
=0D
[LibraryClasses.ARM]=0D
@@ -232,6 +233,7 @@
CryptoPkg/Library/BaseCryptLib/RuntimeCryptLib.inf=0D
CryptoPkg/Library/BaseCryptLibNull/BaseCryptLibNull.inf=0D
CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf=0D
+ CryptoPkg/Library/FltUsedLib/FltUsedLib.inf=0D
CryptoPkg/Library/TlsLib/TlsLib.inf=0D
CryptoPkg/Library/TlsLibNull/TlsLibNull.inf=0D
CryptoPkg/Library/OpensslLib/OpensslLib.inf=0D
diff --git a/CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf b/CryptoPkg/Li=
brary/BaseCryptLib/BaseCryptLib.inf
index 1bbe4f435a..c82e703aa0 100644
--- a/CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
+++ b/CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
@@ -84,6 +84,7 @@
DebugLib=0D
OpensslLib=0D
IntrinsicLib=0D
+ FltUsedLib=0D
PrintLib=0D
=0D
#=0D
diff --git a/CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf b/CryptoPkg/Lib=
rary/BaseCryptLib/PeiCryptLib.inf
index c836c257f8..342aad008c 100644
--- a/CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf
+++ b/CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf
@@ -78,6 +78,7 @@
DebugLib=0D
OpensslLib=0D
IntrinsicLib=0D
+ FltUsedLib=0D
=0D
#=0D
# Remove these [BuildOptions] after this library is cleaned up=0D
diff --git a/CryptoPkg/Library/BaseCryptLib/RuntimeCryptLib.inf b/CryptoPkg=
/Library/BaseCryptLib/RuntimeCryptLib.inf
index bff308a4f5..dcf209d7f5 100644
--- a/CryptoPkg/Library/BaseCryptLib/RuntimeCryptLib.inf
+++ b/CryptoPkg/Library/BaseCryptLib/RuntimeCryptLib.inf
@@ -89,6 +89,7 @@
DebugLib=0D
OpensslLib=0D
IntrinsicLib=0D
+ FltUsedLib=0D
PrintLib=0D
=0D
#=0D
diff --git a/CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf b/CryptoPkg/Lib=
rary/BaseCryptLib/SmmCryptLib.inf
index cc0b65fd25..7fdaaa48a6 100644
--- a/CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf
+++ b/CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf
@@ -88,6 +88,7 @@
MemoryAllocationLib=0D
OpensslLib=0D
IntrinsicLib=0D
+ FltUsedLib=0D
PrintLib=0D
=0D
#=0D
diff --git a/CryptoPkg/Library/FltUsedLib/FltUsedLib.c b/CryptoPkg/Library/=
FltUsedLib/FltUsedLib.c
new file mode 100644
index 0000000000..8f2487ea13
--- /dev/null
+++ b/CryptoPkg/Library/FltUsedLib/FltUsedLib.c
@@ -0,0 +1,14 @@
+/** @file=0D
+ Need include this when use floats.=0D
+=0D
+ Copyright (C) Microsoft Corporation. All rights reserved.<BR>=0D
+ Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>=0D
+ SPDX-License-Identifier: BSD-2-Clause-Patent=0D
+=0D
+**/=0D
+=0D
+//=0D
+// You need to include this to let the compiler know we are going to use=0D
+// floating point=0D
+//=0D
+int _fltused =3D 0x9875;=0D
diff --git a/CryptoPkg/Library/FltUsedLib/FltUsedLib.inf b/CryptoPkg/Librar=
y/FltUsedLib/FltUsedLib.inf
new file mode 100644
index 0000000000..8d67eadfa5
--- /dev/null
+++ b/CryptoPkg/Library/FltUsedLib/FltUsedLib.inf
@@ -0,0 +1,33 @@
+## @file=0D
+# It is depent on when using floats=0D
+#=0D
+# Copyright (C) Microsoft Corporation. All rights reserved.<BR>=0D
+# Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>=0D
+# SPDX-License-Identifier: BSD-2-Clause-Patent=0D
+#=0D
+##=0D
+=0D
+[Defines]=0D
+ INF_VERSION =3D 0x00010005=0D
+ BASE_NAME =3D FltUsedLib=0D
+ FILE_GUID =3D C004F180-9FE2-4D2B-8318-BADC2A231774=
=0D
+ MODULE_TYPE =3D BASE=0D
+ VERSION_STRING =3D 1.0=0D
+ LIBRARY_CLASS =3D FltUsedLib=0D
+=0D
+#=0D
+# The following information is for reference only and not required by the =
build tools.=0D
+#=0D
+# VALID_ARCHITECTURES =3D IA32 X64 AARCH64=0D
+#=0D
+=0D
+[Sources]=0D
+ FltUsedLib.c=0D
+=0D
+[Packages]=0D
+ MdePkg/MdePkg.dec=0D
+=0D
+[BuildOptions]=0D
+ # Disable GL due to linker error LNK1237=0D
+ # https://docs.microsoft.com/en-us/cpp/error-messages/tool-errors/linker=
-tools-error-lnk1237?view=3Dvs-2017=0D
+ MSFT:*_*_*_CC_FLAGS =3D /GL-=0D
diff --git a/CryptoPkg/Library/TlsLib/TlsLib.inf b/CryptoPkg/Library/TlsLib=
/TlsLib.inf
index 2f3ce695c3..febbdf5149 100644
--- a/CryptoPkg/Library/TlsLib/TlsLib.inf
+++ b/CryptoPkg/Library/TlsLib/TlsLib.inf
@@ -37,6 +37,7 @@
BaseMemoryLib=0D
DebugLib=0D
IntrinsicLib=0D
+ FltUsedLib=0D
MemoryAllocationLib=0D
OpensslLib=0D
SafeIntLib=0D
--=20
2.25.1.windows.1

Join devel@edk2.groups.io to automatically receive all group messages.