Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp28255pxa; Tue, 18 Aug 2020 14:45:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyV9mrVdyFV95El3lGQTYp+I0jSWStBKii/hx225K/+ho0QFmIG34VNZPIJb/Z9A9FCdt2T X-Received: by 2002:a05:6402:7d5:: with SMTP id u21mr21667800edy.235.1597787100391; Tue, 18 Aug 2020 14:45:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597787100; cv=none; d=google.com; s=arc-20160816; b=0nWDCmOxY8YPh2dWuRVnEi3vuhOz27rE4VM68Y001HJzklololgOZ38d7DJKbDiuvO sx5u1y8pgdfyfuFMvIKvXZo6Q/K1RzawjIw9X4QYBTTeN8O1uJQ+HqQuvXeHEWK3gzdb /DcmIo/uit7LNQdtgEyGSIsD4IfuVHTkvhhpOgVCW5ZVZOTX9+po3+YfJH3boQehlnVE uncw4uo4yRtEGIzsANq0zXKs116Y2WPf6keV/7YbFUfX7BUAXhqeHEODCWGXr4gutXqK 3udIu8LOWNx+NwdsII5shtG71Ab3y38VbNvbFy0PipFsOCms7PmoBv8DNU24GI36FGLO Ayzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:date:from :dkim-signature; bh=BV9nHKz7rPkGsIi+O/4jfrEZv5isGZdcPFjOb+WDLfE=; b=rlQtf5ldcM23k72s80Y27OSVaSXqJ1yY4nTuk0EzRPo8GYEIZoO8WOok+m7KaBksrm 2odmXXTXJd5/pHfXpW2IHLBqiAs9F0s9zgI9eOS6UPf8UmpQ3RpKap+gUnxfy9B9XoPA V4h7A53eZvBlylZcKaxqThJMtR/IA4zATocGhsVsG3nxqzSoyunFLP+jo9QZnGRzQO9G 5MNfppbA6mCoWmkG+yiSxttfhYq7yJLGsj3d+WCqOyApBKyRkKnIMqMFh9Fn3NGJd4vZ Uotwc5ouFVNKq2QIwPayXPV+Pgcc65n/FRSWdz2BX3NMCSPxqa6Ow+F4wS++cX8BouN5 DcMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=FOJz8Gdj; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v16si13872636ejq.43.2020.08.18.14.44.32; Tue, 18 Aug 2020 14:45:00 -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=fail header.i=@gmail.com header.s=20161025 header.b=FOJz8Gdj; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726735AbgHRVlw (ORCPT + 99 others); Tue, 18 Aug 2020 17:41:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726366AbgHRVlu (ORCPT ); Tue, 18 Aug 2020 17:41:50 -0400 Received: from mail-qv1-xf42.google.com (mail-qv1-xf42.google.com [IPv6:2607:f8b0:4864:20::f42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A1F7C061389; Tue, 18 Aug 2020 14:41:50 -0700 (PDT) Received: by mail-qv1-xf42.google.com with SMTP id o2so10307887qvk.6; Tue, 18 Aug 2020 14:41:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:date:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=BV9nHKz7rPkGsIi+O/4jfrEZv5isGZdcPFjOb+WDLfE=; b=FOJz8GdjccX2cbuIKuz3pWT2p0F7/c+kmfoN5iv5WhhsrWwDZYzIjgnJz95owS6WI3 UBG8sBpdx3nD+nnfuhMyblLHdjf6LGvd4UVn8Q00VFxenPEsBtLh0Ukr+Q4h7/EoJPw0 d8qeXzJqxja8gZznvZhwvj1FgcbpiHi/uBrljyr8ia2qp0uiWQkFPcKsf9SEUsLWIZR6 a+mKks42+TALVES2XNxnCqw3BNWp1pXPTmTJrjCtJvFCHqUAbN7FbKrvxlRhYKLE7kpM R7q+oA+uJ9dLf8bWgVEZ9+8dkF2+web4Qn/ym1VY+fSXhqJA3LcpeAhHgeUDJk1O5YvM QmcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:date:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to; bh=BV9nHKz7rPkGsIi+O/4jfrEZv5isGZdcPFjOb+WDLfE=; b=OSQxc/N2T0amw2Uz8tGa/mJBLVzSnPT+8WwPA1mr6IVfuN42scswUCm+qijP0hSr64 sFiXpWn/9PRWC3cjiuacBKTg+RMwUBLq93HrTB+tIBe1DNqkYkdABWCXAz/UHePHtfFd eb0PfstXEY281FBxOFBmePUS5840o1bDAlVMZ500l9eN2FTXSMISYhAVz2yK/+cT2cZU kG84TjJrbQ6IKaV81u2905fAWTE7B6mZ4IlO+8PJgGyV5Zw2rHDrJBUf8ifyUX+cpd9h OeLqdw7wgQ3WKxJyNidrQXOVhv1+jZe8r+xIyN6NtBiXEdLreJY3+9FJ4Ff7Why3PVp6 JGPg== X-Gm-Message-State: AOAM531thbjeNYlaNqIFEAmVCVHowr0k/mVIzF2A0g5NyMra20fzVpfy DtNJx4Hsv8dzWJZn95O8Fw4= X-Received: by 2002:a05:6214:290:: with SMTP id l16mr21439284qvv.187.1597786909673; Tue, 18 Aug 2020 14:41:49 -0700 (PDT) Received: from rani.riverdale.lan ([2001:470:1f07:5f3::b55f]) by smtp.gmail.com with ESMTPSA id i30sm26355390qte.30.2020.08.18.14.41.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Aug 2020 14:41:49 -0700 (PDT) From: Arvind Sankar X-Google-Original-From: Arvind Sankar Date: Tue, 18 Aug 2020 17:41:46 -0400 To: Nick Desaulniers Cc: Arvind Sankar , =?utf-8?B?RMOhdmlkIEJvbHZhbnNrw70=?= , 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 Subject: Re: [PATCH 0/4] -ffreestanding/-fno-builtin-* patches Message-ID: <20200818214146.GA3196105@rani.riverdale.lan> References: <20200817220212.338670-1-ndesaulniers@google.com> <76071c24-ec6f-7f7a-4172-082bd574d581@zytor.com> <20200818202407.GA3143683@rani.riverdale.lan> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 playing > > > > > whack-a-mole *for a limited time* is unreasonable. But I would like to go back > > > > > to the compiler authors and get them to implement such a #pragma: "this > > > > > freestanding implementation *does* support *this specific library 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 standard > > > > function"). > > > > > > > > IOW, there's nothing wrong with -ffreestanding if you then also have > > > > __builtin_memcpy() etc, and they do the sane compiler optimizations > > > > for memcpy(). > > > > > > > > What we want to avoid is the compiler making *assumptions* based 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. #pragma, or > > > even just allowing -fbuiltin-foo options would be useful. > > I do really like the idea of -fbuiltin-foo. For example, you'd specify: > > -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.