On Tuesday 08 February 2022 11:22:12 Martin Storsjö wrote:
> On Tue, 8 Feb 2022, LIU Hao wrote:
> 
> > 在 2/8/22 16:33, Martin Storsjö 写道:
> > > On Sun, 6 Feb 2022, Pali Rohár wrote:
> > > 
> > > > Mark _vscprintf() and _scprintf() functions with attribute pure as their
> > > > return value depends only on passed arguments.
> > > > 
> > > > In function __ms_vsnprintf() check only for n==0 and move
> > > > _vscprintf() call
> > > > at the end of function. This allows LTO to optimize out _vscprintf() 
> > > > call
> > > > from __ms_vsnprintf() function if caller of snprintf() or vsnprintf() 
> > > > does
> > > > not use return value.
> > > > 
> > > > It works because _vscprintf() is direct return value of __ms_vsnprintf()
> > > > and function marked as pure is automatically optimized out if its return
> > > > value is not used.
> > > > ---
> > > > mingw-w64-crt/stdio/vsnprintf.c | 10 +++++-----
> > > > mingw-w64-headers/crt/stdio.h   |  3 +++
> > > > 2 files changed, 8 insertions(+), 5 deletions(-)
> > > 
> > > This looks ok to me, so I pushed it.
> > > 
> > > 
> > 
> > Please use `__pure__` instead of `pure` in standard library headers. The
> > latter is subject to user-defined macros.
> 
> Oh, right, sorry for missing that bit.

Oh, do you need to send a fixup patch for this?

> > Although I have no objection against this patch, I do wonder whether it
> > is practical to build the CRT with LTO. There are some symbols (e.g. the
> > TLS directory) that mean to 'be there unconditionally', which might be
> > stripped by LTO and cause undefined references (I thought I had seen
> > this before, not sure).
> 
> Yeah, it's probably a cornercase in itself, but the patch seemed harmless
> anyway.

Well, I have tried to compile just a simple executable application with
"snprintf" call which do not check return value of snprintf function and
with LTO built of CRT was _vscprintf call fully eliminated without any
undefined reference issues and application worked correctly.


_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to