apple / swift-crypto

Open-source implementation of a substantial portion of the API of Apple CryptoKit suitable for use on Linux platforms.
https://apple.github.io/swift-crypto
Apache License 2.0
1.47k stars 165 forks source link

Fix windows build and update BoringSSL to 2587c4974dbe9872451151c8e975f58567a1ce0d #279

Closed Lukasa closed 1 month ago

Lukasa commented 1 month ago

This patch updates the BoringSSL vendoring pattern and updates BoringSSL itself to 2587c4974dbe9872451151c8e975f58567a1ce0d.

The changes to vendored assembly mean that we're in the inverted pattern from where we were before: we now have arm64 assembly, but not x86 assembly. This patch comments out the x86 assembly support on Windows. I've reached out to the BoringSSL team to work out if there is any interest on their end in ceasing the use of nasm on Windows, as SwiftPM can't use it today. For now, however, this is the pragmatic compromise.

Resolves #275.

Lukasa commented 1 month ago

@gregcotten To ensure that we've actually squashed this series of bugs, would you be willing to also test this on your end? I've done some x86 Windows validation locally but I don't have an arm64 install of Windows floating about, and it sounds like you do.

gregcotten commented 1 month ago

Using

Swift version 6.0.1 (swift-6.0.1-RELEASE)
Target: aarch64-unknown-windows-msvc

swift build -c debug runs just fine.

swift build -c release, however, results in a nasty compiler assertion. I also get this on swift-crypto/main, so probably not even relevant to your PR?

Assertion failed: getAlign() && *getAlign() == Align && "Alignment representation error!", file C:\Users\swift-ci\jenkins\workspace\swift-6.0.0-windows-toolchain-arm64\llvm-project\llvm\lib\IR\Globals.cpp, line 140
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.      Program arguments: C:\\Users\\Greg\\AppData\\Local\\Programs\\Swift\\Toolchains\\6.0.1+Asserts\\usr\\bin\\clang.exe -target aarch64-unknown-windows-msvc -O2 -DSWIFT_PACKAGE=1 -fblocks -I C:\\Users\\Greg\\Documents\\GitHub\\lukasa-swift-crypto\\Sources\\CCryptoBoringSSL\\include -D_HAS_EXCEPTIONS=0 -DWIN32_LEAN_AND_MEAN -DNOMINMAX -D_CRT_SECURE_NO_WARNINGS -D_MT -D_DLL -Xclang --dependent-lib=msvcrt -gdwarf -MD -MT dependencies -MF C:\\Users\\Greg\\Documents\\GitHub\\lukasa-swift-crypto\\.build\\aarch64-unknown-windows-msvc\\release\\CCryptoBoringSSL.build\\crypto\\fipsmodule\\bcm.c.d -c C:\\Users\\Greg\\Documents\\GitHub\\lukasa-swift-crypto\\Sources\\CCryptoBoringSSL\\crypto\\fipsmodule\\bcm.c -o C:\\Users\\Greg\\Documents\\GitHub\\lukasa-swift-crypto\\.build\\aarch64-unknown-windows-msvc\\release\\CCryptoBoringSSL.build\\crypto\\fipsmodule\\bcm.c.o
1.      <eof> parser at end of file
2.      Optimizer
Exception Code: 0x80000003
 #0 0x00007ff7192fbb10 (C:\Users\Greg\AppData\Local\Programs\Swift\Toolchains\6.0.1+Asserts\usr\bin\clang.exe+0x167bb10)
 #1 0x00007ffa55a05f08 (C:\Windows\System32\ucrtbase.dll+0x75f08)
 #2 0x00007ffa55a06ebc (C:\Windows\System32\ucrtbase.dll+0x76ebc)
 #3 0x00007ffa55a086dc (C:\Windows\System32\ucrtbase.dll+0x786dc)
 #4 0x00007ffa55a088d8 (C:\Windows\System32\ucrtbase.dll+0x788d8)
 #5 0x00007ff718eb2aec (C:\Users\Greg\AppData\Local\Programs\Swift\Toolchains\6.0.1+Asserts\usr\bin\clang.exe+0x1232aec)
 #6 0x00007ff7193d51e0 (C:\Users\Greg\AppData\Local\Programs\Swift\Toolchains\6.0.1+Asserts\usr\bin\clang.exe+0x17551e0)
 #7 0x00007ff7193cd058 (C:\Users\Greg\AppData\Local\Programs\Swift\Toolchains\6.0.1+Asserts\usr\bin\clang.exe+0x174d058)
 #8 0x00007ff71908da60 (C:\Users\Greg\AppData\Local\Programs\Swift\Toolchains\6.0.1+Asserts\usr\bin\clang.exe+0x140da60)
 #9 0x00007ff718fadcd4 (C:\Users\Greg\AppData\Local\Programs\Swift\Toolchains\6.0.1+Asserts\usr\bin\clang.exe+0x132dcd4)
#10 0x00007ff718faa748 (C:\Users\Greg\AppData\Local\Programs\Swift\Toolchains\6.0.1+Asserts\usr\bin\clang.exe+0x132a748)
#11 0x00007ff718f9fbfc (C:\Users\Greg\AppData\Local\Programs\Swift\Toolchains\6.0.1+Asserts\usr\bin\clang.exe+0x131fbfc)
#12 0x00007ff718fa9994 (C:\Users\Greg\AppData\Local\Programs\Swift\Toolchains\6.0.1+Asserts\usr\bin\clang.exe+0x1329994)
#13 0x00007ff7195ec094 (C:\Users\Greg\AppData\Local\Programs\Swift\Toolchains\6.0.1+Asserts\usr\bin\clang.exe+0x196c094)
#14 0x00007ff718f0648c (C:\Users\Greg\AppData\Local\Programs\Swift\Toolchains\6.0.1+Asserts\usr\bin\clang.exe+0x128648c)
#15 0x00007ff7195ec044 (C:\Users\Greg\AppData\Local\Programs\Swift\Toolchains\6.0.1+Asserts\usr\bin\clang.exe+0x196c044)
#16 0x00007ff718f06b8c (C:\Users\Greg\AppData\Local\Programs\Swift\Toolchains\6.0.1+Asserts\usr\bin\clang.exe+0x1286b8c)
#17 0x00007ff7195ec43c (C:\Users\Greg\AppData\Local\Programs\Swift\Toolchains\6.0.1+Asserts\usr\bin\clang.exe+0x196c43c)
#18 0x00007ff718f066ec (C:\Users\Greg\AppData\Local\Programs\Swift\Toolchains\6.0.1+Asserts\usr\bin\clang.exe+0x12866ec)
#19 0x00007ff7195e5f2c (C:\Users\Greg\AppData\Local\Programs\Swift\Toolchains\6.0.1+Asserts\usr\bin\clang.exe+0x1965f2c)
#20 0x00007ff7195e327c (C:\Users\Greg\AppData\Local\Programs\Swift\Toolchains\6.0.1+Asserts\usr\bin\clang.exe+0x196327c)
#21 0x00007ff7195e3974 (C:\Users\Greg\AppData\Local\Programs\Swift\Toolchains\6.0.1+Asserts\usr\bin\clang.exe+0x1963974)
#22 0x00007ff71c7e994c (C:\Users\Greg\AppData\Local\Programs\Swift\Toolchains\6.0.1+Asserts\usr\bin\clang.exe+0x4b6994c)
#23 0x00007ff71ad520b0 (C:\Users\Greg\AppData\Local\Programs\Swift\Toolchains\6.0.1+Asserts\usr\bin\clang.exe+0x30d20b0)
#24 0x00007ff719dd5938 (C:\Users\Greg\AppData\Local\Programs\Swift\Toolchains\6.0.1+Asserts\usr\bin\clang.exe+0x2155938)
#25 0x00007ff71c7e8800 (C:\Users\Greg\AppData\Local\Programs\Swift\Toolchains\6.0.1+Asserts\usr\bin\clang.exe+0x4b68800)
#26 0x00007ff719dd5770 (C:\Users\Greg\AppData\Local\Programs\Swift\Toolchains\6.0.1+Asserts\usr\bin\clang.exe+0x2155770)
#27 0x00007ff719d86d6c (C:\Users\Greg\AppData\Local\Programs\Swift\Toolchains\6.0.1+Asserts\usr\bin\clang.exe+0x2106d6c)
#28 0x00007ff719e556c4 (C:\Users\Greg\AppData\Local\Programs\Swift\Toolchains\6.0.1+Asserts\usr\bin\clang.exe+0x21d56c4)
#29 0x00007ff717cfa248 (C:\Users\Greg\AppData\Local\Programs\Swift\Toolchains\6.0.1+Asserts\usr\bin\clang.exe+0x7a248)
#30 0x00007ff717cf1ad8 (C:\Users\Greg\AppData\Local\Programs\Swift\Toolchains\6.0.1+Asserts\usr\bin\clang.exe+0x71ad8)
#31 0x00007ff719c94af4 (C:\Users\Greg\AppData\Local\Programs\Swift\Toolchains\6.0.1+Asserts\usr\bin\clang.exe+0x2014af4)
#32 0x00007ff7192e9648 (C:\Users\Greg\AppData\Local\Programs\Swift\Toolchains\6.0.1+Asserts\usr\bin\clang.exe+0x1669648)
#33 0x00007ff719c950ec (C:\Users\Greg\AppData\Local\Programs\Swift\Toolchains\6.0.1+Asserts\usr\bin\clang.exe+0x20150ec)
#34 0x00007ff719be7884 (C:\Users\Greg\AppData\Local\Programs\Swift\Toolchains\6.0.1+Asserts\usr\bin\clang.exe+0x1f67884)
#35 0x00007ff719be7a88 (C:\Users\Greg\AppData\Local\Programs\Swift\Toolchains\6.0.1+Asserts\usr\bin\clang.exe+0x1f67a88)
#36 0x00007ff719bcb888 (C:\Users\Greg\AppData\Local\Programs\Swift\Toolchains\6.0.1+Asserts\usr\bin\clang.exe+0x1f4b888)
#37 0x00007ff717cf3d0c (C:\Users\Greg\AppData\Local\Programs\Swift\Toolchains\6.0.1+Asserts\usr\bin\clang.exe+0x73d0c)
#38 0x00007ff717d05624 (C:\Users\Greg\AppData\Local\Programs\Swift\Toolchains\6.0.1+Asserts\usr\bin\clang.exe+0x85624)
#39 0x00007ff71c057c40 (C:\Users\Greg\AppData\Local\Programs\Swift\Toolchains\6.0.1+Asserts\usr\bin\clang.exe+0x43d7c40)
#40 0x00007ff71c057cdc (C:\Users\Greg\AppData\Local\Programs\Swift\Toolchains\6.0.1+Asserts\usr\bin\clang.exe+0x43d7cdc)
#41 0x00007ffa57f42310 (C:\Windows\System32\KERNEL32.DLL+0x12310)
#42 0x00007ffa59875afc (C:\Windows\SYSTEM32\ntdll.dll+0x75afc)
clang: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 17.0.6
Target: aarch64-unknown-windows-msvc
Thread model: posix
InstalledDir: C:\Users\Greg\AppData\Local\Programs\Swift\Toolchains\6.0.1+Asserts\usr\bin
clang: note: diagnostic msg:
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang: note: diagnostic msg: C:\Users\Greg\AppData\Local\Temp\bcm-55dc5b.c
clang: note: diagnostic msg: C:\Users\Greg\AppData\Local\Temp\bcm-55dc5b.sh
clang: note: diagnostic msg:

********************
[1/5] Compiling CCryptoBoringSSL crypto\fipsmodule\bcm.c
(process terminates)

I've attached the diagnostic c file and shell script, if that's relevant to you. bcm-55dc5b_diagnostics.zip

Lukasa commented 1 month ago

Yeah, not relevant to this PR but not good: we shouldn't be able to crash clang, and having the release build be impossible to do is pretty bad.

Lukasa commented 1 month ago

I'm chasing this crash with the LLVM folks. In the meantime, given the evidence that this doesn't regress main from where it currently is, I'll merge this patch.