Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mingw-w64-qt5-base] undefined reference to `_imp__CertCreateCertificateContext@12 #41

Closed
xantares opened this issue Sep 14, 2017 · 20 comments

Comments

@xantares
Copy link
Contributor

I just tried to rebuild mingw-w64-qt5-base from scratch after the update to mingw-gcc 7.2,
and got undefined symbols like CertCreateCertificateContext when linking qt5Network.dll:

It's weird as this should be in libcrypt32, and -lcrypt32 is passed

$ grep -nr CertCreateCertificateContext /usr/i686-w64-mingw32/lib/
Binary file /usr/i686-w64-mingw32/lib/libcrypt32.a matches

Here're the full error:

i686-w64-mingw32-g++ -c -include .pch/release/qt_pch.h -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions --param=ssp-buffer-size=4 -fno-keep-inline-dllexport -fpch-preprocess -msse2 -mstackrealign -mfpmath=sse -O2 -g -std=c++1z -fno-exceptions -Wall -Wextra -Wvla -Wdate-time -Wshift-overflow=2 -Wduplicated-cond -DUNICODE -DQT_NO_USING_NAMESPACE -DQT_NO_FOREACH -DWINVER=0x0600 -D_WIN32_WINNT=0x0600 -DQT_USE_SYSTEM_PROXIES -DQT_NO_NARROWING_CONVERSIONS_IN_CONNECT -DQT_BUILD_NETWORK_LIB -DQT_BUILDING_QT -D_CRT_SECURE_NO_WARNINGS -D_USE_MATH_DEFINES -DQT_NO_CAST_TO_ASCII -DQT_ASCII_CAST_WARNINGS -DQT_MOC_COMPAT -DQT_USE_QSTRINGBUILDER -DQT_DEPRECATED_WARNINGS -DQT_DISABLE_DEPRECATED_BEFORE=0x040800 -DQT_NO_EXCEPTIONS -DQT_NO_DEBUG -DQT_CORE_LIB -I/home/xantares/projects/aur-scripts/yaourt-tmp-root/aur-mingw-w64-qt5-base/src/qtbase-opensource-src-5.9.1/src/network -I. -I/home/xantares/projects/aur-scripts/yaourt-tmp-root/aur-mingw-w64-qt5-base/src/qtbase-opensource-src-5.9.1/src/network/kernel -I/home/xantares/projects/aur-scripts/yaourt-tmp-root/aur-mingw-w64-qt5-base/src/qtbase-opensource-src-5.9.1/include -I/home/xantares/projects/aur-scripts/yaourt-tmp-root/aur-mingw-w64-qt5-base/src/qtbase-opensource-src-5.9.1/include/QtNetwork -I../../include -I../../include/QtNetwork -I/home/xantares/projects/aur-scripts/yaourt-tmp-root/aur-mingw-w64-qt5-base/src/qtbase-opensource-src-5.9.1/include/QtNetwork/5.9.1 -I/home/xantares/projects/aur-scripts/yaourt-tmp-root/aur-mingw-w64-qt5-base/src/qtbase-opensource-src-5.9.1/include/QtNetwork/5.9.1/QtNetwork -I../../include/QtNetwork/5.9.1 -I../../include/QtNetwork/5.9.1/QtNetwork -Itmp -I/usr/i686-w64-mingw32/include/openssl-1.0 -I/home/xantares/projects/aur-scripts/yaourt-tmp-root/aur-mingw-w64-qt5-base/src/qtbase-opensource-src-5.9.1/include/QtCore/5.9.1 -I/home/xantares/projects/aur-scripts/yaourt-tmp-root/aur-mingw-w64-qt5-base/src/qtbase-opensource-src-5.9.1/include/QtCore/5.9.1/QtCore -I../../include/QtCore/5.9.1 -I../../include/QtCore/5.9.1/QtCore -I/home/xantares/projects/aur-scripts/yaourt-tmp-root/aur-mingw-w64-qt5-base/src/qtbase-opensource-src-5.9.1/include/QtCore -I../../include/QtCore -I.moc/release -I/usr/i686-w64-mingw32/include/freetype2 -I/usr/i686-w64-mingw32/include -I/usr/i686-w64-mingw32/include/harfbuzz -I/usr/i686-w64-mingw32/include/glib-2.0 -I/usr/i686-w64-mingw32/lib/glib-2.0/include -I/usr/i686-w64-mingw32/include -I/usr/i686-w64-mingw32/include/dbus-1.0 -I/usr/i686-w64-mingw32/lib/dbus-1.0/include -I/usr/i686-w64-mingw32/include/mariadb -I/home/xantares/projects/aur-scripts/yaourt-tmp-root/aur-mingw-w64-qt5-base/src/qtbase-opensource-src-5.9.1/mkspecs/mingw-w64-g++  -o .obj/release/qftp.o /home/xantares/projects/aur-scripts/yaourt-tmp-root/aur-mingw-w64-qt5-base/src/qtbase-opensource-src-5.9.1/src/network/access/qftp.cpp
i686-w64-mingw32-g++ -g -shared -Wl,-subsystem,windows -Wl,--out-implib,/home/xantares/projects/aur-scripts/yaourt-tmp-root/aur-mingw-w64-qt5-base/src/build-i686-w64-mingw32/lib/libQt5Network.dll.a -o ../../lib/Qt5Network.dll object_script.Qt5Network.Release  -lws2_32 -lcrypt32 -ldnsapi -L/home/xantares/projects/aur-scripts/yaourt-tmp-root/aur-mingw-w64-qt5-base/src/build-i686-w64-mingw32/lib /home/xantares/projects/aur-scripts/yaourt-tmp-root/aur-mingw-w64-qt5-base/src/build-i686-w64-mingw32/lib/libQt5Core.dll.a -ldnsapi -liphlpapi -ladvapi32 -lcrypt32 -lz
./.obj/release/qsslsocket_openssl.o: In function `ZN21QWindowsCaRootFetcher5startEv':
/home/xantares/projects/aur-scripts/yaourt-tmp-root/aur-mingw-w64-qt5-base/src/qtbase-opensource-src-5.9.1/src/network/ssl/qsslsocket_openssl.cpp:1390: undefined reference to `_imp__CertCreateCertificateContext@12'
/home/xantares/projects/aur-scripts/yaourt-tmp-root/aur-mingw-w64-qt5-base/src/qtbase-opensource-src-5.9.1/src/network/ssl/qsslsocket_openssl.cpp:1422: undefined reference to `_imp__CertGetCertificateChain@32'
/home/xantares/projects/aur-scripts/yaourt-tmp-root/aur-mingw-w64-qt5-base/src/qtbase-opensource-src-5.9.1/src/network/ssl/qsslsocket_openssl.cpp:1465: undefined reference to `_imp__CertFreeCertificateChain@4'
collect2: error: ld returned 1 exit status
@xantares xantares changed the title undefined reference to `_imp__CertCreateCertificateContext@12 [mingw-w64-qt5-base] undefined reference to `_imp__CertCreateCertificateContext@12 Sep 14, 2017
@Martchus
Copy link
Owner

Martchus commented Sep 14, 2017

Yes, from the error I would also say -lcrypt32 is missing, but it isn't. Very strange.

Note that the relevant file is not /usr/i686-w64-mingw32/lib/libcrypt32.a since the dynamic version is (usually) preferred unless you use -static. So /usr/i686-w64-mingw32/lib/libcrypt32.dll.a would be relevant.

What happens if you swap the architectures, so that x86_64 is built first? If the x86_64 build succeeds, we at least know that the issue i686/32-bit specific (maybe wrong calling convention assumed).

@Martchus Martchus added the bug label Sep 14, 2017
@xantares
Copy link
Contributor Author

I've got the same error with x86_64-w64-mingw32

@Martchus
Copy link
Owner

Theory falsified. But then I'm currently out of guesses. Maybe I can try to rebuild myself later, but actually I had planned to do some video encoding and maybe finally built qt5-webkit NG on that server...

Another thing you could try is to create a very simple application using eg. CertCreateCertificateContext. Just a single file with some dummy calls. If that doesn't compile as will, you found a bug outside of the scope of my packaging.

@xantares
Copy link
Contributor Author

seems these symbols cannot be found, like
CertCreateCertificateContext

$ i686-w64-mingw32-gcc test_lcypt32.c -lcrypt32
/tmp/ccmX3g9L.o:lcrypt32.c:(.text+0x40): undefined reference to `_imp__CertCreateCertificateContext@12

CertFreeCertificateContext is found though:

#include <windows.h>
#include <stdio.h>
#include <wincrypt.h>

#define MY_ENCODING_TYPE  (PKCS_7_ASN_ENCODING | X509_ASN_ENCODING)

void main()
{
	PCCERT_CONTEXT  pCertContext = NULL; 
	PCCERT_CONTEXT  pDesiredCert = NULL; 
	//------------------------------------------------------------------ 
	//  Create a new certificate from the encoded part of
	//  an available certificate. pDesiredCert is a previously
	//  assigned PCCERT_CONTEXT variable.
	if(pCertContext = CertCreateCertificateContext(
		MY_ENCODING_TYPE,              // The encoding type
		pDesiredCert->pbCertEncoded,   // The encoded data from
									   // the certificate retrieved
		pDesiredCert->cbCertEncoded))  // The length of the encoded data
	{
		printf("A new certificate has been created.\n");
	 
		// Use the certificate context as needed.
		// ...

		// When finished, free the certificate context.
		CertFreeCertificateContext(pCertContext);
	}
	else
	{
		printf("A new certificate could not be created.\n");
		exit(1);
	}
}

@Martchus
Copy link
Owner

It is likely a mingw-w64 bug then. Or your package is just corrupted.

As a workaround you could use the static version of that library. It would be a little bit work to convince qmake to use the static version, but maybe you can just replace the *.dll.a file with the *.a file.

@xantares
Copy link
Contributor Author

there's no dynamic version of libcrypt32, only the libcrypt32.a

@xantares
Copy link
Contributor Author

$ md5sum /usr/i686-w64-mingw32/lib/libcrypt32.a 
976a5477def5644aaea04f5fd28be90d  /usr/i686-w64-mingw32/lib/libcrypt32.a

what's yours ?

@Martchus
Copy link
Owner

Martchus commented Sep 14, 2017

The same. And yes, there is no dynamic ".dll.a" version. I confused it with libcrypto.dll.a, but that's from openssl. But note that libcrypt32.a itself is just an import lib for CRYPT32.dll.

@xantares
Copy link
Contributor Author

xantares commented Sep 14, 2017

CertCreateCertificateContext symbol seems to be there, no difference with CertFreeCertificateContext:

$ i686-w64-mingw32-nm /usr/i686-w64-mingw32/lib/libcrypt32.a |grep CertCreateCertificateContext
00000000 T _CertCreateCertificateContext@12
00000000 I __imp__CertCreateCertificateContext@12
$ i686-w64-mingw32-nm /usr/i686-w64-mingw32/lib/libcrypt32.a |grep CertFreeCertificateContext
00000000 T _CertFreeCertificateContext@4
00000000 I __imp__CertFreeCertificateContext@4

@xantares
Copy link
Contributor Author

I deleted my pacman cache. Do you still have mingw-w64-gcc 7.1 to test that ?

@Martchus
Copy link
Owner

Martchus commented Sep 14, 2017

Sure. In fact the cache on my server is even publicly available: https://martchus.no-ip.biz/repo/arch/official/os/x86_64/mingw-w64-gcc-7.1.1-1-x86_64.pkg.tar.xz

@Martchus
Copy link
Owner

Martchus commented Sep 14, 2017

I mentioned the issue on #mingw-w64 IRC channel. Maybe someone knows. And the concerning package would be mingw-w64-crt. But maybe it is also GCC which is not handling the library provided by mingw-w64-crt correctly. Then it would be a GCC bug.

@xantares
Copy link
Contributor Author

thanks. same with gcc 7.1. I wonder what changed.

@Martchus
Copy link
Owner

Compiling your test application works here. I have a fully upgraded Arch system. However, I use mingw-w64-binutils-symlinks which is a customized version of the official mingw-w64-binutils package and hence still version 2.28. So I would guess that mingw-w64-binutils makes the difference.

The previous version and the version using symlinks (to be able to use mount --bind) are both also in the repo directory on my server.

@xantares
Copy link
Contributor Author

xantares commented Sep 14, 2017

I just tried mingw-w64-binutils 2.28, and mingw-w64-binutils-symlinks 2.28, still the same error

@xantares
Copy link
Contributor Author

xantares commented Sep 14, 2017

I changed mirrors, and cleared the cache, the error is gone, probably a corrupted package.
Thanks for the help.

@xantares
Copy link
Contributor Author

It was a conflict with mingw-w64-gnutls which contains /usr/i686-w64-mingw32/lib/crypt32.dll.a that is linked when provided -lcrypt32. So it miust be removed before building qt5.

@Martchus
Copy link
Owner

Ok, then the actual issue is that mingw-w64-gnutls contains that library. Considering the gnutls sources I would say this library is just meant to be used as mock for the testsuite. So I guess I can simply remove it from the mingw-w64-gnutls package then.

@Martchus Martchus reopened this Sep 18, 2017
@xantares
Copy link
Contributor Author

xantares commented Sep 18, 2017

cool! that or hardwire /usr/arch/lib/libcrypt32.a instead of -lcrypt32 in the qt5 patches

@Martchus
Copy link
Owner

Updated the mingw-w64-gnutls package. The ncrypt library was affected as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants