在 2020/5/6 18:48, Martin Storsjö 写道: > > This is generally the risk of this kind of commit - regardless of how > right/wrong the status quo is, there's _a lot_ of code that relies on it > behaving in a specific way, and changing that will certainly run into > minor issues in a lot of places. > As it was I that committed the patch - I thought it should be safe, because 0) G++ has been hardcoding `__USE_MINGW_ANSI_STDIO` for years (see 'bits/os_defines.h'), and 1) MSYS2 has it too (see 'makepkg_mingw64.conf' which affects all packages in C or C++). It was however an oversight that during bootstrapping GCC doesn't use the CPPFLAGS from the build environment, which I think is unusual, as all MSYS2 packages have `__USE_MINGW_ANSI_STDIO`. The hard-coded (?) `printf` attribute expects the MS behavior, which shouldn't be the case, if we were building something that calls functions from libgomp.h directly, despite the fact that it isn't a public header. >> 2. Make GCC treat `format(printf)` as `format(gnu_printf)` if C11 or >> C++11 is selected, or > > I'm not very keen on that. The compiler should ideally not assume to > much about what the platform headers do in detail, because it limits > what we can change. (If we'd make that change in the compiler, and then > for another reason end up reverting the commit, we'd have the same issue > in reverse.) > Yes I agree. It's pretty bad that the C (but not C++) standard allows users to declare standard functions without including appropriate headers. If someone declare `printf` themselves then they will end up in calling it from MSVCRT, even in C11 mode. >> 3. Replace `format(printf)` with `format(gnu_printf)` in libgomp source. > > This also kind of hardcodes too much; libgomp in general can't and > shouldn't assume too much about which format kind it uses, unless > libgomp itself hardcodes __USE_MINGW_ANSI_STDIO. Also, the whole > gnu_printf format is something that only GCC supports, not Clang, but I > guess libgomp is rather GCC specific anyway. > As long as 'libgomp.h' is a private header, it might be fine to change or remove this attribute. > However we do have a define that should expand to the right thing - just > like inttypes.h PRIu64 follows __USE_MINGW_ANSI_STDIO - we have > __MINGW_PRINTF_FORMAT. > > So something like this should work: > > #ifdef __MINGW32__ > #define PRINTF_FORMAT __MINGW_PRINTF_FORMAT > #else > #define PRINTF_FORMAT printf > #endif > > __attribute__((format(PRINTF_FORMAT))) > > Not very pretty, but should work without hardcoding any assumptions > about which format actually is used. > So we end up in patching libgomp source anyway. I will try this tomorrow. -- Best regards, LH_Mouse
Attachment:
signature.asc
Description: OpenPGP digital signature