From: "H. Peter Anvin" <hpa@zytor.com>
To: Nick Desaulniers <ndesaulniers@google.com>,
Masahiro Yamada <masahiroy@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>
Cc: "Michal Marek" <michal.lkml@markovi.net>,
linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org,
"Kees Cook" <keescook@chromium.org>,
"Tony Luck" <tony.luck@intel.com>,
"Dmitry Vyukov" <dvyukov@google.com>,
"Michael Ellerman" <mpe@ellerman.id.au>,
"Joe Perches" <joe@perches.com>,
"Joel Fernandes" <joel@joelfernandes.org>,
"Daniel Axtens" <dja@axtens.net>,
"Arvind Sankar" <nivedita@alum.mit.edu>,
"Andy Shevchenko" <andriy.shevchenko@linux.intel.com>,
"Alexandru Ardelean" <alexandru.ardelean@analog.com>,
"Yury Norov" <yury.norov@gmail.com>,
x86@kernel.org, "Ard Biesheuvel" <ardb@kernel.org>,
"Paul E . McKenney" <paulmck@kernel.org>,
"Daniel Kiper" <daniel.kiper@oracle.com>,
"Bruce Ashfield" <bruce.ashfield@gmail.com>,
"Marco Elver" <elver@google.com>,
"Vamshi K Sthambamkadi" <vamshi.k.sthambamkadi@gmail.com>,
"Andi Kleen" <ak@suse.de>,
"Linus Torvalds" <torvalds@linux-foundation.org>,
"Dávid Bolvanský" <david.bolvansky@gmail.com>,
"Eli Friedman" <efriedma@quicinc.com>
Subject: Re: [PATCH 0/4] -ffreestanding/-fno-builtin-* patches
Date: Mon, 17 Aug 2020 15:44:31 -0700 [thread overview]
Message-ID: <fae91af3-4e08-a929-e5c3-25271ad7324b@zytor.com> (raw)
In-Reply-To: <20200817220212.338670-1-ndesaulniers@google.com>
On 2020-08-17 15:02, Nick Desaulniers wrote:
> -ffreestanding typically inhibits "libcall optimizations" where calls to
> certain library functions can be replaced by the compiler in certain
> cases to calls to other library functions that may be more efficient.
> This can be problematic for embedded targets that don't provide full
> libc implementations.
>
> -ffreestanding inhibits all such optimizations, which is the safe
> choice, but generally we want the optimizations that are performed. The
> Linux kernel does implement a fair amount of libc routines. Instead of
> -ffreestanding (which makes more sense in smaller images like kexec's
> purgatory image), prefer -fno-builtin-* flags to disable the compiler
> from emitting calls to functions which may not be defined.
>
> If you see a linkage failure due to a missing symbol that's typically
> defined in a libc, and not explicitly called from the source code, then
> the compiler may have done such a transform. You can either implement
> such a function (ie. in lib/string.c) or disable the transform outright
> via -fno-builtin-* flag (where * is the name of the library routine, ie.
> -fno-builtin-bcmp).
>
This is arguably exactly the wrong way around.
The way this *should* be done is by opt-in, not opt-out, which by almost
definition ends up being a game of whack-a-mole, like in this case
stpcpy(). Furthermore, it is unlikely that people will remember what
options to flip when and if stpcpy() happens to be implemented in the
kernel.
The problem here is twofold:
1. The user would be expected to know what kind of the optimizations the
compiler can do on what function, which is private knowledge to the
compiler.
2. The only way to override -fno-builtin is by a header file with macros
overriding the function names with __builtin, but that doesn't tell the
compiler proper anything about the execution environment.
So the Right Thing is for the compiler authors to change the way
-ffreestanding works. -ffreestanding means, by definition, that there
are no library calls (other than libgcc or whatever else is supplied
with the compiler) that the compiler can call. That is currently an
all-or-nothing choice, or at least one choice per C standard implemented.
Instead, a compile job with -ffreestanding should be able to provide a
list of standard C functions that the compiler may call, and thus the
compiler actually can do the right thing depending on which exact
functions it would consider calling. This list is probably most easily
supplied in the form of a header file with #pragma directives.
-hpa
next prev parent reply other threads:[~2020-08-17 22:45 UTC|newest]
Thread overview: 65+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-17 22:02 [PATCH 0/4] -ffreestanding/-fno-builtin-* patches Nick Desaulniers
2020-08-17 22:02 ` [PATCH 1/4] Makefile: add -fno-builtin-stpcpy Nick Desaulniers
2020-08-17 22:31 ` H. Peter Anvin
2020-08-17 23:36 ` Nick Desaulniers
2020-08-18 19:21 ` Kees Cook
2020-08-18 7:10 ` Ard Biesheuvel
2020-08-18 7:25 ` Greg KH
2020-08-18 7:29 ` Ard Biesheuvel
2020-08-18 7:34 ` Greg KH
2020-08-18 19:23 ` Kees Cook
2020-08-17 22:02 ` [PATCH 2/4] Revert "lib/string.c: implement a basic bcmp" Nick Desaulniers
2020-08-18 5:44 ` Nathan Chancellor
2020-08-18 18:00 ` Nick Desaulniers
2020-08-18 19:24 ` Kees Cook
2020-08-17 22:02 ` [PATCH 3/4] x86/boot: use -fno-builtin-bcmp Nick Desaulniers
2020-08-18 19:24 ` Kees Cook
2020-08-17 22:02 ` [PATCH 4/4] x86: don't build CONFIG_X86_32 as -ffreestanding Nick Desaulniers
2020-08-18 19:24 ` Kees Cook
2021-01-07 0:27 ` Fangrui Song
2020-08-17 22:44 ` H. Peter Anvin [this message]
2020-08-18 17:56 ` [PATCH 0/4] -ffreestanding/-fno-builtin-* patches Nick Desaulniers
2020-08-18 19:02 ` H. Peter Anvin
2020-08-18 19:13 ` Linus Torvalds
2020-08-18 19:25 ` Nick Desaulniers
2020-08-18 19:58 ` Nick Desaulniers
2020-08-19 12:19 ` Clement Courbet
2020-08-18 20:24 ` Arvind Sankar
2020-08-18 20:27 ` Nick Desaulniers
2020-08-18 20:58 ` Nick Desaulniers
2020-08-18 21:41 ` Arvind Sankar
2020-08-18 21:51 ` Dávid Bolvanský
2020-08-18 21:59 ` Nick Desaulniers
2020-08-18 22:05 ` Dávid Bolvanský
2020-08-18 23:22 ` Nick Desaulniers
2020-08-20 14:56 ` Rasmus Villemoes
2020-08-20 17:56 ` Arvind Sankar
2020-08-20 18:05 ` Dávid Bolvanský
2020-08-20 23:33 ` Linus Torvalds
2020-08-21 17:29 ` Arvind Sankar
2020-08-21 17:54 ` Linus Torvalds
2020-08-21 18:02 ` Linus Torvalds
2020-08-21 19:14 ` Arvind Sankar
2020-08-21 19:23 ` Linus Torvalds
2020-08-21 19:57 ` Arvind Sankar
2020-08-21 20:03 ` Peter Zijlstra
2020-08-21 21:39 ` Linus Torvalds
2020-08-22 0:12 ` Nick Desaulniers
2020-08-22 12:20 ` David Laight
2020-08-21 6:45 ` Rasmus Villemoes
2020-08-24 15:57 ` Masahiro Yamada
2020-08-24 17:34 ` Arvind Sankar
2020-08-25 7:10 ` Nick Desaulniers
2020-08-25 7:31 ` Nick Desaulniers
2020-08-25 12:28 ` Masahiro Yamada
2020-08-25 14:02 ` Nick Desaulniers
2020-08-26 13:28 ` Masahiro Yamada
2020-08-18 21:53 ` David Laight
2020-08-20 22:41 ` H. Peter Anvin
2020-08-20 23:17 ` Arvind Sankar
2020-08-18 19:35 ` Nick Desaulniers
2020-08-18 22:25 ` Arvind Sankar
2020-08-18 22:59 ` Nick Desaulniers
2020-08-18 23:51 ` Arvind Sankar
2020-08-19 0:20 ` Arvind Sankar
2020-08-19 8:26 ` David Laight
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=fae91af3-4e08-a929-e5c3-25271ad7324b@zytor.com \
--to=hpa@zytor.com \
--cc=ak@suse.de \
--cc=akpm@linux-foundation.org \
--cc=alexandru.ardelean@analog.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=ardb@kernel.org \
--cc=bp@alien8.de \
--cc=bruce.ashfield@gmail.com \
--cc=daniel.kiper@oracle.com \
--cc=david.bolvansky@gmail.com \
--cc=dja@axtens.net \
--cc=dvyukov@google.com \
--cc=efriedma@quicinc.com \
--cc=elver@google.com \
--cc=joe@perches.com \
--cc=joel@joelfernandes.org \
--cc=keescook@chromium.org \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=masahiroy@kernel.org \
--cc=michal.lkml@markovi.net \
--cc=mingo@redhat.com \
--cc=mpe@ellerman.id.au \
--cc=ndesaulniers@google.com \
--cc=nivedita@alum.mit.edu \
--cc=paulmck@kernel.org \
--cc=tglx@linutronix.de \
--cc=tony.luck@intel.com \
--cc=torvalds@linux-foundation.org \
--cc=vamshi.k.sthambamkadi@gmail.com \
--cc=x86@kernel.org \
--cc=yury.norov@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox