From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 34966C433E1 for ; Tue, 25 Aug 2020 12:29:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 09F132075E for ; Tue, 25 Aug 2020 12:29:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598358594; bh=5/xJB4fbpQRXrU82ykLHnJ4QCGEYTfQbwz4FwUUEDwc=; h=References:In-Reply-To:From:Date:Subject:To:Cc:List-ID:From; b=KE8Kckw5qvq8cEeex7Qz3554ChJrS2V51TfePFPT5Ia/s/XYEWKnEBUiok4qRc6ra DEuvML4M+TvhCXYBAWzWw5bRcTn8QXsM+OijDmlS5GYZ1h2TK54BsEiCwxK/1VQlJJ VyZo3TXkCUeSTHHFA5t7cKngJQwOBUDvUcNkahyA= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726661AbgHYM3w (ORCPT ); Tue, 25 Aug 2020 08:29:52 -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-Google-Smtp-Source: ABdhPJyIs8Whq8eByRuYrPFEYB0rQzL0fX4J9QQ+NaRlsfdCpvIiae7R+ZUfqK/NgN1ob6KxzLkuKR0sk2tFUVY+/JQ= 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-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@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