Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1298056pxa; Sat, 15 Aug 2020 14:54:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzWN4oLZHxolxoF1OlV3g+0CAOPYYs9XOSaP671bH+GbSc1E5oQZwg85GZSRFKkX8TYPgAG X-Received: by 2002:a17:906:414b:: with SMTP id l11mr8500758ejk.334.1597528464082; Sat, 15 Aug 2020 14:54:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597528464; cv=none; d=google.com; s=arc-20160816; b=GpUS+lOv/qzO2J9BlJLGIlaB/cUWySd1ilSZZaVGZXa4EuwrxXlO+jZaap7wJB1BiD Vzv61foo3Ms0qgyFMxyOwWDDFPFfaHNZbOtFK/kUaxEchTotRx8vmMOIihhc6g4Or09T xVnP18YJ3rXN3cYyNJ44jHLV9zSddaJqkRgkbhpaR1jWd3ctUkeqNjsP651sSifXlBsM TLZMjWQT1UD9jhPuNri8MmhiVjGVlHifG1X7YNbAxPXhbQKY9jQrdom2X9272ROtG0Kq IwqYQsS6pwPCLoxARZckNY/NiDNb93ibTKjn/h7v1UUuKFcc6l3oPkffWyvsXNKvIsW2 pFQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=cE/B8jLj1zvXZ+mvl87f60vua1FqTOB1sidvPP/WOgw=; b=qjBiDsT9sc0YoxvcJv9WfetHabQ9x+rpek7TU47xcgcYLgCLZc2O9rQQeiavIH+lMA eEQIjdrGSs3uqkt6BxF6gutSAc05RlsPeUunYHALq7lE+34VwZFf4vrR/+Kr3sSIHks4 FgBgb3HnVHdZ5MZEvA+1I5NBPi1zrkG7VXOgqDxr8mS3PA0VJp4N+RGdhEo9vYz0gwBF chSKQ8mP4QOJ/TarVzlLdHuDqMKAhBGowCl+SilBwi3cJFpg4nkVGHX+FTMI84lksHGO YHYUBV16fOuEntPEVSzh+kGO1ngE0dwD8UuIn01sS/ezYvRLTtcrVnwuuEbOHEuac0na DJxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=opWbEJLA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y20si8313096ejj.325.2020.08.15.14.54.01; Sat, 15 Aug 2020 14:54:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=opWbEJLA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728137AbgHOVww (ORCPT + 99 others); Sat, 15 Aug 2020 17:52:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729110AbgHOVwf (ORCPT ); Sat, 15 Aug 2020 17:52:35 -0400 Received: from mail-ej1-x642.google.com (mail-ej1-x642.google.com [IPv6:2a00:1450:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D79DC061348 for ; Fri, 14 Aug 2020 17:53:41 -0700 (PDT) Received: by mail-ej1-x642.google.com with SMTP id m22so11679847eje.10 for ; Fri, 14 Aug 2020 17:53:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=cE/B8jLj1zvXZ+mvl87f60vua1FqTOB1sidvPP/WOgw=; b=opWbEJLAX5qZbFpaKKZsvc/e8RNL/4tGU/5+gViPNL//IDiQoQtBlTLSzzmrl1XfSN 7gIxERT+8ExdXmKG1LZPDzPWMkzQTReXKx0ITYiliKFUjkIt6i85mEChVWopekn4wAGj gfiBKSUqnKRTjekrpQOpCDJwSnJi5XmbQtbdar7ObT4lW8YvuI/aTPsZkMlLbGps1t2p bO2tf5mNlVMAsRothforYyk+YoS5Z+5q/+DAG+Dh+tT6ki+L/aTkg+EW8W9a1CJKuB4A g8ceSac41Bcdsa2UCT/3ODU+9pbD/lXNdVzCH3EyG+f9Sd7/CsWbnqwKtbPqC1BPyPJ+ xgvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=cE/B8jLj1zvXZ+mvl87f60vua1FqTOB1sidvPP/WOgw=; b=A91T7hD1+s6vpi6GyGVCvBTRTp3e/RFInT5iy+7fMh21ZSRdxRpwC6lWl+0CCsoPn+ tsqFig4fJNEYdN1x/TCIiGBHODju1/RraIMWpaBqqayV0HUqPcd+22bz3gmPKBuoRyTx Tb3RVSQBmhEkFmKDR5oGM+NG3i0/DsYiHwbhqlTIP5lZHXKAHPXBuawrC25luPT7Mq9a WDywHdHuVj0/Q6ZfedBvEFCbC5NeFIJYRn1UCyRKye6jy5KP3jmZKz129yKrWEtlal5I 76If48ZkPeze3W11C0Z0BBuL48XI7fWCLa866UIV2/SlZk0tNckVlcAqwHIUcp0RyWDV ORWQ== X-Gm-Message-State: AOAM533+aUPVrsdxkTkWjx5G/69FqrMqRVVv3TATbFSFB5e02Vbi0zG2 +q0i30cKmZU0Zwi5DTOwzhTKsA9kgWX2SZw62EJ3EQ== X-Received: by 2002:a17:906:2356:: with SMTP id m22mr4835600eja.124.1597452819358; Fri, 14 Aug 2020 17:53:39 -0700 (PDT) MIME-Version: 1.0 References: <20200815002417.1512973-1-ndesaulniers@google.com> In-Reply-To: <20200815002417.1512973-1-ndesaulniers@google.com> From: Sami Tolvanen Date: Fri, 14 Aug 2020 17:53:28 -0700 Message-ID: Subject: Re: [PATCH] lib/string.c: implement stpcpy To: Nick Desaulniers Cc: Andrew Morton , =?UTF-8?B?RMOhdmlkIEJvbHZhbnNrw70=?= , Eli Friedman , stable@vger.kernel.org, Joe Perches , Tony Luck , Yury Norov , Daniel Axtens , Arvind Sankar , Dan Williams , "Joel Fernandes (Google)" , Andy Shevchenko , Kees Cook , Alexandru Ardelean , LKML , clang-built-linux Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Nick, On Fri, Aug 14, 2020 at 5:24 PM Nick Desaulniers wrote: > > LLVM implemented a recent "libcall optimization" that lowers calls to > `sprintf(dest, "%s", str)` where the return value is used to > `stpcpy(dest, str) - dest`. This generally avoids the machinery involved > in parsing format strings. > > `stpcpy` is just like `strcpy` except: > 1. it returns the pointer to the new tail of `dest`. This allows you to > chain multiple calls to `stpcpy` in one statement. > 2. it requires the parameters not to overlap. Calling `sprintf` with > overlapping arguments was clarified in ISO C99 and POSIX.1-2001 to be > undefined behavior. > > `stpcpy` was first standardized in POSIX.1-2008. > > Implement this so that we don't observe linkage failures due to missing > symbol definitions for `stpcpy`. > > Similar to last year's fire drill with: > commit 5f074f3e192f ("lib/string.c: implement a basic bcmp") > > This optimization was introduced into clang-12. > > Cc: stable@vger.kernel.org > Link: https://bugs.llvm.org/show_bug.cgi?id=47162 > Link: https://github.com/ClangBuiltLinux/linux/issues/1126 > Link: https://man7.org/linux/man-pages/man3/stpcpy.3.html > Link: https://pubs.opengroup.org/onlinepubs/9699919799/functions/stpcpy.html > Link: https://reviews.llvm.org/D85963 > Reported-by: Sami Tolvanen > Signed-off-by: Nick Desaulniers > --- > include/linux/string.h | 3 +++ > lib/string.c | 23 +++++++++++++++++++++++ > 2 files changed, 26 insertions(+) Thank you for the patch! I can confirm that this fixes the build for me with ToT Clang. Tested-by: Sami Tolvanen Sami