On Wed, 2 Sep 2026, Zhongteng Gui wrote:
Hi, I'd like to propose adding more testcases for mingw-w64-crt with different CFLAGS. I'm trying to enable `-O2`, `_FORTIFY_SOURCE=2` and `-fstack-protector-strong` when building mingw-w64-crt itself for MSYS2.
Generally, adding testing for more build configurations may be useful - I've also considered doing that for building mingw-w64-crt with -ffunction-sections -fdata-sections. (If doing that is entirely safe, we could even consider defaulting to building with them enabled. But on the other hand, if we have things split up enough into separate files, it shouldn't really gain us anything either.)
Some regression (e.g. `-fstack-protector-strong` linking issue) is actually downstream (Rust) bug. However, some regression (e.g. `_FORTIFY_SOURCE=2` causes infinite loop in `__memcpy_chk` for Clang) is likely a bug in mingw-w64 itself.
I'm not sure if I think it is reasonable to build mingw-w64-crt with _FORTIFY_SOURCE=2, that can certainly lead to bugs like that.
Many optimizations can transform user C code into a call for such a system function, which causes infinite recursion, when you're actually trying to implement that function. This is e.g. why we build mingw-w64-crt with -fno-builtin.
Currently, GitHub CI only enables `-Werror`. And it's not clear whether `-O2` is enabled (there's some logic in `configure` that defaults to `-g -O2` or `-O2`, but I'm not sure whether they're effective).
I'm quite sure that it is built with -O2; we do set CPPFLAGS, but as we don't set CFLAGS, it should use the default values of "-g -O2".
BTW, I understand that some flags that are useful for downstream may not be applicable when compiling mingw-w64-crt itself (I suspect __USE_MINGW_ANSI_STDIO is one of these, and I'm not sure whether _FORTIFY_SOURCE is also one of these).
__USE_MINGW_ANSI_STDIO shouldn't be relevant here, no; we hardcode building with -D__USE_MINGW_ANSI_STDIO=0 in mingw-w64-crt/Makefile.am. If you try to inject another version of this define, it depends on whether it gets applied before or after our default.
In general, I'd say that most such user preferences aren't really relevant for mingw-w64-crt - which is meant to be built in very specific ways.
But testing with e.g. -ffunction-sections -fdata-sections (and -Wl,--gc-sections) could be relevant.
// Martin _______________________________________________ Mingw-w64-public mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
