public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Liu Hao <lh_mouse@126.com>
To: "Martin Storsjö" <martin@martin.st>,
	"mingw-w64-public@lists.sourceforge.net"
	<mingw-w64-public@lists.sourceforge.net>
Cc: "gcc-help@gcc.gnu.org" <gcc-help@gcc.gnu.org>
Subject: Re: [Mingw-w64-public] mingw-w64 and __attribute__((format(printf))) issue
Date: Wed, 6 May 2020 20:45:20 +0800	[thread overview]
Message-ID: <11517505-9ad5-14b4-9101-6011a557f52d@126.com> (raw)
In-Reply-To: <alpine.DEB.2.20.2005061256580.23006@cone.martin.st>


[-- Attachment #1.1: Type: text/plain, Size: 2811 bytes --]

在 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 #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2020-05-06 12:45 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-06  5:36 Liu Hao
2020-05-06 10:48 ` [Mingw-w64-public] " Martin Storsjö
2020-05-06 12:45   ` Liu Hao [this message]
2020-05-07  4:09   ` Liu Hao
2020-05-10  4:27 ` JonY
2020-05-10  9:03   ` Liu Hao
2020-05-12 11:14     ` JonY
2020-05-12 12:02       ` Jakub Jelinek
2020-05-12 13:15         ` Liu Hao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=11517505-9ad5-14b4-9101-6011a557f52d@126.com \
    --to=lh_mouse@126.com \
    --cc=gcc-help@gcc.gnu.org \
    --cc=martin@martin.st \
    --cc=mingw-w64-public@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).