On Fri, 21 Jan 2022, LIU Hao wrote:

This seems easy to reproduce in MSYS2:

 ```
 lh_mouse@lhmouse-pc ~/Desktop $ cat conftest.c
 extern int snprintf(char*, unsigned, const char*, ...);

 int main(void)
 {
   char temp[42];
   snprintf(temp, 10, "");
 }
 lh_mouse@lhmouse-pc ~/Desktop $ gcc conftest.c
C:/MSYS2/mingw32/lib/gcc/i686-w64-mingw32/11.2.1/../../../../i686-w64-mingw32/bin/ld.exe: C:/MSYS2/mingw32/lib/gcc/i686-w64-mingw32/11.2.1/../../../../i686-w64-mingw32/lib/../lib/libmsvcrt.a(lib32_libmsvcrt_extra_a-_vscprintf.o): in function `emu_vscprintf':

D:/lh_mouse/GitHub/MINGW-packages/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/stdio/_vscprintf.c:49: undefined reference to `_set_errno' C:/MSYS2/mingw32/lib/gcc/i686-w64-mingw32/11.2.1/../../../../i686-w64-mingw32/bin/ld.exe: D:/lh_mouse/GitHub/MINGW-packages/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/stdio/_vscprintf.c:23: undefined reference to `_set_errno'
 collect2.exe: error: ld returned 1 exit status
 lh_mouse@lhmouse-pc ~/Desktop $
 ```

Thanks, reproduced it now. (And now I realized that I should have built GCC itself on top of it, not just build a cross GCC targeting it, to exhibit the issue.)

It's yet another case of layering issues with all the support functions that are scattered across libmingwex.a and libmsvcrt.a. In the current invocation, we already have a series of "-lmingwex -lmsvcrt -lmingwex -lmsvcrt", but even in the last invocation of -lmsvcrt in this case, we end up needing more symbols from -lmingwex. This hasn't been an issue for me, when testing with lld, as lld always resolves undefined symbols in earlier libraries too, contrary to ld.bfd.

In this case, we could move _set_errno from libmingwex.a to libmsvcrt.a, as all newer numbered versions of msvcr*.dll, and UCRT, all provide _set_errno already. I'll send a patch.

But longer term, I wonder if it wouldn't be best if we'd just pass --start-group --end-group around the system libraries that GCC links against, to resolve this kind of circular dependencies, as these do crop up every now and then.

// Martin



_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to