Open swift-ci opened 5 years ago
@swift-ci create
one line repro (assuming docker is installed):
git clone https://github.com/vapor/crypto.git && cd crypto && git reset --hard 13e0acacb5bdd27f0031930854798254f2156060 && docker pull swift && docker run -it --rm -w "$PWD" -v "$PWD:$PWD" swift swift build
output is
$ git clone https://github.com/vapor/crypto.git && cd crypto && git reset --hard 13e0acacb5bdd27f0031930854798254f2156060 && docker pull swift && docker run -it --rm -w /tmp/crypto -v /tmp/crypto:/tmp/crypto swift swift build
Cloning into 'crypto'...
remote: Enumerating objects: 90, done.
remote: Counting objects: 100% (90/90), done.
remote: Compressing objects: 100% (60/60), done.
remote: Total 1766 (delta 36), reused 64 (delta 22), pack-reused 1676
Receiving objects: 100% (1766/1766), 396.85 KiB | 1.71 MiB/s, done.
Resolving deltas: 100% (852/852), done.
HEAD is now at 13e0aca small typo fix
Using default tag: latest
latest: Pulling from library/swift
Digest: sha256:642beec6d119c3f2e22740bf91f6ca383727237794db8980d5d00ea71d117394
Status: Image is up to date for swift:latest
Fetching https://github.com/apple/swift-nio-ssl.git
Fetching https://github.com/apple/swift-nio-ssl-support.git
Fetching https://github.com/vapor/core.git
Fetching https://github.com/apple/swift-nio.git
Fetching https://github.com/apple/swift-nio-zlib-support.git
Completed resolution in 33.06s
Cloning https://github.com/apple/swift-nio-ssl.git
Resolving https://github.com/apple/swift-nio-ssl.git at 1.3.1
Cloning https://github.com/apple/swift-nio.git
Resolving https://github.com/apple/swift-nio.git at 1.9.5
Cloning https://github.com/apple/swift-nio-ssl-support.git
Resolving https://github.com/apple/swift-nio-ssl-support.git at 1.0.0
Cloning https://github.com/apple/swift-nio-zlib-support.git
Resolving https://github.com/apple/swift-nio-zlib-support.git at 1.0.0
Cloning https://github.com/vapor/core.git
Resolving https://github.com/vapor/core.git at 3.4.3
Compile Swift Module 'NIOPriorityQueue' (2 sources)
Compile CNIOSHA1 c_nio_sha1.c
Compile Swift Module 'COperatingSystem' (1 sources)
Compile Swift Module 'Debugging' (3 sources)
Compile CNIOOpenSSL shims.c
Compile CNIOOpenSSL helpers.c
Compile CNIOLinux shim.c
Compile CNIODarwin shim.c
Compile CNIOAtomics src/c-atomics.c
Compile CCryptoOpenSSL shim.c
Compile CBcrypt blf.c
Compile CBcrypt bcrypt.c
Compile CBase32 base32.c
Compile Swift Module 'NIOConcurrencyHelpers' (2 sources)
Compile Swift Module 'NIO' (52 sources)
Compile Swift Module 'NIOFoundationCompat' (1 sources)
Compile Swift Module 'NIOTLS' (3 sources)
Compile Swift Module 'Bits' (12 sources)
Compile Swift Module 'Async' (15 sources)
Compile Swift Module 'NIOOpenSSL' (15 sources)
Compile Swift Module 'Random' (4 sources)
Compile Swift Module 'Core' (25 sources)
/tmp/crypto/.build/checkouts/swift-nio-ssl.git-4227812431449795004/Sources/NIOOpenSSL/OpenSSLHandler.swift:270:35: warning: 'changeCapacity(to:)' is deprecated: changeCapacity has been replaced by reserveCapacity
receiveBuffer.changeCapacity(to: receiveBuffer.capacity + 1024)
^
Compile Swift Module 'Crypto' (15 sources)
swift: /home/buildnode/jenkins/workspace/oss-swift-4.2-package-linux-ubuntu-16_04/llvm/tools/clang/lib/CodeGen/CGRecordLayout.h:187: unsigned int clang::CodeGen::CGRecordLayout::getLLVMFieldNo(const clang::FieldDecl *) const: Assertion `FieldInfo.count(FD) && "Invalid field for record!"' failed.
/usr/bin/swift[0x4108b64]
/usr/bin/swift[0x41069f2]
/usr/bin/swift[0x4108d12]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x11390)[0x7f1748d2c390]
/lib/x86_64-linux-gnu/libc.so.6(gsignal+0x38)[0x7f174746b428]
/lib/x86_64-linux-gnu/libc.so.6(abort+0x16a)[0x7f174746d02a]
/lib/x86_64-linux-gnu/libc.so.6(+0x2dbd7)[0x7f1747463bd7]
/lib/x86_64-linux-gnu/libc.so.6(+0x2dc82)[0x7f1747463c82]
/usr/bin/swift[0x6c26c5]
/usr/bin/swift[0x78cf76]
/usr/bin/swift[0x773955]
/usr/bin/swift[0x7810bc]
/usr/bin/swift[0x770098]
/usr/bin/swift[0x779a54]
/usr/bin/swift[0x7c8bb5]
/usr/bin/swift[0x7bf536]
/usr/bin/swift[0x76f790]
/usr/bin/swift[0x76f739]
/usr/bin/swift[0x811764]
/usr/bin/swift[0x81b9bf]
/usr/bin/swift[0x864c30]
/usr/bin/swift[0x87a06c]
/usr/bin/swift[0x874c39]
/usr/bin/swift[0x87c674]
/usr/bin/swift[0x6cabf0]
/usr/bin/swift[0x66a42b]
/usr/bin/swift[0x50b68f]
/usr/bin/swift[0x5eb716]
/usr/bin/swift[0x5e6ab8]
/usr/bin/swift[0x5e4a5e]
/usr/bin/swift[0x5064d5]
/usr/bin/swift[0x5be9c1]
/usr/bin/swift[0x5bf1a1]
/usr/bin/swift[0x4df28d]
/usr/bin/swift[0x4da400]
/usr/bin/swift[0x48a348]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0)[0x7f1747456830]
/usr/bin/swift[0x488009]
Stack dump:
0. Program arguments: /usr/bin/swift -frontend -c /tmp/crypto/Sources/Crypto/BCrypt/BCryptDigest.swift /tmp/crypto/Sources/Crypto/Cipher/Cipher.swift /tmp/crypto/Sources/Crypto/Cipher/CipherAlgorithm.swift /tmp/crypto/Sources/Crypto/Digest/Digest.swift /tmp/crypto/Sources/Crypto/Digest/DigestAlgorithm.swift /tmp/crypto/Sources/Crypto/MAC/HMAC.swift /tmp/crypto/Sources/Crypto/MAC/OTP.swift /tmp/crypto/Sources/Crypto/RSA/RSA.swift -primary-file /tmp/crypto/Sources/Crypto/RSA/RSAKey.swift -primary-file /tmp/crypto/Sources/Crypto/RSA/RSAPadding.swift -primary-file /tmp/crypto/Sources/Crypto/Random/CryptoRandom.swift -primary-file /tmp/crypto/Sources/Crypto/Utilities/Base32.swift /tmp/crypto/Sources/Crypto/Utilities/CryptoError.swift /tmp/crypto/Sources/Crypto/Utilities/Deprecated.swift /tmp/crypto/Sources/Crypto/Utilities/Exports.swift -emit-module-path /tmp/crypto/.build/x86_64-unknown-linux/debug/Crypto.build/RSAKey~partial.swiftmodule -emit-module-path /tmp/crypto/.build/x86_64-unknown-linux/debug/Crypto.build/RSAPadding~partial.swiftmodule -emit-module-path /tmp/crypto/.build/x86_64-unknown-linux/debug/Crypto.build/CryptoRandom~partial.swiftmodule -emit-module-path /tmp/crypto/.build/x86_64-unknown-linux/debug/Crypto.build/Base32~partial.swiftmodule -emit-module-doc-path /tmp/crypto/.build/x86_64-unknown-linux/debug/Crypto.build/RSAKey~partial.swiftdoc -emit-module-doc-path /tmp/crypto/.build/x86_64-unknown-linux/debug/Crypto.build/RSAPadding~partial.swiftdoc -emit-module-doc-path /tmp/crypto/.build/x86_64-unknown-linux/debug/Crypto.build/CryptoRandom~partial.swiftdoc -emit-module-doc-path /tmp/crypto/.build/x86_64-unknown-linux/debug/Crypto.build/Base32~partial.swiftdoc -emit-dependencies-path /tmp/crypto/.build/x86_64-unknown-linux/debug/Crypto.build/RSAKey.d -emit-dependencies-path /tmp/crypto/.build/x86_64-unknown-linux/debug/Crypto.build/RSAPadding.d -emit-dependencies-path /tmp/crypto/.build/x86_64-unknown-linux/debug/Crypto.build/CryptoRandom.d -emit-dependencies-path /tmp/crypto/.build/x86_64-unknown-linux/debug/Crypto.build/Base32.d -emit-reference-dependencies-path /tmp/crypto/.build/x86_64-unknown-linux/debug/Crypto.build/RSAKey.swiftdeps -emit-reference-dependencies-path /tmp/crypto/.build/x86_64-unknown-linux/debug/Crypto.build/RSAPadding.swiftdeps -emit-reference-dependencies-path /tmp/crypto/.build/x86_64-unknown-linux/debug/Crypto.build/CryptoRandom.swiftdeps -emit-reference-dependencies-path /tmp/crypto/.build/x86_64-unknown-linux/debug/Crypto.build/Base32.swiftdeps -target x86_64-unknown-linux -disable-objc-interop -sdk / -I /tmp/crypto/.build/x86_64-unknown-linux/debug -I /tmp/crypto/.build/checkouts/swift-nio-ssl.git-4227812431449795004/Sources/CNIOOpenSSL/include -I /tmp/crypto/.build/checkouts/swift-nio.git-1751651985981854940/Sources/CNIOSHA1/include -I /tmp/crypto/.build/checkouts/swift-nio.git-1751651985981854940/Sources/CNIOAtomics/include -I /tmp/crypto/.build/checkouts/swift-nio.git-1751651985981854940/Sources/CNIODarwin/include -I /tmp/crypto/.build/checkouts/swift-nio.git-1751651985981854940/Sources/CNIOLinux/include -I /tmp/crypto/Sources/CCryptoOpenSSL/include -I /tmp/crypto/Sources/CBcrypt/include -I /tmp/crypto/Sources/CBase32/include -enable-testing -g -module-cache-path /tmp/crypto/.build/x86_64-unknown-linux/debug/ModuleCache -swift-version 4 -Onone -D SWIFT_PACKAGE -D DEBUG -color-diagnostics -Xcc -fmodule-map-file=/tmp/crypto/.build/x86_64-unknown-linux/debug/CNIOOpenSSL.build/module.modulemap -Xcc -fmodule-map-file=/tmp/crypto/.build/x86_64-unknown-linux/debug/CNIOSHA1.build/module.modulemap -Xcc -fmodule-map-file=/tmp/crypto/.build/x86_64-unknown-linux/debug/CNIOAtomics.build/module.modulemap -Xcc -fmodule-map-file=/tmp/crypto/.build/x86_64-unknown-linux/debug/CNIODarwin.build/module.modulemap -Xcc -fmodule-map-file=/tmp/crypto/.build/x86_64-unknown-linux/debug/CNIOLinux.build/module.modulemap -Xcc -fmodule-map-file=/tmp/crypto/.build/checkouts/swift-nio-zlib-support.git-3041174887584855254/module.modulemap -Xcc -fmodule-map-file=/tmp/crypto/.build/x86_64-unknown-linux/debug/CCryptoOpenSSL.build/module.modulemap -Xcc -fmodule-map-file=/tmp/crypto/Sources/CBcrypt/include/module.modulemap -Xcc -fmodule-map-file=/tmp/crypto/Sources/CBase32/include/module.modulemap -Xcc -fmodule-map-file=/tmp/crypto/.build/checkouts/swift-nio-ssl-support.git--619593487001172901/module.modulemap -parse-as-library -module-name Crypto -o /tmp/crypto/.build/x86_64-unknown-linux/debug/Crypto.build/RSA/RSAKey.swift.o -o /tmp/crypto/.build/x86_64-unknown-linux/debug/Crypto.build/RSA/RSAPadding.swift.o -o /tmp/crypto/.build/x86_64-unknown-linux/debug/Crypto.build/Random/CryptoRandom.swift.o -o /tmp/crypto/.build/x86_64-unknown-linux/debug/Crypto.build/Utilities/Base32.swift.o
1. While emitting IR SIL function "@$S6Crypto6RSAKeyV10components1n1e1dACSS_S2SSgtKFZ".
for 'components(n:e:d:)' at /tmp/crypto/Sources/Crypto/RSA/RSAKey.swift:67:12
2. /tmp/crypto/Sources/CCryptoOpenSSL/include/c_crypto_openssl.h:27:5: Generating code for declaration 'RSA_set0_key'
<unknown>:0: error: unable to execute command: Aborted
<unknown>:0: error: compile command failed due to signal 6 (use -v to see invocation)
error: terminated(1): /usr/bin/swift-build-tool -f /tmp/crypto/.build/debug.yaml main output:
-1- johannes:/tmp/crypto (master)
$ docker run -it --rm swift
root@7944f805bac9:/# swift -version
Swift version 4.2 (swift-4.2-RELEASE)
Target: x86_64-unknown-linux-gnu
root@7944f805bac9:/# exit
so as soon as we look at any member of an RSA *
it crashes. This code works just fine
27 static inline int RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d) {
28 //void *x = ((RSA*)r)->n;
29 memset(r, 0, sizeof(RSA));
30 return 0;
31 }
but uncommenting line 28 crashes clang. The real code is in Sources/CCryptoOpenSSL/include/c_crypto_openssl.h
. The functions should all be static inline
or only declared there and implemented in a C file but that's not the actual issue here.
ok, so tannernelson (JIRA User) found what's needed: By only declaring the functions in the header files and putting the actual implementations in .c
files this can be worked around.
Just making them static inline
didn't fix it. So my random guess is that this is only a ClangImporter issue and not a clang issue per se. By putting the implementation into separate C files (that get compiled with clang
), the ClangImporter only sees the function prototype. So the ClangImporter never sees anything 'looking into' the RSA
and we're all happy 🙂.
Still, this should be fixed.
Environment
Swift 4.2 release. Ubuntu 16.04Additional Detail from JIRA
| | | |------------------|-----------------| |Votes | 3 | |Component/s | Compiler | |Labels | Bug, ClangImporter, CompilerCrash | |Assignee | None | |Priority | Medium | md5: b5264cf2d8e59d1efb118c26dfc2003bIssue Description:
Git repo: https://github.com/vapor/crypto
Commit hash: 13e0acacb5bdd27f0031930854798254f2156060
Run: swift build
See: https://github.com/vapor/crypto/pull/75#issuecomment-424280884