Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp433465pxa; Fri, 21 Aug 2020 10:58:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJySoyHzUD/ln/tVRO0n+bkqtZzM16lIoAUAp+RMwd669jbG/aKZ4tUEQb+s02pIAOZR+YkQ X-Received: by 2002:a17:906:5811:: with SMTP id m17mr4013214ejq.40.1598032720571; Fri, 21 Aug 2020 10:58:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598032720; cv=none; d=google.com; s=arc-20160816; b=fPD7byhVLxffDJY2IHpFJSltiAPv0lHUSFkU0SnKrOcDIdy4vV66GlWeqr5BpfItzL u/6nbOerbgibl3jtRTi2xD6vZAu/D6KdOZQ+M7a4wJicvVlD/4/7xd7JgGKCA7Frdn2K faLM4kA8bB+kTJErcSHvXUOxyHi1ii4HxUC2lpMJ+d/iGE/wrpa0XJkdjNH4Vvco5jTc o0bVSURKXohcUKMKhtCo82iuVm0TBdEQe4pqpyEXYvMaIS8JIGxX+2HNZIXDb9r0XPho oenu/lxP0DXDUUwY9eoDEyTao336EVEbSgzAwTakw6eM6YZF03HAk5svr/O21KUxwher SuUw== 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=m4V8fZt1LIyKWUpK//pHmx+UE2cyQI+1k+0DpARcdKs=; b=vpFM6daZRHOGGvkrsWz4oatTcMn9KZzQHWkE7pL1xoeordFxDtrdxby4f4w+LdaJfW 1+JWd0nkN0zmdxrrlJ+6+vvODkWaKRaXqOzETcAB7rsOShym99BM5SAvF36yAKhlPLBR FsuThcQabe6qbyu4MQIuZ+yRZTbDxYIoJXmXtIz08v0lVv3QP0xh+IuhoxOqcbvCsxpE tjP0SKR1f4zv1f+z+BJbp+p3PkbPS7gXmH/hLxy97rRsEv+8GrD8QlICs4/Y7a/DCaF+ mk/Bvigw8Ercsj8Jz+deKZ+nWPcHKRulWMM9ysddvHJVkqzmJa0U8AlLzYpDCMLutOtN +9UQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=UCXANsHT; 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 f12si2030775edx.142.2020.08.21.10.58.16; Fri, 21 Aug 2020 10:58:40 -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=@linux-foundation.org header.s=google header.b=UCXANsHT; 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 S1726967AbgHURzV (ORCPT + 99 others); Fri, 21 Aug 2020 13:55:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726867AbgHURzS (ORCPT ); Fri, 21 Aug 2020 13:55:18 -0400 Received: from mail-lf1-x141.google.com (mail-lf1-x141.google.com [IPv6:2a00:1450:4864:20::141]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1BB7C061574 for ; Fri, 21 Aug 2020 10:55:17 -0700 (PDT) Received: by mail-lf1-x141.google.com with SMTP id c15so1329328lfi.3 for ; Fri, 21 Aug 2020 10:55:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=m4V8fZt1LIyKWUpK//pHmx+UE2cyQI+1k+0DpARcdKs=; b=UCXANsHTDuglcuMoaPQrO2SPcgEY6vG1EKV1rTav9qeDhjuPUXwzOzAWO97GPtjQDH vnro5pnl96FGhRTeEBpt/OEZjQu48BweLMmP5gUzvXiHcfKKCnzSqCp8rihnevc6AQ5B Ceo5/n8nq9tRTr1tnI08EiIZY6bxL404FbH6M= 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=m4V8fZt1LIyKWUpK//pHmx+UE2cyQI+1k+0DpARcdKs=; b=nPmsr5/N2kmO+NzJpmJ/bvNwLWYidC20EYWLv4kNNgC9Akg43XDCm5bBJc2LFW1/eu Mz8HGaAkaoyBNYh3SDi88iZqtZde6RRr/eCCMBLxxDWmG50IVK9VKO3ykF8FABGnYzCh acLykC52mgDginik79N4lpflF4WuRMpnUtLzKwgD8JEnBMkKdk5qft5m2ZQ9y89AAjGb FGuUNrKJM/bPtmIpUa/UiRBgsN+G0PYPzHH0cdHFm1T1QJHMzzldChlq6kLNwsa+nTng uccNcx9uk92B174MjmI75xCwcff/VcQOVB2+Wy9NEwWp77hNlbtf7lZr0VlM4IdbSUoC GKbQ== X-Gm-Message-State: AOAM531Ls99Ps18oRmLtzR89xxATJ33jFEn5nclAhT3I3eKTTHY99Cj6 b99WRH2Rbaz/qTc18oqTjjLv8SNFN33vzA== X-Received: by 2002:ac2:5e2c:: with SMTP id o12mr1894921lfg.71.1598032515439; Fri, 21 Aug 2020 10:55:15 -0700 (PDT) Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com. [209.85.208.169]) by smtp.gmail.com with ESMTPSA id y26sm508804ljm.132.2020.08.21.10.55.13 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 21 Aug 2020 10:55:14 -0700 (PDT) Received: by mail-lj1-f169.google.com with SMTP id w14so2786166ljj.4 for ; Fri, 21 Aug 2020 10:55:13 -0700 (PDT) X-Received: by 2002:a05:651c:503:: with SMTP id o3mr2203972ljp.312.1598032513384; Fri, 21 Aug 2020 10:55:13 -0700 (PDT) MIME-Version: 1.0 References: <76071c24-ec6f-7f7a-4172-082bd574d581@zytor.com> <20200818202407.GA3143683@rani.riverdale.lan> <20200818214146.GA3196105@rani.riverdale.lan> <20200820175617.GA604994@rani.riverdale.lan> <20200821172935.GA1411923@rani.riverdale.lan> In-Reply-To: <20200821172935.GA1411923@rani.riverdale.lan> From: Linus Torvalds Date: Fri, 21 Aug 2020 10:54:57 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 0/4] -ffreestanding/-fno-builtin-* patches To: Arvind Sankar Cc: Rasmus Villemoes , Nick Desaulniers , =?UTF-8?B?RMOhdmlkIEJvbHZhbnNrw70=?= , Eli Friedman , "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" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Aug 21, 2020 at 10:29 AM Arvind Sankar wrote: > > The no-builtin- options _don't_ disable > __builtin_ functions. They remove the default definition of foo() as > __builtin_foo(). Oh, ok, then it's fine. > Take the problem that instigated this thread. __builtin_stpcpy() doesn't > work in the kernel because the fallback, stpcpy(), isn't implemented. Right. The only problem is the - bogus - recognition of (or rewriting of) code patterns that the compiler recohnmizes. __builtin_stpcpy() itself is fine if somebody wants to use it - and has the fallback. But implicitly recognizing some code sequence and turning it into something else is the problem. > This is why I'm saying clang's no-builtin-foo option is useful for > embedded: it doesn't prevent the programmer using __builtin_foo(), it > prevents the _compiler_ using __builtin_foo() on its own. And that's fine. But it's apparently not what gcc does. > > So this is things like the compiler silently seeing "oh, you called > > your function 'free()', so we know that the stores you did to it are > > dead and we'll remove them". > > > > Or this is the compiler doing "Oh, you did four stores of zero in a > > row, and and you asked for size optimizations, so we'll turn those > > into a 'bzero()' call". > > This one is slightly different from the previous one. The first case is > really a call to __builtin_free(). No, the first case is a disgrace and a compiler bug. We've had a situation where gcc complained about a static function called "free()", without any header file inclusion, and then complained about it not matching its idea of what "free()" is. Which is pure and utter garbage. It's like you have a local variable "int free", and the compiler says "hey, this doesn't match the prototype that I know this name should have". It's BS. You just saw the user not just *use* that name, but *define* it, and do it in a scope where the complaint is irrelevant and stupid, and when we hadn't even included the header that would have resulted in conflicts. IOW, it's an example of a compiler that thinks "it knows better". It's a broken compiler. And it's an example of the kind of breakage that compilers absolutely shouldn't do. The second example is from clang doesn't something horribly horribly stupid. > This one is turning something that wasn't a function call into > __builtin_bzero(), and I would hope that no-builtin-bzero would stop it > as well. OTOH, the compiler is free to turn it into memset(), just like > it could for structure/array initializers. The whole "the compiler is free to do X" argument is pure BS. Stop repeating that bogus argument. Of COURSE a compiler can do whatever the hell it wants. That doesn't change the fact that certain things are broken beyond words and utterly stupid, and a compiler that does them is a *BAD* compiler. Turning four stores into a memset() is garbage. Just admit it, instead of trying to say that it's allowed. Technically a compiler can decode to simply not compile the kernel at all, because we do things that are outside a lot of standards. So the "technically allowed" is not an argument. Linus