public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Joe Simmons-Talbott <josimmon@redhat.com>
To: Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>
Cc: Florian Weimer <fweimer@redhat.com>,
	Adhemerval Zanella Netto via Libc-alpha
	<libc-alpha@sourceware.org>
Subject: Re: [PATCH] printf_fp: Get rid of alloca.
Date: Wed, 6 Sep 2023 16:28:47 -0400	[thread overview]
Message-ID: <20230906202847.GK3849957@oak> (raw)
In-Reply-To: <533dbfc5-0ecf-97cb-7d64-4a0a902552fc@linaro.org>

On Wed, Sep 06, 2023 at 01:55:55PM -0300, Adhemerval Zanella Netto wrote:
> 
> 
> On 01/09/23 09:35, Adhemerval Zanella Netto wrote:
> > 
> > 
> > On 01/09/23 09:20, Florian Weimer wrote:
> >> * Adhemerval Zanella Netto via Libc-alpha:
> >>
> >>> The maximum size of frac/tmp/scale is bound by the largest size of floating
> >>> supported by the ABI.  The p.exponent will at maximum LDBL_MAX_EXP, so the
> >>> required size will depend of the maximum support floating point support
> >>> (2080 for most architectures, otherwise 160).
> >>>
> >>> Using scratch_buffer will already increase the minimum stack usage for ~3k,
> >>> so I wonder if would be better to just define the maximum mp_limb_t size
> >>> direct on hack_digit_param:
> >>
> >> The issue is that this increases the stack size for functions like
> >> dprintf that might be used in signal handlers.  While it's conditional
> >> and only for floating point formatting, the old approach restricts the
> >> most excess to certain subcases, especially those involving long double.
> >> That's why I left in the alloca when I refactored __printf_fp to avoid
> >> stdio interfaces for internal use.
> > 
> > It already calls malloc in __printf_fp_buffer_1, so this is not fully 
> > AS-signal safe (it is unlikely, but possible).  Another option would to 
> > decompose __printf_fp_buffer_1 and if long double / float128 is use it 
> > routes to another function that allocates a large stack (the default for 
> > double should be ok, about ~680 bytes of extra stack).
> 
> I think we still avoid the pessimization of using one scratch_buffer for
> each temporary variable (~3KB of stack requirement) with some code
> refactoring.  For double we need at maximum ~160 bytes for each
> temporary, so we can allocate all the required buffer on the stack.
> The main issue is long double / _Float128, which may require up to
> ~6Kb of extra memory.  In this case, I think a single scratch_buffer
> should be suffice.  
> 
> Joe, I have implemented these on a personal branch [1].  It does not
> avoid the use o malloc (so printf double is still not fully AS-safe),
> but it should use a feasible amount of stack.
> 
> [1] https://sourceware.org/git/?p=glibc.git;a=blobdiff;f=stdio-common/printf_fp.c;h=431602caed85ee35c341a3565346406ff0736d45;hp=6f22985ba136da2ccb2bb5b9d397ce386c78ee91;hb=3c0bc3ed09ff7ce13524bab5ddb760b363640a1e;hpb=742b35228f3efa25d41d14f27c8911f308514b28
> 

Your branch looks okay to me and passed 'make check' without any
regressions.  Could you post the patch so that others more knowledgable
than myself can comment and review please?

Thanks,
Joe


  reply	other threads:[~2023-09-06 20:28 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-05 17:19 Joe Simmons-Talbott
2023-08-28 20:36 ` Joe Simmons-Talbott
2023-08-31 19:02 ` Adhemerval Zanella Netto
2023-09-01 12:20   ` Florian Weimer
2023-09-01 12:35     ` Adhemerval Zanella Netto
2023-09-06 16:55       ` Adhemerval Zanella Netto
2023-09-06 20:28         ` Joe Simmons-Talbott [this message]
2023-09-11 12:00           ` Adhemerval Zanella Netto

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=20230906202847.GK3849957@oak \
    --to=josimmon@redhat.com \
    --cc=adhemerval.zanella@linaro.org \
    --cc=fweimer@redhat.com \
    --cc=libc-alpha@sourceware.org \
    /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).