Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2519327pxa; Mon, 17 Aug 2020 11:39:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzfSfnXHh/ArC2UZNBsYkNARupvi4TS24u/G3XbG7lFMCjTVDbi1PgbzSbzoLZdLxTEuJzV X-Received: by 2002:aa7:c88f:: with SMTP id p15mr16586093eds.33.1597689556989; Mon, 17 Aug 2020 11:39:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597689556; cv=none; d=google.com; s=arc-20160816; b=uprFmtv4zhI7hhE7C0kCDQHT+wwXMqup8VTAxQLFfy9aQ4nwl9kMEawLi3etzQcNBe XSBrwlzP81no93A40JhhiyburV0HqvqQsPwQ82wnUDryI1/NjdhkWONCkn8x4D3scHoZ /fYvSh9lA7Gj7fWFxUb4jcA/U0HZ0T+iIptdqaVforpfTTZ09u8evtWAZRb5q6KQIxrm Y6fq+mFlTsNok7NQyZQBhZ+htAL6BXpoyUzl9KljqhPBTnIPJ5xGobejsozNLxM2nWwA 7WZBB2cZeceNQcrr8r/4w987NBsaXGJpCBbFqzvOlhM9BZCiT9mxjXDEuK69YRe/B5qL bCLA== 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=Qs4A+yO1as0umF/I9cYQ72bVP8PG6ZMKCk38nSsEIIo=; b=xLakiuiVozq7izAyasVncFfWnf+E6XqsPl5dCAB+CrZrkwhN6ESc1A51uhHd+XtekM IeO7cLKSI/flh8/73JwsoBNVaijINp/spO17a1kY+xhNMKrTPvTnRpBgfxdQ2Cks8tfH S5bDNyyGYi9gfpJd3sYsavVWc37Ysf9mzrW9BRsuy5Z3zArCdyRKambleBJn4Xc7naFO prcxwvRp0TsY9Fkk7rLDpeKeUGdsUgs3mhDl4NDtvj+tLij9Oze3EZU4SJyizXMThR2S JYX8TZcnngkVk3IMkEQi9h+wc8ADg26kly9nKAzkdV4rSMwL6rvw+IuvjT8a4LW5lY8y nOHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=SISFndTk; 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 bd8si11357855edb.477.2020.08.17.11.38.54; Mon, 17 Aug 2020 11:39:16 -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=SISFndTk; 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 S2389141AbgHQShJ (ORCPT + 99 others); Mon, 17 Aug 2020 14:37:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730586AbgHQShC (ORCPT ); Mon, 17 Aug 2020 14:37:02 -0400 Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82C1FC061389 for ; Mon, 17 Aug 2020 11:37:01 -0700 (PDT) Received: by mail-pf1-x441.google.com with SMTP id a79so8636199pfa.8 for ; Mon, 17 Aug 2020 11:37:01 -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=Qs4A+yO1as0umF/I9cYQ72bVP8PG6ZMKCk38nSsEIIo=; b=SISFndTkcUp1pFH8U2YJFkEw+BBQKq+fPBX0eplQ0w0CvJ7hvE9YNjpKcE135MBPmF aNGX23frr8ivsWZfRpIx6QCzwGTIyYb009KwfQPglZxUaQMAGseC48uBHP5u3tXn4Y41 viemUxJp2fH19u/cR+4Li1Qh5Yt0qX3bEb5ezK61MDWVsYXc/1sy3x2sYodeRPMh73jt xacOsf6vqOjFVkL95ZrjdTHG5h3gxGixIkz2LYtqd7u/MxXS0iLkVgfIv7u6C2Ff4QiG OitIeDihGZSyo+I7KjXFEdUHSxPnYEEbNqC2Pjx3klB0C8VMJtcc/qPNYa4pZMBABFm+ FJcA== 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=Qs4A+yO1as0umF/I9cYQ72bVP8PG6ZMKCk38nSsEIIo=; b=gplkAo12rIeQeSho07rMgTrAM2aDRgvmmCG9RganMlkW7x4a8urXUxi639tzW0/FAq +WJpN5b2eq2GzMqbB/VmST5ymqA0t90uamCi+xGf8zOm0aZhurG+UEZCOvffnF2cUSLy twoLJ1/K6sRq+QbJK9PyqK1OmglX5wjhYoN2Aqh6nf1tqh9xbXP6GAcP59rAYlgtT7E+ qlXaaXD+/e0ajfkIRIJGeoJMVVlhfqTnBfbHR1CF/x/aF0cdkkdyWf62xsTKKEk4bf9R dS2Jg8Z+rrXPPu3+SKOTkJ4K7ouMxzCGq+lKKkmdf5kf9vb/OmtUbSoLtAIUDTdSU5rf pCvQ== X-Gm-Message-State: AOAM5306TFvmf1rXIytrulg27MgNHXgnbczXdfJL3puuWtMXSzEYc8CY +okILe27JXV5wPV0B4+CBTw2PHNXm3AeeWLIg3mWYA== X-Received: by 2002:a05:6a00:14d0:: with SMTP id w16mr12126301pfu.39.1597689420744; Mon, 17 Aug 2020 11:37:00 -0700 (PDT) MIME-Version: 1.0 References: <20200815014006.GB99152@rani.riverdale.lan> <20200815020946.1538085-1-ndesaulniers@google.com> <202008150921.B70721A359@keescook> <457a91183581509abfa00575d0392be543acbe07.camel@perches.com> <20200816001917.4krsnrik7hxxfqfm@google.com> <20200816150217.GA1306483@rani.riverdale.lan> In-Reply-To: From: Nick Desaulniers Date: Mon, 17 Aug 2020 11:36:49 -0700 Message-ID: Subject: Re: [PATCH v2] lib/string.c: implement stpcpy To: Sami Tolvanen , Arvind Sankar , Kees Cook Cc: Sedat Dilek , Fangrui Song , Joe Perches , Andrew Morton , =?UTF-8?B?RMOhdmlkIEJvbHZhbnNrw70=?= , Eli Friedman , "# 3.4.x" , Vishal Verma , Dan Williams , Andy Shevchenko , "Joel Fernandes (Google)" , Daniel Axtens , Ingo Molnar , Yury Norov , Alexandru Ardelean , LKML , clang-built-linux , Rasmus Villemoes , Nathan Chancellor 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 On Mon, Aug 17, 2020 at 10:14 AM Sami Tolvanen wrote: > > On Sun, Aug 16, 2020 at 8:02 AM Arvind Sankar wrote: > > > > On Sun, Aug 16, 2020 at 07:22:35AM +0200, Sedat Dilek wrote: > > > On Sun, Aug 16, 2020 at 2:19 AM 'Fangrui Song' via Clang Built Linux > > > wrote: > > > > > > > > Adding a definition without a declaration for stpcpy looks good. > > > > Clang LTO will work. > > > > > > > > (If the kernel does not want to provide these routines, > > > > is http://git.kernel.org/linus/6edfba1b33c701108717f4e036320fc39abe1912 > > > > probably wrong? (why remove -ffreestanding from the main Makefile) ) > > > > > > > > > > We had some many issues in arch/x86 where *FLAGS were removed or used > > > differently and had to re-add them :-(. > > > > > > So if -ffreestanding is used in arch/x86 and was! used in top-level > > > Makefile - it makes sense to re-add it back? > > > ( I cannot speak for archs other than x86. ) > > > > > > - Sedat - > > > > -ffreestanding disables _all_ builtins and libcall optimizations, which > > is probably not desirable. If we added it back, we'd need to also go I agree. > > back to #define various string functions to the __builtin versions. > > > > Though I don't understand the original issue, with -ffreestanding, > > sprintf shouldn't have been turned into strcpy in the first place. Huh? The original issue for this thread is because `-ffreestanding` *isn't* being used for most targets (oh boy, actually mixed usage by ARCH. Looks like MIPS, m68k, superH, xtensa, and 32b x86 use it?); and I'm not suggesting it be used. > > 32-bit still has -ffreestanding -- I wonder if that's actually necessary > > any more? Fair question. Someone will have to go chase git history, since 0a6ef376d4ba covers it up. If anyone has any tricks to do so quickly; I'd love to know. I generally checkout the commit prior, then use vim fugitive to get git blame. > > Why does -fno-builtin-stpcpy not work with clang LTO? Isn't that a > > compiler bug? Yes; Sami found a recent patch that looks to me like it may have recently solved that bug. https://reviews.llvm.org/D71193 which landed Dec 12 2019. The bug report was based on https://github.com/ClangBuiltLinux/linux/issues/416#issuecomment-472231304 (Issue reported March 8 2019). And I do recall being able to reproduce the bug when I sent commit 5f074f3e192f ("lib/string.c: implement a basic bcmp") Now that that is fixed as reported by Sami below, I don't mind sending a revert for 5f074f3e192f that adds -fno-builtin-bcmp, because the current implementation of bcmp isn't useful. That said, this libcall optimization/transformation (sprintf->stpcpy) does look useful to me. Kees, do you have thoughts on me providing the implementation without exposing it in a header vs using -fno-builtin-stpcpy? (I would need to add the missing EXPORT_SYMBOL, as pointed out by 0day bot and on the github thread). I don't care either way; I'd just like your input before sending a V+1. Maybe better to just not implement it and never implement it? > > I just confirmed that adding -fno-builtin-stpcpy to KBUILD_CFLAGS does > work with LTO as well. > > Sami -- Thanks, ~Nick Desaulniers