Merge pull request #372 from dgarske/mingwfixes

MinGW fixes
This commit is contained in:
toddouska
2016-04-18 12:50:13 -07:00
18 changed files with 164 additions and 46 deletions

View File

@@ -2638,10 +2638,18 @@ fi
LIB_SOCKET_NSL LIB_SOCKET_NSL
AX_HARDEN_CC_COMPILER_FLAGS AX_HARDEN_CC_COMPILER_FLAGS
# link to ws2_32 if on mingw # if mingw then link to ws2_32 for sockets
case $host_os in case $host_os in
*mingw32) mingw*)
LDFLAGS="$LDFLAGS -lws2_32" ;; LDFLAGS="$LDFLAGS -lws2_32"
if test "$enable_shared" = "yes"
then
AC_DEFINE([WOLFSSL_DLL], [1], [Use __declspec(dllexport) when building library])
if test "$enable_static" = "yes"
then
MINGW_LIB_WARNING="yes"
fi
fi ;;
esac esac
# add user C_EXTRA_FLAGS back # add user C_EXTRA_FLAGS back
@@ -2717,7 +2725,7 @@ for option in $OPTION_FLAGS; do
noequalsign=`echo $defonly | sed 's/=/ /'` noequalsign=`echo $defonly | sed 's/=/ /'`
if test "$noequalsign" = "NDEBUG" || test "$noequalsign" = "DEBUG" if test "$noequalsign" = "NDEBUG" || test "$noequalsign" = "DEBUG"
then then
echo "not outputing (N)DEBUG to $OPTION_FILE" echo "not outputting (N)DEBUG to $OPTION_FILE"
continue continue
fi fi
@@ -2767,8 +2775,16 @@ done < $OPTION_FILE
# switch ifdef protection in cyassl/option.h to CYASSL_OPTONS_H, remove bak # switch ifdef protection in cyassl/option.h to CYASSL_OPTONS_H, remove bak
sed -i.bak 's/WOLFSSL_OPTIONS_H/CYASSL_OPTIONS_H/g' cyassl/options.h sed -i.bak 's/WOLFSSL_OPTIONS_H/CYASSL_OPTIONS_H/g' cyassl/options.h
# workaround for mingw sed that may get "Permission denied" trying to preserver permissions
case $host_os in
mingw*)
chmod u+w cyassl/options.h ;;
esac
rm cyassl/options.h.bak rm cyassl/options.h.bak
# output config summary # output config summary
echo "---" echo "---"
echo "Configuration summary for $PACKAGE_NAME version $VERSION" echo "Configuration summary for $PACKAGE_NAME version $VERSION"
@@ -2878,8 +2894,30 @@ echo " * Async Crypto: $ENABLED_ASYNCCRYPT"
echo "" echo ""
echo "---" echo "---"
################################################################################
# Show warnings at bottom so they are noticed # Show warnings at bottom so they are noticed
################################################################################
if test "$ENABLED_ASYNCCRYPT" = "yes" if test "$ENABLED_ASYNCCRYPT" = "yes"
then then
AC_MSG_WARN([Make sure real async files are loaded. Contact wolfSSL for details on using the asynccrypt option.]) AC_MSG_WARN([Make sure real async files are loaded. Contact wolfSSL for details on using the asynccrypt option.])
fi fi
# MinGW static vs shared library
# Reference URL from libtool for MinGW is located at
# http://www.gnu.org/software/libtool/manual/libtool.html#Cygwin-to-MinGW-Cross
# this allows for not even having dllimport/dllexport on functions
# with recent libtools, only requiring it with global variables.
#
# The following warning is displayed here because if not using "contemporary GNU
# tools" there is the possibility of export/import issues.
# wolfSSL uses __declspec(dllexport) and "contemporary GNU tools" handle the
# case where both static and shared libraries are built.
#
# More can be found about the MinGW linker at
# https://sourceware.org/binutils/docs/ld/WIN32.html
if test "$MINGW_LIB_WARNING" = "yes"
then
AC_MSG_WARN([Building with shared and static library at the same time on this system may cause export/import problems when using non contemporary GNU tools.])
fi

View File

@@ -84,7 +84,7 @@ THREAD_RETURN CYASSL_THREAD echoserver_test(void* args)
int outCreated = 0; int outCreated = 0;
int shutDown = 0; int shutDown = 0;
int useAnyAddr = 0; int useAnyAddr = 0;
word16 port = wolfSSLPort; word16 port;
int argc = ((func_args*)args)->argc; int argc = ((func_args*)args)->argc;
char** argv = ((func_args*)args)->argv; char** argv = ((func_args*)args)->argv;
@@ -114,14 +114,21 @@ THREAD_RETURN CYASSL_THREAD echoserver_test(void* args)
doPSK = 1; doPSK = 1;
#endif #endif
#if defined(NO_MAIN_DRIVER) && !defined(USE_WINDOWS_API) && \ #if defined(USE_WINDOWS_API)
!defined(CYASSL_SNIFFER) && !defined(WOLFSSL_MDK_SHELL) && \ /* Generate random port for testing */
!defined(CYASSL_TIRTOS) port = GetRandomPort();
#elif defined(NO_MAIN_DRIVER) && !defined(CYASSL_SNIFFER) && \
!defined(WOLFSSL_MDK_SHELL) && !defined(CYASSL_TIRTOS)
/* Let tcp_listen assign port */
port = 0; port = 0;
#endif #else
#if defined(USE_ANY_ADDR) /* Use default port */
port = wolfSSLPort;
#endif
#if defined(USE_ANY_ADDR)
useAnyAddr = 1; useAnyAddr = 1;
#endif #endif
#ifdef CYASSL_TIRTOS #ifdef CYASSL_TIRTOS
fdOpenSession(Task_self()); fdOpenSession(Task_self());

View File

@@ -398,10 +398,6 @@ THREAD_RETURN CYASSL_THREAD server_test(void* args)
case 'p' : case 'p' :
port = (word16)atoi(myoptarg); port = (word16)atoi(myoptarg);
#if defined(USE_WINDOWS_API)
if (port == 0)
err_sys("port number cannot be 0");
#endif
break; break;
case 'w' : case 'w' :
@@ -730,6 +726,13 @@ THREAD_RETURN CYASSL_THREAD server_test(void* args)
err_sys("UseSNI failed"); err_sys("UseSNI failed");
#endif #endif
#ifdef USE_WINDOWS_API
if (port == 0) {
/* Generate random port for testing */
port = GetRandomPort();
}
#endif /* USE_WINDOWS_API */
while (1) { while (1) {
/* allow resume option */ /* allow resume option */
if(resumeCount > 1) { if(resumeCount > 1) {

View File

@@ -1,5 +1,5 @@
# visibility.m4 serial 4 (gettext-0.18.2) # visibility.m4 serial 5 (gettext-0.18.2)
dnl Copyright (C) 2005, 2008, 2010-2011 Free Software Foundation, Inc. dnl Copyright (C) 2005, 2008, 2010-2014 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it, dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved. dnl with or without modifications, as long as this notice is preserved.
@@ -12,7 +12,7 @@ dnl __attribute__((__visibility__("hidden"))) and
dnl __attribute__((__visibility__("default"))). dnl __attribute__((__visibility__("default"))).
dnl Does *not* test for __visibility__("protected") - which has tricky dnl Does *not* test for __visibility__("protected") - which has tricky
dnl semantics (see the 'vismain' test in glibc) and does not exist e.g. on dnl semantics (see the 'vismain' test in glibc) and does not exist e.g. on
dnl MacOS X. dnl Mac OS X.
dnl Does *not* test for __visibility__("internal") - which has processor dnl Does *not* test for __visibility__("internal") - which has processor
dnl dependent semantics. dnl dependent semantics.
dnl Does *not* test for #pragma GCC visibility push(hidden) - which is dnl Does *not* test for #pragma GCC visibility push(hidden) - which is
@@ -58,7 +58,7 @@ AC_DEFUN([gl_VISIBILITY],
extern __attribute__((__visibility__("default"))) int exportedvar; extern __attribute__((__visibility__("default"))) int exportedvar;
extern __attribute__((__visibility__("hidden"))) int hiddenfunc (void); extern __attribute__((__visibility__("hidden"))) int hiddenfunc (void);
extern __attribute__((__visibility__("default"))) int exportedfunc (void); extern __attribute__((__visibility__("default"))) int exportedfunc (void);
void dummyfunc (void) {} int hiddenfunc (void) { return 0; }
]], ]],
[[]])], [[]])],
[gl_cv_cc_visibility=yes], [gl_cv_cc_visibility=yes],

View File

@@ -16,9 +16,9 @@ else
fi fi
# is our desired server there? # is our desired server there?
ping -c 2 $server ./scripts/ping.test $server 2
RESULT=$? RESULT=$?
[ $RESULT -ne 0 ] && echo -e "\n\nCouldn't find $server, skipping" && exit 0 [ $RESULT -ne 0 ] && exit 0
# client test against the server # client test against the server
./examples/client/client -X -C -h $server -p 443 -g -A $ca ./examples/client/client -X -C -h $server -p 443 -g -A $ca

View File

@@ -7,9 +7,9 @@ server=www.google.com
[ ! -x ./examples/client/client ] && echo -e "\n\nClient doesn't exist" && exit 1 [ ! -x ./examples/client/client ] && echo -e "\n\nClient doesn't exist" && exit 1
# is our desired server there? # is our desired server there?
ping -c 2 $server ./scripts/ping.test $server 2
RESULT=$? RESULT=$?
[ $RESULT -ne 0 ] && echo -e "\n\nCouldn't find $server, skipping" && exit 0 [ $RESULT -ne 0 ] && exit 0
# client test against the server # client test against the server
./examples/client/client -X -C -h $server -p 443 -g -d ./examples/client/client -X -C -h $server -p 443 -g -d

View File

@@ -57,6 +57,8 @@ dist_noinst_SCRIPTS+= scripts/google.test
endif endif
endif endif
EXTRA_DIST += scripts/testsuite.pcap EXTRA_DIST += scripts/testsuite.pcap \
scripts/ping.test
# leave openssl.test as extra until non bash works # leave openssl.test as extra until non bash works
EXTRA_DIST += scripts/openssl.test EXTRA_DIST += scripts/openssl.test

View File

@@ -10,9 +10,7 @@ ca=certs/external/ca-verisign-g5.pem
[ ! -x ./examples/client/client ] && echo -e "\n\nClient doesn't exist" && exit 1 [ ! -x ./examples/client/client ] && echo -e "\n\nClient doesn't exist" && exit 1
# is our desired server there? - login.live.com doesn't answers PING # is our desired server there? - login.live.com doesn't answers PING
# ping -c 2 $server #./scripts/ping.test $server 2
# RESULT=$?
# [ $RESULT -ne 0 ] && echo -e "\n\nCouldn't find $server, skipping" && exit 0
# client test against the server # client test against the server
./examples/client/client -X -C -h $server -p 443 -A $ca -g -W 1 ./examples/client/client -X -C -h $server -p 443 -A $ca -g -W 1

View File

@@ -8,9 +8,9 @@ ca=certs/external/ca-globalsign-root-r2.pem
[ ! -x ./examples/client/client ] && echo -e "\n\nClient doesn't exist" && exit 1 [ ! -x ./examples/client/client ] && echo -e "\n\nClient doesn't exist" && exit 1
# is our desired server there? # is our desired server there?
ping -c 2 $server ./scripts/ping.test $server 2
RESULT=$? RESULT=$?
[ $RESULT -ne 0 ] && echo -e "\n\nCouldn't find $server, skipping" && exit 0 [ $RESULT -ne 0 ] && exit 0
# client test against the server # client test against the server
./examples/client/client -X -C -h $server -p 443 -A $ca -g -o ./examples/client/client -X -C -h $server -p 443 -A $ca -g -o

29
scripts/ping.test Executable file
View File

@@ -0,0 +1,29 @@
#!/bin/sh
# ping.test
# defaults
server=www.wolfssl.com
tries=2
# populate args
if [ "$#" -gt 1 ]; then
tries=$2
fi
if [ "$#" -gt 0 ]; then
server=$1
fi
# determine os
OS="`uname`"
case $OS in
MINGW* | MSYS*) PINGSW=-n ;;
*) PINGSW=-c ;;
esac
# is our desired server there?
ping $PINGSW $tries $server
RESULT=$?
[ $RESULT -ne 0 ] && echo -e "\n\nCouldn't find $server, skipping" && exit 1
exit 0

View File

@@ -58,7 +58,13 @@ static const char* passed = "passed";
static const char* failed = "failed"; static const char* failed = "failed";
#if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS)
static const char* bogusFile = "/dev/null"; static const char* bogusFile =
#ifdef _WIN32
"NUL"
#else
"/dev/null"
#endif
;
#endif #endif
/*----------------------------------------------------------------------------* /*----------------------------------------------------------------------------*
@@ -485,7 +491,7 @@ static THREAD_RETURN WOLFSSL_THREAD test_server_nofail(void* args)
{ {
SOCKET_T sockfd = 0; SOCKET_T sockfd = 0;
SOCKET_T clientfd = 0; SOCKET_T clientfd = 0;
word16 port = wolfSSLPort; word16 port;
WOLFSSL_METHOD* method = 0; WOLFSSL_METHOD* method = 0;
WOLFSSL_CTX* ctx = 0; WOLFSSL_CTX* ctx = 0;
@@ -503,10 +509,16 @@ static THREAD_RETURN WOLFSSL_THREAD test_server_nofail(void* args)
method = wolfSSLv23_server_method(); method = wolfSSLv23_server_method();
ctx = wolfSSL_CTX_new(method); ctx = wolfSSL_CTX_new(method);
#if defined(NO_MAIN_DRIVER) && !defined(USE_WINDOWS_API) && \ #if defined(USE_WINDOWS_API)
!defined(WOLFSSL_SNIFFER) && !defined(WOLFSSL_MDK_SHELL) && \ /* Generate random port for testing */
!defined(WOLFSSL_TIRTOS) port = GetRandomPort();
#elif defined(NO_MAIN_DRIVER) && !defined(WOLFSSL_SNIFFER) && \
!defined(WOLFSSL_MDK_SHELL) && !defined(WOLFSSL_TIRTOS)
/* Let tcp_listen assign port */
port = 0; port = 0;
#else
/* Use default port */
port = wolfSSLPort;
#endif #endif
wolfSSL_CTX_set_verify(ctx, wolfSSL_CTX_set_verify(ctx,
@@ -704,7 +716,7 @@ static THREAD_RETURN WOLFSSL_THREAD run_wolfssl_server(void* args)
WOLFSSL* ssl = NULL; WOLFSSL* ssl = NULL;
SOCKET_T sfd = 0; SOCKET_T sfd = 0;
SOCKET_T cfd = 0; SOCKET_T cfd = 0;
word16 port = wolfSSLPort; word16 port;
char msg[] = "I hear you fa shizzle!"; char msg[] = "I hear you fa shizzle!";
int len = (int) XSTRLEN(msg); int len = (int) XSTRLEN(msg);
@@ -716,10 +728,16 @@ static THREAD_RETURN WOLFSSL_THREAD run_wolfssl_server(void* args)
#endif #endif
((func_args*)args)->return_code = TEST_FAIL; ((func_args*)args)->return_code = TEST_FAIL;
#if defined(NO_MAIN_DRIVER) && !defined(USE_WINDOWS_API) && \ #if defined(USE_WINDOWS_API)
!defined(WOLFSSL_SNIFFER) && !defined(WOLFSSL_MDK_SHELL) && \ /* Generate random port for testing */
!defined(WOLFSSL_TIRTOS) port = GetRandomPort();
#elif defined(NO_MAIN_DRIVER) && !defined(WOLFSSL_SNIFFER) && \
!defined(WOLFSSL_MDK_SHELL) && !defined(WOLFSSL_TIRTOS)
/* Let tcp_listen assign port */
port = 0; port = 0;
#else
/* Use default port */
port = wolfSSLPort;
#endif #endif
wolfSSL_CTX_set_verify(ctx, wolfSSL_CTX_set_verify(ctx,

View File

@@ -152,6 +152,7 @@ void join_thread(THREAD_TYPE thread)
assert(res == WAIT_OBJECT_0); assert(res == WAIT_OBJECT_0);
res = CloseHandle((HANDLE)thread); res = CloseHandle((HANDLE)thread);
assert(res); assert(res);
(void)res; /* Suppress un-used variable warning */
#endif #endif
} }

View File

@@ -332,6 +332,7 @@ void join_thread(THREAD_TYPE thread)
assert(res == WAIT_OBJECT_0); assert(res == WAIT_OBJECT_0);
res = CloseHandle((HANDLE)thread); res = CloseHandle((HANDLE)thread);
assert(res); assert(res);
(void)res; /* Suppress un-used variable warning */
#endif #endif
} }

View File

@@ -7093,7 +7093,7 @@ static int WriteCertBody(DerCert* der, byte* buffer)
if (der->extensionsSz) { if (der->extensionsSz) {
/* extensions */ /* extensions */
XMEMCPY(buffer + idx, der->extensions, min(der->extensionsSz, XMEMCPY(buffer + idx, der->extensions, min(der->extensionsSz,
sizeof(der->extensions))); (int)sizeof(der->extensions)));
idx += der->extensionsSz; idx += der->extensionsSz;
} }

View File

@@ -347,7 +347,7 @@ int wc_DsaSign(const byte* digest, byte* out, DsaKey* key, WC_RNG* rng)
int ret, sz; int ret, sz;
byte buffer[DSA_HALF_SIZE]; byte buffer[DSA_HALF_SIZE];
sz = min(sizeof(buffer), mp_unsigned_bin_size(&key->q)); sz = min((int)sizeof(buffer), mp_unsigned_bin_size(&key->q));
/* generate k */ /* generate k */
ret = wc_RNG_GenerateBlock(rng, buffer, sz); ret = wc_RNG_GenerateBlock(rng, buffer, sz);

View File

@@ -1925,4 +1925,18 @@ static INLINE const char* mymktemp(char *tempfn, int len, int num)
} }
#endif #endif
static INLINE word16 GetRandomPort(void)
{
word16 port = 0;
/* Generate random port for testing */
WC_RNG rng;
if (wc_InitRng(&rng) == 0) {
wc_RNG_GenerateBlock(&rng, (byte*)&port, sizeof(port));
port |= 0xC000; /* Make sure its in the 49152 - 65535 range */
wc_FreeRng(&rng);
}
return port;
}
#endif /* wolfSSL_TEST_H */ #endif /* wolfSSL_TEST_H */

View File

@@ -223,6 +223,13 @@
#define XSTRTOK strtok_r #define XSTRTOK strtok_r
#else #else
#define XSTRTOK strtok_s #define XSTRTOK strtok_s
#ifdef __MINGW32__
#pragma GCC diagnostic push
#pragma GCC diagnostic warning "-Wcpp"
#warning "MinGW may be missing strtok_s. You can find a public domain implementation here: https://github.com/fletcher/MultiMarkdown-4/blob/master/strtok.c"
#pragma GCC diagnostic pop
#endif
#endif #endif
#endif #endif
#endif #endif

View File

@@ -46,8 +46,8 @@
#elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550) #elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550)
#define WOLFSSL_API __global #define WOLFSSL_API __global
#define WOLFSSL_LOCAL __hidden #define WOLFSSL_LOCAL __hidden
#elif defined(_MSC_VER) #elif defined(_MSC_VER) || defined(__MINGW32__)
#ifdef WOLFSSL_DLL #if defined(WOLFSSL_DLL)
#define WOLFSSL_API __declspec(dllexport) #define WOLFSSL_API __declspec(dllexport)
#else #else
#define WOLFSSL_API #define WOLFSSL_API
@@ -58,8 +58,8 @@
#define WOLFSSL_LOCAL #define WOLFSSL_LOCAL
#endif /* HAVE_VISIBILITY */ #endif /* HAVE_VISIBILITY */
#else /* BUILDING_WOLFSSL */ #else /* BUILDING_WOLFSSL */
#if defined(_MSC_VER) #if defined(_MSC_VER) || defined(__MINGW32__)
#ifdef WOLFSSL_DLL #if defined(WOLFSSL_DLL)
#define WOLFSSL_API __declspec(dllimport) #define WOLFSSL_API __declspec(dllimport)
#else #else
#define WOLFSSL_API #define WOLFSSL_API