From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D6B2729B233 for ; Sat, 7 Mar 2026 11:31:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772883070; cv=none; b=GRN3DF2SG/9vQ6tkHut6XgTixbYMz/kkyP2EF43q2OQ5MsMjrED1XfZTYKkGPsZfp0zdoD52g6lpcoBwkyQwwAdXsurIy0NKKTqhfeXjd+O6gHqFvBaNi0+o6bUiRspRuarXkqrFeBbMCzSkFnpwMi3CUD42oPDSnvyjHwjupm4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772883070; c=relaxed/simple; bh=jtW9N0U+MsWSDtA2MWZSjmp6DQP3KSCI8/UR748GtwY=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Z/JvR3uD5KJZz5Ks3zLsA4DumO27Ahz/75A+ZcqEq19284oENyVUbrjuTHP1sOEUR1X8b0Mby8Ilh2+v639X6Kv5VDakhNaN9keQNIlxub73Y48EREIypwcwwOnMCvQnoZ7NOc1u+1G/62HlwgUHjEVhU2HJO64Q9APm+63dII8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Gm9oglXv; arc=none smtp.client-ip=209.85.221.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Gm9oglXv" Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-439b790af67so3975410f8f.0 for ; Sat, 07 Mar 2026 03:31:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772883067; x=1773487867; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=ZI3cIt89HTYmcqN2jeHYSdoatchu7SvbS0eW5s0/dmE=; b=Gm9oglXvxuR/bDfGBG0XSuDSs1FLjxiugL2+LMelDE4BO+ZNAMZNeZSKdoh+ku1jQm auDf/BLfP8nZZBzp4Tu9gnbXUQp+xGwKRLN9OCMdcRfqA/k/ge2tnVq26gAkYnjOekud J9kly+Vu/8EKri21L/bc7TuBLa1uFcptzdWqqncR1nP3vSgTBZpxcstTbrjDLHtGnjU9 B6xC28kktkvLDT1WXmsT6oIemCUeZYuhEsPlZ/N+LIDhdSv16mIMXdaIXoe46rsrETaz nn4Tip6fojbZr8E2mUzHFx8brNtLLb/hsfD9vfVj1cjFlUfKloJvWt4rGAxRBAL/Nn9E Yv0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772883067; x=1773487867; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=ZI3cIt89HTYmcqN2jeHYSdoatchu7SvbS0eW5s0/dmE=; b=pPiq+80PqsXBjGeTf8FqCqx48Zt5S62Kls74lV8AmciIyw4xjPMr0ESx3NQNFYMAtC adpkDBjLW8F4kBqH4MLpQ9buwShFeDjW0rGnrDLjEifrtvpelWNDiAcgDWAkJ6Sa+y/q JxLAhnaiVOAoL1UHCM4eBFYTFhE80IjdbCO1ChQ8qKuJX0LmS4L7taYBgbfXlG5WB9fz ixPm/Ix1QYOiXhX1wfyhp+61bqIXzYHNFhf6xESHKOOw6ptWzjeqW6CjINeagkLkFWdS PJ1rTpjttHTUX/FeyetmZ7jRuboZjKD79BR/Ecg/9BKw7aBiA1+NgquAHYjKjExmK0ig /3SA== X-Forwarded-Encrypted: i=1; AJvYcCWyaCH95k/caourXzSoDtYvAdBafBjAgmuaZPXt+4cogRUMUBj67qqHdvgqiEnvnTrn0sI+vDYqk0HJRAc=@vger.kernel.org X-Gm-Message-State: AOJu0YxEHD95ChjDLSeS9kROARkU7VPK8NDt31e63jgGdne0GD8Ic8yK s0BEVLYEAs/n0FmBiR8JXGwIKnitIFUCeeDbpvgjJE73399BXRcHrUlM X-Gm-Gg: ATEYQzyyoX128V6s7H8M4k1zDOxgKjY+uOAYLn2nTbYWZ4rn9owF8r2/utfixx76afa XOyLwo1uA70xqQ7dX3jaI1ScaiU4Kx9qATkPINRAMwlZotnTgDPtDAyI8jtfXzTBah0J544mgXB bVtkrPArCbxoltsUJ484yvhq3sE7vJ511Ikxyt0zUJhyTJ0uYubiyC8IeLLdfrOThHjcPmSM5jZ k+0tTdKmZs640kVMuF7IJLH6Zzmm8OgizRRVjYdu/6lZg/f3WmFKR2LFqkjUlNrgY5diz2YpR7R spXyxFqOdnthxghXfzpaRXOX92UzCm8zSzRvYoG0WLLB5ab7dfSJ3bzEwRfTjduku8CsuNQRQne K1XyjKCVQRYgMgUwpKQOtQelJ3GIG8UbRkSALOH/sWy8qypSHhkYFVOIYdNZXAQea8+Ook8hlRF Mup5I2NKMjsINy6c1F+21eqJvbtMM9LpHyAlcRiLuG5a8rjArHEZNGgIlCqlsc47+L X-Received: by 2002:a05:600c:4e43:b0:475:ddad:c3a9 with SMTP id 5b1f17b1804b1-48526759b11mr92527235e9.13.1772883066983; Sat, 07 Mar 2026 03:31:06 -0800 (PST) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-485244a5c0esm63924505e9.4.2026.03.07.03.31.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Mar 2026 03:31:06 -0800 (PST) Date: Sat, 7 Mar 2026 11:31:05 +0000 From: David Laight To: Willy Tarreau Cc: Thomas =?UTF-8?B?V2Vpw59zY2h1aA==?= , 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: <20260307113105.76fb7fe9@pumpkin> In-Reply-To: References: <20260302101815.3043-1-david.laight.linux@gmail.com> <20260302101815.3043-10-david.laight.linux@gmail.com> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) 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-Transfer-Encoding: 7bit On Sat, 7 Mar 2026 11:18:41 +0100 Willy Tarreau wrote: > 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: But that would be silly, and you get what you deserve :-) It's not like passing char[64] will be too short because of some overlong error text. > > > +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; Looks like it should 'return ERANGE' (matching glibc 2.13+). > } > > (and we can safely ignore it for strerror()). ISTR strerror_r() tends to get inlined into strerror() so it would be optimised away. That simple (slightly over-enthusiastic) check is probably fine. Especially since normal code will be expecting a much longer string. I did think of implementing strerror_r() as: return snprintf(buf, buflen, "errno=%d", errnum) < buflen ? 0 : ERANGE; but that seems excessive. > > > + __builtin_memcpy(buf, "errno=", 6); > > + return 6 + i64toa_r(errnum, buf + 6); > > +} > > + > (...) > > Thanks, > Willy