From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mta1.formilux.org (mta1.formilux.org [51.159.59.229]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A60543254B3 for ; Sun, 8 Mar 2026 11:58:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=51.159.59.229 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772971127; cv=none; b=hN/CsQsNdctNkKV4kV7USRuh8n/S6XgnhQhypkeS2PQO6DkzPUe3GTnHbosN9exrVF+sHKZbZJ7YC/DzHwa+ZduesxBZEKtUk8QPbf0GvUsg71nikVjXXRQYahFin3ijj6IMkgEXSaAgV23l/pJEkKgvUM9d4ABlvkyRknExh9o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772971127; c=relaxed/simple; bh=IiDYJuFRDsp0vMDW1hHUwgWZ8ViTGkpfio0VoJAdpBA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=aioOL1cNtv1AkEH13gFlGKm7WpeHwbGQUwoAYG0Ndu7HxiIs9p1GgAXer+lUIlw9rjs9hsJSUdyjrFYhFNmWrXO8DvoJp6WNk0wfPGdSbfIFy8TII/ZTnj97lBQrK/wSdMmxN2IAmkTLsgiPNZzsNqW61EYDGVUzIkjjP8nANuw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=1wt.eu; spf=pass smtp.mailfrom=1wt.eu; dkim=pass (1024-bit key) header.d=1wt.eu header.i=@1wt.eu header.b=ejUUTFtl; arc=none smtp.client-ip=51.159.59.229 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=1wt.eu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=1wt.eu Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=1wt.eu header.i=@1wt.eu header.b="ejUUTFtl" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1wt.eu; s=mail; t=1772971117; bh=7ognLW41m6P7BTbXzhJoZdl89hcWdx/o5XnS5mPn1Ig=; h=From:Message-ID:From; b=ejUUTFtlbjCji+eVOqrCjT6p1FW9QK4f/+rzCbyo92tHB+g6K56lDtRNz9cA+TYHO +zlxjxLl4qMB/HIxVtnrIpO6NZa262pqXnor0EAiowXVmOGbVSNm2PERKYJ1wWtoYZ SpzQT5e/F2xi9Z0cq7wQ+kK4lJiSuy6dBkFDUfoA= Received: from 1wt.eu (ded1.1wt.eu [163.172.96.212]) by mta1.formilux.org (Postfix) with ESMTP id 1D3B2C09E3; Sun, 08 Mar 2026 12:58:37 +0100 (CET) Date: Sun, 8 Mar 2026 12:58:36 +0100 From: Willy Tarreau To: david.laight.linux@gmail.com Cc: Thomas =?iso-8859-1?Q?Wei=DFschuh?= , linux-kernel@vger.kernel.org, Cheng Li Subject: Re: [PATCH v5 next 00/17] Enhance printf() Message-ID: References: <20260308113742.12649-1-david.laight.linux@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260308113742.12649-1-david.laight.linux@gmail.com> On Sun, Mar 08, 2026 at 11:37:25AM +0000, david.laight.linux@gmail.com wrote: > From: David Laight > > Update printf() so that it handles almost all the non-fp formats. > In particular: > - Left alignment. > - Zero padding. > - Alternate form "%#x" and "%#o". > - Field precision. > - Variable field width and precision. > - Width modifiers q, L, t and z. > - Conversion specifiers i, o and X (X generates lower case). > About the only things that are missing are wide chanacters and floating point. > > The tests are updated to match. > > Bloat/savings (in nolibc-test, but excluding the program) to patch 11: > (Measured for v3) > Function old new delta > _nolibc_u64toa_base.isra - 143 +143 > strerror - 78 +78 > __nolibc_sprintf_cb 58 91 +33 > itoa_r.isra 60 75 +15 > utoa_r.isra 144 - -144 > __nolibc_printf 1081 729 -352 > (All these functions include ~40 bytes for the stack protector code.) > utoa_r.isra and _nolibc_u64toa_base.isra pretty much cancel each other out. > itoa_r.isra grows slightly since it calls _nolibc_u64toa_base(). > strerror() used to be inlined, but over half of it is the stack check. > While some of the code added to __nolibc_sprintf_cb() has come out of > __nolibc_printf() 16-20 bytes is removed from the caller. > So there is a net saving of about 280 bytes (including losing a copy of > the number to ascii code). > > The later patches add code back in: > patch 13 - conversion flags " +#" +80 bytes > patch 14 - left aligning fields +38 bytes > patch 15 - zero padding and field precision +260 bytes > patch 16 - octal output +34 bytes > So probably about +130 bytes, but it will depend on what the application > actually calls and inlining decisions made by the compiler. > (All x86-64, other architectures will vary.) > > The biggest size change is probably removing the .data from strerror(). > This reduced the program binary file by 4k if it is the only initialised > data in a small program. > > Changes for v5: > - Old patches 2 to 7 have been applied to nolibc-next and removed. > - Patch 3 changed to return the correct (success/fail not length) > value from strerror_r() and to return ERANGE if the buffer is short. > - Patch 11 (prepend sign) has an updated comment. Thank you David. For me this is all OK. Great work! Willy