EDK2应用程序在包含LibC和OpensslLib时无法构建,找不到stdatomic.h

huangapple go评论87阅读模式
英文:

EDK2 application fails to build when including both LibC & OpensslLib, stdatomic.h not found

问题

I'm modifying EDK2's ShellPkg application to hardcode the arguments and launch a specific efi application through that shell (see here for context). I want to include OpenSSL so I can verify whether the application I want to run is the correct one. I'm using the edk2-stable202305 release.

To do this, I open the file using fopen (which I include from the StdLib package), and then try use the Sha256Init, Sha256Update and Sha256Final methods from EDK2's OpensslLib to verify the hash of the application I want to run through the shell.

The problem is if I try to build the modified ShellPkg (build -p ShellPkg/ShellPkg.dsc -t GCC5 -a X64 -b RELEASE), I get this error:

In file included from /home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/include/crypto/evp.h:11,
                 from /home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/asn1/a_sign.c:22:
/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/include/internal/refcount.h:21:12: fatal error: stdatomic.h: No such file or directory
 #  include <stdatomic.h>
            ^~~~~~~~~~~~~
compilation terminated.
make: *** [GNUmakefile:1444: /home/zjeffer/git/edk2/edk2/Build/Shell/RELEASE_GCC5/X64/CryptoPkg/Library/OpensslLib/OpensslLibCrypto/OUTPUT/openssl/crypto/asn1/a_sign.obj] Error 1
@/home/zjeffer/git/edk2/edk2/Build/Shell/RELEASE_GCC5/X64/CryptoPkg/Library/OpensslLib/OpensslLibCrypto/OUTPUT/cc_resp.txt
 -g -Os -fshort-wchar -fno-builtin -fno-strict-aliasing -Wall -Werror -Wno-array-bounds -include AutoGen.h -fno-common -ffunction-sections -fdata-sections -DSTRING_ARRAY_NAME=OpensslLibCryptoStrings -m64 -fno-stack-protector "-DEFIAPI=__attribute__((ms_abi))" -maccumulate-outgoing-args -mno-red-zone -Wno-address -mcmodel=small -fpie -fno-asynchronous-unwind-tables -Wno-address  -fno-omit-frame-pointer -flto -DUSING_LTO -Wno-unused-but-set-variable -Wno-unused-const-variable -U_WIN32 -U_WIN64 -DL_ENDIAN -DOPENSSL_SMALL_FOOTPRINT -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE -DOPENSSL_NO_EC -DOPENSSL_NO_ECDH -DOPENSSL_NO_ECDSA -DOPENSSL_NO_TLS1_3 -DOPENSSL_NO_SM2 -DOPENSSL_NO_ASM  -Wno-error=maybe-uninitialized -Wno-error=format -Wno-format -Wno-error=unused-but-set-variable -DNO_MSABI_VA_FUNCS -Wno-unused-but-set-variable -D DISABLE_NEW_DEPRECATED_INTERFACES -nostdinc -nostdlib -DUEFI_C_SOURCE -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/store -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/x509v3 -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/x509 -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/ui -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/txt_db -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/stack -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/sm4 -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/sm3 -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/siphash -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/sha -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/rsa -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/rand -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/pkcs7 -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/pkcs12 -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/pem -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/ocsp -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/objects -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/modes -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/md5 -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/lhash -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/kdf -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/hmac -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/evp -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/err -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/dso -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/dh -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library

<details>
<summary>英文:</summary>

I&#39;m modifying EDK2&#39;s ShellPkg application to hardcode the arguments and launch a specific efi application through that shell (see [here][1] for context). I want to include OpenSSL so I can verify whether the application I want to run is the correct one. I&#39;m using the edk2-stable202305 release.

To do this, I open the file using fopen (which I include from the StdLib package), and then try use the Sha256Init, Sha256Update and Sha256Final methods from EDK2&#39;s OpensslLib to verify the hash of the application I want to run through the shell.

The problem is if I try to build the modified ShellPkg (`build -p ShellPkg/ShellPkg.dsc -t GCC5 -a X64 -b RELEASE`), I get this error:


```sh
In file included from /home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/include/crypto/evp.h:11,
                 from /home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/asn1/a_sign.c:22:
/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/include/internal/refcount.h:21:12: fatal error: stdatomic.h: No such file or directory
 #  include &lt;stdatomic.h&gt;
            ^~~~~~~~~~~~~
compilation terminated.
make: *** [GNUmakefile:1444: /home/zjeffer/git/edk2/edk2/Build/Shell/RELEASE_GCC5/X64/CryptoPkg/Library/OpensslLib/OpensslLibCrypto/OUTPUT/openssl/crypto/asn1/a_sign.obj] Error 1
@/home/zjeffer/git/edk2/edk2/Build/Shell/RELEASE_GCC5/X64/CryptoPkg/Library/OpensslLib/OpensslLibCrypto/OUTPUT/cc_resp.txt
 -g -Os -fshort-wchar -fno-builtin -fno-strict-aliasing -Wall -Werror -Wno-array-bounds -include AutoGen.h -fno-common -ffunction-sections -fdata-sections -DSTRING_ARRAY_NAME=OpensslLibCryptoStrings -m64 -fno-stack-protector &quot;-DEFIAPI=__attribute__((ms_abi))&quot; -maccumulate-outgoing-args -mno-red-zone -Wno-address -mcmodel=small -fpie -fno-asynchronous-unwind-tables -Wno-address  -fno-omit-frame-pointer -flto -DUSING_LTO -Wno-unused-but-set-variable -Wno-unused-const-variable -U_WIN32 -U_WIN64 -DL_ENDIAN -DOPENSSL_SMALL_FOOTPRINT -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE -DOPENSSL_NO_EC -DOPENSSL_NO_ECDH -DOPENSSL_NO_ECDSA -DOPENSSL_NO_TLS1_3 -DOPENSSL_NO_SM2 -DOPENSSL_NO_ASM  -Wno-error=maybe-uninitialized -Wno-error=format -Wno-format -Wno-error=unused-but-set-variable -DNO_MSABI_VA_FUNCS -Wno-unused-but-set-variable -D DISABLE_NEW_DEPRECATED_INTERFACES -nostdinc -nostdlib -DUEFI_C_SOURCE -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/store -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/x509v3 -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/x509 -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/ui -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/txt_db -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/stack -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/sm4 -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/sm3 -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/siphash -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/sha -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/rsa -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/rand -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/pkcs7 -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/pkcs12 -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/pem -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/ocsp -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/objects -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/modes -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/md5 -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/lhash -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/kdf -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/hmac -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/evp -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/err -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/dso -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/dh -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/conf -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/comp -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/cmac -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/buffer -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/bn -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/bio -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/async -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/async/arch -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/asn1 -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/aria -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/aes -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/ms -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib -I/home/zjeffer/git/edk2/edk2/Build/Shell/RELEASE_GCC5/X64/CryptoPkg/Library/OpensslLib/OpensslLibCrypto/DEBUG -I/home/zjeffer/git/edk2/edk2/MdePkg -I/home/zjeffer/git/edk2/edk2/MdePkg/Include -I/home/zjeffer/git/edk2/edk2/MdePkg/Test/UnitTest/Include -I/home/zjeffer/git/edk2/edk2/MdePkg/Test/Mock/Include -I/home/zjeffer/git/edk2/edk2/MdePkg/Library/MipiSysTLib/mipisyst/library/include -I/home/zjeffer/git/edk2/edk2/MdePkg/Include/X64 -I/home/zjeffer/git/edk2/edk2/CryptoPkg -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Include -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Private -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/Include -I/home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/openssl/include



build.py...
 : error 7000: Failed to execute command
        make tbuild [/home/zjeffer/git/edk2/edk2/Build/Shell/RELEASE_GCC5/X64/CryptoPkg/Library/OpensslLib/OpensslLibCrypto]


build.py...
 : error 7000: Failed to execute command
        make tbuild [/home/zjeffer/git/edk2/edk2/Build/Shell/RELEASE_GCC5/X64/CryptoPkg/Library/BaseCryptLib/BaseCryptLib]


build.py...
 : error F002: Failed to build module
        /home/zjeffer/git/edk2/edk2/CryptoPkg/Library/OpensslLib/OpensslLibCrypto.inf [X64, GCC5, RELEASE]

- Failed -

My Shell.inf has the following changes:

[Packages]
  MdePkg/MdePkg.dec
  ShellPkg/ShellPkg.dec
  MdeModulePkg/MdeModulePkg.dec
  StdLib/StdLib.dec
  CryptoPkg/CryptoPkg.dec

[LibraryClasses]
  BaseLib
  UefiApplicationEntryPoint
  UefiLib
  DebugLib
  MemoryAllocationLib
  ShellCommandLib
  UefiRuntimeServicesTableLib
  UefiBootServicesTableLib
  DevicePathLib
  BaseMemoryLib
  PcdLib
  FileHandleLib
  PrintLib
  HiiLib
  SortLib
  HandleParsingLib
  UefiHiiServicesLib
  LibC
  LibStdio
  LibStdLib
  LibString
  LibWchar
  BaseCryptLib
  OpensslLib
  MemoryAllocationLib

My ShellPkg.dsc has the following changes:

  • I included StdLib like this: !include StdLib/StdLib.inc
  • Under [LibraryClasses.common], I added these libraries:
  BaseLib|MdePkg/Library/BaseLib/BaseLib.inf
BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf
BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf
SafeIntLib|MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf
SynchronizationLib|MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.inf
TimerLib|MdePkg/Library/BaseTimerLibNullTemplate/BaseTimerLibNullTemplate.inf
RngLib|MdePkg/Library/BaseRngLib/BaseRngLib.inf
OemHookStatusCodeLib|MdeModulePkg/Library/OemHookStatusCodeLibNull/OemHookStatusCodeLibNull.inf
HashApiLib|CryptoPkg/Library/BaseHashApiLib/BaseHashApiLib.inf
IntrinsicLib|CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf
MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf
# I don&#39;t know which one of these two I should use, they both give the error.
# OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLib.inf 
OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLibCrypto.inf

The error occurs regardless of whether I include any OpenSSL libraries in the Shell.c application.

What's interesting is that if I try to build the CryptoPkg instead (build -p CryptoPkg/CryptoPkg.dsc -t GCC5 -b RELEASE -a X64), which includes the OpensslLib, it builds without issues.


  • I'm using gcc 8.3.0
  • It gives the same error on another system with gcc 11.3.0
  • If I remove the StdLib package, I don't get the error, but I would like to use those libraries in my application.
  • If I include StdLib, and define __STDC_NO_ATOMICS__, I get lots of other errors, most of them multiple definitions errors like this:
/usr/bin/ld: MemoryIntrinsics.obj (symbol from plugin): in function `memset&#39;:
(.text+0x0): multiple definition of `memset&#39;; Misc.obj (symbol from plugin):(.text+0x0): first defined here
/usr/bin/ld: MemoryIntrinsics.obj (symbol from plugin): in function `memset&#39;:
(.text+0x0): multiple definition of `memcmp&#39;; Comparison.obj (symbol from plugin):(.text+0x0): first defined here

答案1

得分: 1

BaseCryptLib定义了一些符号,这些符号也将在LibC中定义。这是在没有LibC的情况下使用OpenSSL所必需的。

如果您想同时使用它们,您必须从BaseCryptLib中排除具有这些定义的代码文件。
如果您只需要LibC中的fopen、fread等方法,请用本机UEFI方法替换它们,这将是最简单的解决方案。

英文:

The BaseCryptLib defines some symbols that will also be defined in LibC. This is required to use OpenSSL without LibC.

If you want to use both, you must exclude the code files with this definitions from BaseCryptLib.
If you only need the fopen, fread,... methods from LibC replace them with the native UEFI methods, this will be the simplest solution.

huangapple
  • 本文由 发表于 2023年6月5日 16:59:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/76404882.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定