Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2882345pxa; Tue, 25 Aug 2020 06:06:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzEA8d0E6u0xiszZWA2Y5R4mND3zV9WbnaaDC7zndLprLmi3AZkWNEWtYKw9IEqZ/6we6kF X-Received: by 2002:a05:6402:a51:: with SMTP id bt17mr9967302edb.382.1598360812736; Tue, 25 Aug 2020 06:06:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598360812; cv=none; d=google.com; s=arc-20160816; b=eb7kLXeRDqUvNhUZnMeffaxP0aGjWrV7td9LHUqHhJUZGX7WCwcDfuojTkRYwY4ULE k9en/JaqTNYBqJDcuitc8aphAZAS5VKe778lgIH0N0LfT2oi18WlOwSLefzAEwH6V+HB d6K9O0o9Yrz1zOtCvoSUlPWZFT6HukR9jGDYFlSQfkKAe1GWLQxOnk0/WsatvNJ5LpZT l1vjpSGBYq4mBVnuup2dpF9bm+bPkwhy4fGL9qrSvb3BGWDo05m5j9kCuBTEsvMCqMtO oGXgZ6z4wei8Bbj0TqfgtXQ5Daf1fwPuIzC+UK/N+I4sKYxrg51mR3sY9rZR8xOI8dPi YEpw== 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:dkim-filter; bh=fWDEMSaOrPS74dlXpFO19QBM3u09HqUhQUZB2brSdsY=; b=wahD6Ms+5lJL+AfZkp53+muVue2RRcBes+a3u6MUwEKKfXvOVDVSZSc38VdMLpePoH +y9DkQIQXHtd8O7M1zOxgpzuc1pOeb45GuAfUnPpDJQ0sb7uoz7vuCL3paDrKWsEDn1f +U3+kf51w9cFH83GfrEjYPFahE0fBvx1eOLQOzUPhwgSOC+i4/jqQhhLEK/+7+jub+ga oCJiERCjukvwgCs75fUjjKbM3pLkqAUrKoa8WwTUJeVMdL+rsD9lZlJhSP5EcaYqvHi/ pj09h22z2vzNbPO49yP/RxHTLohSersQg5Yj9TH10e6FjMF+srSr90e3PZtvxCYQD3rq fx5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=fOxcwLtg; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i3si5772300edt.479.2020.08.25.06.06.24; Tue, 25 Aug 2020 06:06:52 -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=@nifty.com header.s=dec2015msa header.b=fOxcwLtg; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726809AbgHYM3y (ORCPT + 99 others); Tue, 25 Aug 2020 08:29:54 -0400 Received: from conssluserg-02.nifty.com ([210.131.2.81]:48393 "EHLO conssluserg-02.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726336AbgHYM3w (ORCPT ); Tue, 25 Aug 2020 08:29:52 -0400 Received: from mail-vs1-f48.google.com (mail-vs1-f48.google.com [209.85.217.48]) (authenticated) by conssluserg-02.nifty.com with ESMTP id 07PCTVki021974; Tue, 25 Aug 2020 21:29:32 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conssluserg-02.nifty.com 07PCTVki021974 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1598358573; bh=fWDEMSaOrPS74dlXpFO19QBM3u09HqUhQUZB2brSdsY=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=fOxcwLtgxKIPR8hbtZKkbMiRjJ2Aqr4TlwxTj4ubxNpD2txA5BHxg6KAQPsgXUldU MpJOiZ4YGDiPs9RFKoAiLlAW/mAgpfnyAEz0a0/g6shhkRwRf0gHDxSWmNHhaLyvn1 kJa2Ip51JlytlW/TZumMYEP5WZM6Kol30Y/ezYGCRGJ+W/XKHJ1OwQ09Aq44O3qCnI E3ofcAElvx9Woo/XQSE7C4VNnPVa+r/K442fyv8fpmNjr9139ggNgmwSXQKyKS4rh6 tlZuO0sM6KJfyjcQZRjfek8cCuYM5qaUnjR8+zxm6SnB74hxlNfEzNmbT0Y1St3PNa WW2VbtkFCy5qw== X-Nifty-SrcIP: [209.85.217.48] Received: by mail-vs1-f48.google.com with SMTP id e14so6215737vsa.9; Tue, 25 Aug 2020 05:29:32 -0700 (PDT) X-Gm-Message-State: AOAM5315vA0a42hdsf7wqGyqwxCD73iA5Hcjb3vVBEHLDBWuvs7TdUwI C+D15IeOiqeWR18StXchxuKax9pDnqAi1zX6BgI= X-Received: by 2002:a05:6102:7ac:: with SMTP id x12mr5038553vsg.181.1598358571195; Tue, 25 Aug 2020 05:29:31 -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> <20200824173450.GA4157679@rani.riverdale.lan> In-Reply-To: From: Masahiro Yamada Date: Tue, 25 Aug 2020 21:28:53 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 0/4] -ffreestanding/-fno-builtin-* patches To: Nick Desaulniers Cc: Arvind Sankar , =?UTF-8?B?RMOhdmlkIEJvbHZhbnNrw70=?= , Eli Friedman , Linus Torvalds , "H. Peter Anvin" , 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" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 25, 2020 at 4:10 PM Nick Desaulniers wrote: > > On Mon, Aug 24, 2020 at 10:34 AM Arvind Sankar wrote: > > > > On Tue, Aug 25, 2020 at 12:57:22AM +0900, Masahiro Yamada wrote: > > > > > > > > > To prevent transformation from foo() into bar(), > > > there are two ways in Clang to do that; > > > -fno-builtin-foo, and -fno-builtin-bar. > > > There is only one in GCC; -fno-buitin-foo. > > > > > > Is this correct? > > > > > > > It looked that way from previous experimentation, but... > > > > > > > > > > > I just played the optimization > > > from printf("helloworld\n") to puts("helloworld"). > > > > > > https://godbolt.org/z/5s4ded > > > > > > > > > -fno-builtin-puts cannot prevent clang > > > from emitting puts. > > > Is it because clang does not support > > > -fno-builtin-puts? > > > > Ugh. clang doesn't have __builtin_puts() but it optimizes printf() into > > puts(). It doesn't have __builtin_putchar() but will optimize > > printf("c") into putchar('c'). > > Bah, merely a flesh > woundcompiler bugrather > long TODO in the compiler. > https://github.com/llvm/llvm-project/blob/be2bc7d4cef2edd66c7fb74b70adf62fc68754db/clang/include/clang/Basic/Builtins.def#L943 > > Anyways, give me a week and I'll hack through the rest of them > https://reviews.llvm.org/D86508. Certainly made HPA's point hit home, > that's a lot of functionality to implement or disable in an > environment. > > Masahiro, are you implying that we shouldn't take the > -fno-builtin-stpcpy patch, because Clang is inconsistent? (That can be > fixed.) Even though -fno-builtin-stpcpy works here as intended? > https://lore.kernel.org/lkml/20200817220212.338670-2-ndesaulniers@google.com/ > > Otherwise we need to provide an implementation of this symbol in the kernel. > https://lore.kernel.org/lkml/20200815020946.1538085-1-ndesaulniers@google.com/ > > Please, pick your poison. I am not a compiler expert. Nor am I sure if I am the right person who makes this decision. But, if so, I would choose the latter. (implement stpcpy() in the kernel) I was addressed last night, so I should write up my thoughts. I do not think -fno-builtin-stpcpy is a general solution. -fno-builtin-stpcpy will work for now because only Clang implements the transformation from 'sprintf(dest, "%s", str)' into 'stpcpy(dest, str) - dest'. If GCC implements it some day, we would run into a problem because in GCC, it is not -fno-builtin-stpcpy, but -fno-builtin-sprintf that disables that optimization. In this regard, 'KBUILD_CFLAGS += -fno-builtin-sprintf' would be more future-proof, but it is potentially an overkill. We want to disable optimization from sprintf() to stpcpy(), but we may still benefit from the optimization from sprintf() into something else. Linus is uncomfortable with this kind of compiler magic. If we take compiler's freedom away, -ffreestanding is a big hammer to solve this problem. If we welcome the compiler's optimization, we should implement stpcpy(), bcmp(), and whatever until we solve all link errors. -- Best Regards Masahiro Yamada