microsoft / SymCrypt

Cryptographic library
MIT License
660 stars 68 forks source link

Build break in GCC 8 #16

Closed xumia closed 2 years ago

xumia commented 3 years ago

Build error:

/__w/1/SymCrypt/lib/rdseed.c: In function 'SymCryptRdseedSizet':
/__w/1/SymCrypt/lib/rdseed.c:22:28: warning: implicit declaration of function '_rdseed64_step'; did you mean '_rdseedxx_step'? [-Wimplicit-function-declaration]
 #define _rdseedxx_step(_p) _rdseed64_step( (UINT64  *) (_p) )
                            ^~~~~~~~~~~~~~
/__w/1/SymCrypt/lib/rdseed.c:40:7: note: in expansion of macro '_rdseedxx_step'
   if( _rdseedxx_step( p ) != 0 )
       ^~~~~~~~~~~~~~

[ 98%] Built target symcryptunittest_lib
Scanning dependencies of target symcryptunittest
[ 99%] Building CXX object unittest/exe_linux/CMakeFiles/symcryptunittest.dir/main_exe.cpp.o
[ 99%] Linking CXX executable ../../exe/AMD64/LinuxUserMode/symcryptunittest
/usr/bin/ld: ../../lib/AMD64/LinuxUserMode/libsymcrypt_common.a(rdseed.c.o): in function `SymCryptRdseedSizet':
/__w/1/SymCrypt/lib/rdseed.c:40: undefined reference to `_rdseed64_step'
collect2: error: ld returned 1 exit status
make[2]: *** [unittest/exe_linux/CMakeFiles/symcryptunittest.dir/build.make:86: exe/AMD64/LinuxUserMode/symcryptunittest] Error 1
make[1]: *** [CMakeFiles/Makefile2:433: unittest/exe_linux/CMakeFiles/symcryptunittest.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
##[error]Bash exited with code '2'.

See detail: https://dev.azure.com/mssonic/build/_build/results?buildId=22857&view=logs&j=12f1170f-54f2-53f3-20dd-22fc7dff55f9&t=59a85588-b0ba-5043-24c4-d9e29d89c6f6

To reproduce it, only need to build it in debian:buster docker image.

Analysis:

https://github.com/microsoft/SymCrypt/blob/b15ec2c87d54704474ee8d26c95e90762c746ba2/lib/precomp.h#L19

/usr/lib/gcc/x86_64-linux-gnu/8/include/rdseedintrin.h:# error "Never use directly; include instead."

/usr/lib/gcc/x86_64-linux-gnu/9/include/rdseedintrin.h:# error "Never use directly; include instead."

For GCC <=8, need to change to include See https://github.com/gcc-mirror/gcc/commit/59a95143ddeb4939fe2336e8f86cbc908bfa8e1a

Workaround:

cmake .. -DCMAKE_TOOLCHAIN_FILE=../cmake-toolchain/LinuxUserMode-AMD64.cmake -DCMAKE_C_FLAGS="-D_rdseed64_step=__builtin_ia32_rdseed_di_step"

Support request:

GCC 8 is used by debian:buster, which is the latest version of debian currently. Could you please help support it?

mlindgren commented 2 years ago

@xumia apologies for not replying to this earlier - support for Debian/older versions of GCC hasn't been a priority for us. It looks like the current stable version of Debian is now "bullseye." Is this change still needed?

xumia commented 2 years ago

@mlindgren , we have changed to use bullseye, not necessary to support the earlier version for us, thanks.