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 C850D371066 for ; Sat, 7 Mar 2026 10:27:07 +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=1772879229; cv=none; b=g/UOXVv91rxe6LGWEBJJI2EPSz1P9JfJSJXhFzO8ii8s9yrD0w/890qrOQse2uaTgCe+PkyD9QtQguTOBhI2d96flU6dVZB4Op+sS/LsxU9z5mJeMJaVkoM36TVQw0jlN+hUnejgbOgASoRaqDnEJdEUAQQF3lSSPbcQVNIpFaQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772879229; c=relaxed/simple; bh=nMHxuzAjz9fkluMK8O72ODLlqGIlq0FpLBOBA9XbkpE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=jJvMuEHk0U3rddUnpP5wPtimYc1+Yot05vWxHSwRu0IO5KxgnN5kDiwB3YcMVNR1c7gedrQfnVreYVbpI0IOnmBdo03bI4+WaeLioIiNGLkHwPBbBiP+cWGp7DCt5XVxhlv0QkICSrJ3sg0A1+qouYF7UhO/lfMCxKAGOJqzxPQ= 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=VTaZbeAI; 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="VTaZbeAI" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1wt.eu; s=mail; t=1772878722; bh=txIbnxCtmnvMY4/9P83RXnEVJRk2zxlZdawtkoS1WBI=; h=From:Message-ID:From; b=VTaZbeAIOrS3Vx78o6ANQvXjd9VXUmeWprYusjmnq1F0O204bQQrCG6SJ2jI4FPOy x4brwTxsJfQVP7Bbnpv644nK1nTEr+xpP2Fjygy9O0a4TK+42n99tyJ5Ix31dO+eMY dwpBOeFm92JDd2okAoNBUIoXIWBRI1kFOhVMl2OM= Received: from 1wt.eu (ded1.1wt.eu [163.172.96.212]) by mta1.formilux.org (Postfix) with ESMTP id 05EA4C0A05; Sat, 07 Mar 2026 11:18:42 +0100 (CET) Date: Sat, 7 Mar 2026 11:18:41 +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 v4 next 09/23] tools/nolibc: Implement strerror() in terms of strerror_r() Message-ID: References: <20260302101815.3043-1-david.laight.linux@gmail.com> <20260302101815.3043-10-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: <20260302101815.3043-10-david.laight.linux@gmail.com> Hi David, On Mon, Mar 02, 2026 at 10:18:01AM +0000, david.laight.linux@gmail.com wrote: > From: David Laight > > strerror() can be the only part of a program that has a .data section. > This requres 4k in the program file. Thanks for handling this one! Indeed, I saw a trivial hello world program take 4kB once %m got supported, which is a shame. > Add a simple implementation of strerror_r() (ignores buflen) and use > that in strerror() so that the "errno=" string is copied at run-time. > Use __builtin_memcpy() because that optimises away the input string > and just writes the required constants to the target buffer. > > Ignoring buflen is unlikely to be a problem given that the output is > always short. On this point it's not necessarily true, as we can overflow too short an output, e.g. when calling strerror_r() on a single-byte buffer: > +static __attribute__((unused,)) > +int strerror_r(int errnum, char *buf, size_t buflen __attribute__((unused))) > +{ Here I think we can simply do this to comply with the man page: if (buflen < 18) { errno = ERANGE; return -1; } (and we can safely ignore it for strerror()). > + __builtin_memcpy(buf, "errno=", 6); > + return 6 + i64toa_r(errnum, buf + 6); > +} > + (...) Thanks, Willy