Merge pull request #4979 from ripopov/fix-tests-mingw-w64

tests: fix link failure and stack overflow on Mingw w64