public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Willy Tarreau <w@1wt.eu>
To: "licheng.li" <im.lechain@gmail.com>
Cc: "Thomas Weißschuh" <linux@weissschuh.net>, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 1/2] tools/nolibc: support left alignment (-) and zero padding (0) in printf
Date: Thu, 29 Jan 2026 07:41:04 +0100	[thread overview]
Message-ID: <aXsBANfAJdoTr8Iv@1wt.eu> (raw)
In-Reply-To: <20260128094224.11299-2-im.lechain@gmail.com>

Hi Cheng,

On Wed, Jan 28, 2026 at 05:42:23PM +0800, licheng.li wrote:
> From: Cheng Li <im.lechain@gmail.com>
> 
> Currently, __nolibc_printf() in nolibc parses the width field but always
> pads with spaces on the left. It ignores the '-' flag (left alignment)
> and treats leading zeros in the width as part of the number parsing
> (resulting in space padding instead of zero padding).
> 
> This patch implements support for:
> 1. The '-' flag: forces left alignment by padding spaces on the right.
> 2. The '0' flag: forces zero padding on the left instead of spaces.
> 
> The implementation reuses the padding character logic to handle both
> cases.
> 
> Logic behavior:
>  - "%5d"  -> "   12" (unchanged)
>  - "%-5d" -> "12   " (new: left align)
>  - "%05d" -> "00012" (new: zero pad)
>  - "%-05d"-> "12   " (new: left align overrides zero pad)
> 
> The code is optimized to keep the binary size impact minimal.
> Measuring the nolibc-test binary on x86_64:
> 
>   text    data     bss     dec     hex filename
>  43552     248     112   43912    ab88 nolibc-test (before)
>  43677     248     112   44037    ac05 nolibc-test (after)
> 
> The net increase is 125 bytes.

Is it normal this didn't change since previous patch, or did you just
forget to update that part of the commit message? In my case I'm seeing
a difference:

   text    data     bss     dec     hex filename
  35964     112     120   36196    8d64 nolibc-test-before
  36070     112     120   36302    8dce nolibc-test-after1 <- first patchset: +106
  36044     112     120   36276    8db4 nolibc-test-after2 <- this patchset: +80

If it's just an omission, I can edit the commit message if you paste
the new before/after in response, and save you from a respin just for
this! If it didn't change anything, that's possible as well, but
surprising, which is why I preferred to ask.

Thanks,
Willy

  reply	other threads:[~2026-01-29  6:41 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-28  9:42 [PATCH v2 0/2] tools/nolibc: printf left alignment and zero padding licheng.li
2026-01-28  9:42 ` [PATCH v2 1/2] tools/nolibc: support left alignment (-) and zero padding (0) in printf licheng.li
2026-01-29  6:41   ` Willy Tarreau [this message]
2026-01-29  6:57     ` licheng
2026-01-29  7:07       ` Willy Tarreau
2026-01-29 10:30   ` David Laight
2026-01-30  1:05     ` Cheng Li
2026-01-30  8:01       ` David Laight
2026-01-30  9:52         ` Cheng Li
2026-01-28  9:42 ` [PATCH v2 2/2] selftests/nolibc: add tests for printf left alignment and zero padding licheng.li

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=aXsBANfAJdoTr8Iv@1wt.eu \
    --to=w@1wt.eu \
    --cc=im.lechain@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@weissschuh.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