Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp83023pxa; Tue, 18 Aug 2020 16:43:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzplvsD/+5/3qPx1tFQeDhWB9C7SZ4F62LfsrznZwmuMfJgNzwnCri2eZpL9/foD3i+dg8J X-Received: by 2002:a17:906:5495:: with SMTP id r21mr21774286ejo.33.1597794199622; Tue, 18 Aug 2020 16:43:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597794199; cv=none; d=google.com; s=arc-20160816; b=GCxozb6GwusQluAQAn3KRROutxCKF7EapcC3twbNuQ4SJ3vGt1XKs2w2tuaQg2w7xM v6mhn+tabPlhe6gW0wDLayhecbf+QgXCk2mFPdGXZmBcQn8E5tlhGtM65ILrtLWXkAZz 7TdKZAn5r3qgYcWLLBEDOUjTW999XrU2UnMTaxFzkAh8RmdNI0GDnmWKYEUPozOggwoy xlallblDJdVk51BlHLdh6bNTUIkFCYT7PQa8wDkrDBzM0XbGZIxWvJzUIv6MT0Hd1Nc5 +A+RVZKsYheBwSMb0X0o670xW26ZOqLHovqE2MWFDSmRc/IV+UYucPM5O5M7mDxlujV3 fScQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=dQQ7nxmbbtqPjMJ2v1Fd/tVads8v7A1o12xPycfzDck=; b=XqMJisf4gBTNda9s96U5C4PwEDoW7KnOXla6uMaTIvntFdNHMGjO2XdEeZ+Z4oQAVw ZPSqrXHnGZf934pgWite7cgoUPHBjb4yvlwnCpDMcU9sezSgPZFxc+nfqAvae3nlM638 H/uI545E+E7PE7pgIWUXXK1U3H+mEIn1kKKSgWtC4S3w4KOBdXtfwUbhAK1T0p9MZbVp xfY8JyBqts+7DoogQovWEzYbyah+CFXyODD3+63mRXDJP7782XUBwIRuQPYIvJcO+9bx 37rZpVFq/aW+R0/L32mfC6fC5dJBxdZ46ez1HFkfHvuWPEDGZDIiERHoqmlZ+POzmVYA pLwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=YlDFccnv; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k19si14696663ejz.79.2020.08.18.16.42.29; Tue, 18 Aug 2020 16:43:19 -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=@gmail.com header.s=20161025 header.b=YlDFccnv; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726876AbgHRWFv (ORCPT + 99 others); Tue, 18 Aug 2020 18:05:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726617AbgHRWFr (ORCPT ); Tue, 18 Aug 2020 18:05:47 -0400 Received: from mail-io1-xd41.google.com (mail-io1-xd41.google.com [IPv6:2607:f8b0:4864:20::d41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4E80C061389; Tue, 18 Aug 2020 15:05:45 -0700 (PDT) Received: by mail-io1-xd41.google.com with SMTP id u126so22650632iod.12; Tue, 18 Aug 2020 15:05:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=dQQ7nxmbbtqPjMJ2v1Fd/tVads8v7A1o12xPycfzDck=; b=YlDFccnv1UsuHHlQzmM690C7v5BvX0FQV4SVnxlk1r34xvRCg89M4up+6M50Vk9wEE Y2AteDF2L+d+fP3EhlI1cwk+MOKK68zbdaMsRaneQgG0Qa50cTFaOtYUXpuQteQPYRuw HI/01vu5IL39hjTzCS81cCrcLUFZbFmKjwRyf5JPcQ2k4wye8vdDWxwAxy2rtMcJdOB+ +7XGA3O3cbaIP2O0UmO8u7wA+l3zoCyuxw5sOQZHJHpTR5PSsjTleP9w5PGSH7anFPQC XHa3Ipk8wHGiDURmM9E3vujONTW1+d3dZ/FS3T5Sa+vndQVzaM7prYOsZXwebQb5uA5q jYgg== 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:content-transfer-encoding; bh=dQQ7nxmbbtqPjMJ2v1Fd/tVads8v7A1o12xPycfzDck=; b=TDQH71yUdbjoHZzehoR0/toGCpruJ/rVviPowD8/V5iQSvqEE9XStkA7u5cyDYfZev Ra68CTtOyL5ELG34a57yuzjOC+QS6B/bFh1l9AXDyNVtP2qadkIwZZrzuiRtUSoV8VPO JPyJG/jw4WviDZ4PU2FkGw5gQ2g/yMfoDOTefMA7v0cHL0HFdT02+nblMqS9P5z5tRgl CK9QO++Ow3fBVjJjProYNOkCEzf/YdQxFhixWNTm/Xu2kXVMQ/KIvPev82eOW+I7G2rP r+cU24AZ4El9Y3W6s5AeJlcN7FgHzPqsT9Fb8SadH2LLMJzNf2uFgvRKaU89aqdVB1G8 Lkqg== X-Gm-Message-State: AOAM532vW5DxSDN8rbeizUEceD11oM8ATbnqK2xk38kyTvwyXyXvnewN fHfpljyLR59IQYFucWEGPWs7q0V1ZJ27S6IjY2Q= X-Received: by 2002:a05:6638:594:: with SMTP id a20mr21415996jar.127.1597788345058; Tue, 18 Aug 2020 15:05:45 -0700 (PDT) MIME-Version: 1.0 References: <20200817220212.338670-1-ndesaulniers@google.com> <76071c24-ec6f-7f7a-4172-082bd574d581@zytor.com> <20200818202407.GA3143683@rani.riverdale.lan> <20200818214146.GA3196105@rani.riverdale.lan> In-Reply-To: From: =?UTF-8?B?RMOhdmlkIEJvbHZhbnNrw70=?= Date: Wed, 19 Aug 2020 00:05:34 +0200 Message-ID: Subject: Re: [PATCH 0/4] -ffreestanding/-fno-builtin-* patches To: Nick Desaulniers Cc: Arvind Sankar , Eli Friedman , Linus Torvalds , "H. Peter Anvin" , Masahiro Yamada , Andrew Morton , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Michal Marek , Linux Kbuild mailing list , LKML , Kees Cook , Tony Luck , Dmitry Vyukov , Michael Ellerman , Joe Perches , Joel Fernandes , Daniel Axtens , Andy Shevchenko , Alexandru Ardelean , Yury Norov , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , Ard Biesheuvel , "Paul E . McKenney" , Daniel Kiper , Bruce Ashfield , Marco Elver , Vamshi K Sthambamkadi Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Here: https://godbolt.org/z/qjo5P6 st 19. 8. 2020 o 0:00 Nick Desaulniers nap=C3=ADs= al(a): > > On Tue, Aug 18, 2020 at 2:41 PM Arvind Sankar wro= te: > > > > On Tue, Aug 18, 2020 at 01:58:51PM -0700, Nick Desaulniers wrote: > > > On Tue, Aug 18, 2020 at 1:27 PM Nick Desaulniers > > > wrote: > > > > > > > > On Tue, Aug 18, 2020 at 1:24 PM Arvind Sankar wrote: > > > > > > > > > > On Tue, Aug 18, 2020 at 12:13:22PM -0700, Linus Torvalds wrote: > > > > > > On Tue, Aug 18, 2020 at 12:03 PM H. Peter Anvin = wrote: > > > > > > > > > > > > > > I'm not saying "change the semantics", nor am I saying that p= laying > > > > > > > whack-a-mole *for a limited time* is unreasonable. But I woul= d like to go back > > > > > > > to the compiler authors and get them to implement such a #pra= gma: "this > > > > > > > freestanding implementation *does* support *this specific lib= rary function*, > > > > > > > and you are free to call it." > > > > > > > > > > > > I'd much rather just see the library functions as builtins that= always > > > > > > do the right thing (with the fallback being "just call the stan= dard > > > > > > function"). > > > > > > > > > > > > IOW, there's nothing wrong with -ffreestanding if you then also= have > > > > > > __builtin_memcpy() etc, and they do the sane compiler optimizat= ions > > > > > > for memcpy(). > > > > > > > > > > > > What we want to avoid is the compiler making *assumptions* base= d on > > > > > > standard names, because we may implement some of those things > > > > > > differently. > > > > > > > > > > > > > > > > -ffreestanding as it stands today does have __builtin_memcpy and > > > > > friends. But you need to then use #define memcpy __builtin_memcpy= etc, > > > > > which is messy and also doesn't fully express what you want. #pra= gma, or > > > > > even just allowing -fbuiltin-foo options would be useful. > > > > > > I do really like the idea of -fbuiltin-foo. For example, you'd speci= fy: > > > > > > -ffreestanding -fbuiltin-bcmp > > > > > > as an example. `-ffreestanding` would opt you out of ALL libcall > > > optimizations, `-fbuiltin-bcmp` would then opt you back in to > > > transforms that produce bcmp. That way you're informing the compiler > > > more precisely about the environment you'd be targeting. It feels > > > symmetric to existing `-fno-` flags (clang makes -f vs -fno- pretty > > > easy when there is such symmetry). And it's already convention that > > > if you specify multiple conflicting compiler flags, then the latter > > > one specified "wins." In that sense, turning back on specific > > > libcalls after disabling the rest looks more ergonomic to me. > > > > > > Maybe Eli or David have thoughts on why that may or may not be as > > > ergonomic or possible to implement as I imagine? > > > > > > > Note that -fno-builtin-foo seems to mean slightly different things in > > clang and gcc. From experimentation, clang will neither optimize a call > > to foo, nor perform an optimization that introduces a call to foo. gcc > > will avoid optimizing calls to foo, but it can still generate new calls > > to foo while optimizing something else. Which means that > > -fno-builtin-{bcmp,stpcpy} only solves things for clang, not gcc. It's > > just that gcc doesn't seem to have implemented those optimizations. > > Can you please share some godbolt links that demonstrate these observatio= ns? > -- > Thanks, > ~Nick Desaulniers