Backport some commits from mingw-w64 trunk