Re: [PATCH 0/4] -ffreestanding/-fno-builtin-* patches

2020-08-26 Thread Masahiro Yamada
On Tue, Aug 25, 2020 at 11:02 PM Nick Desaulniers wrote: > > On Tue, Aug 25, 2020 at 5:30 AM Masahiro Yamada wrote: > > > > On Tue, Aug 25, 2020 at 4:10 PM Nick Desaulniers > > wrote: > > > > > > Masahiro, are you implying that we shouldn't take the > > > -fno-builtin-stpcpy patch, because Clang

Re: [PATCH 0/4] -ffreestanding/-fno-builtin-* patches

2020-08-25 Thread Nick Desaulniers
On Tue, Aug 25, 2020 at 5:30 AM Masahiro Yamada wrote: > > On Tue, Aug 25, 2020 at 4:10 PM Nick Desaulniers > wrote: > > > > 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

Re: [PATCH 0/4] -ffreestanding/-fno-builtin-* patches

2020-08-25 Thread Masahiro Yamada
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 tha

Re: [PATCH 0/4] -ffreestanding/-fno-builtin-* patches

2020-08-25 Thread Nick Desaulniers
On Tue, Aug 25, 2020 at 12:10 AM 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 th

Re: [PATCH 0/4] -ffreestanding/-fno-builtin-* patches

2020-08-25 Thread Nick Desaulniers
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 G

Re: [PATCH 0/4] -ffreestanding/-fno-builtin-* patches

2020-08-24 Thread Arvind Sankar
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 fro

Re: [PATCH 0/4] -ffreestanding/-fno-builtin-* patches

2020-08-24 Thread Masahiro Yamada
On Wed, Aug 19, 2020 at 6:41 AM Arvind Sankar wrote: > > 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

RE: [PATCH 0/4] -ffreestanding/-fno-builtin-* patches

2020-08-22 Thread David Laight
> For more context for folks at home eating popcorn and enjoying the > show: > https://github.com/ClangBuiltLinux/linux/issues/876#issuecomment-613049480. > And that was specifically with KASAN enabled and doesn't appear to be > common behavior in clang otherwise (higher threshold). Why the > heur

Re: [PATCH 0/4] -ffreestanding/-fno-builtin-* patches

2020-08-21 Thread Nick Desaulniers
On Fri, Aug 21, 2020 at 2:39 PM Linus Torvalds wrote: > > On Fri, Aug 21, 2020 at 12:57 PM Arvind Sankar wrote: > > > > Look, four stores into memset(), yeah that's a bit weird. I didn't think > > you meant "four" literally. But in any case, that has nothing to do with > > the topic at hand. It w

Re: [PATCH 0/4] -ffreestanding/-fno-builtin-* patches

2020-08-21 Thread Linus Torvalds
On Fri, Aug 21, 2020 at 12:57 PM Arvind Sankar wrote: > > Look, four stores into memset(), yeah that's a bit weird. I didn't think > you meant "four" literally. But in any case, that has nothing to do with > the topic at hand. It would be just as bad if it was a 16-byte structure > being initializ

Re: [PATCH 0/4] -ffreestanding/-fno-builtin-* patches

2020-08-21 Thread Peter Zijlstra
On Fri, Aug 21, 2020 at 03:57:12PM -0400, Arvind Sankar wrote: > closely: check out what gcc does to initialize a 7-character array with > zeros at -Os. You do know that 's' stands for 'stupid', right? -Os is infamous for generating atrocious crap.

Re: [PATCH 0/4] -ffreestanding/-fno-builtin-* patches

2020-08-21 Thread Arvind Sankar
On Fri, Aug 21, 2020 at 10:54:57AM -0700, Linus Torvalds wrote: > On Fri, Aug 21, 2020 at 10:29 AM Arvind Sankar wrote: > > > > 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. >

Re: [PATCH 0/4] -ffreestanding/-fno-builtin-* patches

2020-08-21 Thread Linus Torvalds
On Fri, Aug 21, 2020 at 12:15 PM Arvind Sankar wrote: > > How are you testing it? > > https://godbolt.org/z/eahdGn Ugh. I tested the reverse thing - that the builtin is still available for manual use despite the -fno-builtin. Because I - stupidly - assumed that fno-builtin would do *something*.

Re: [PATCH 0/4] -ffreestanding/-fno-builtin-* patches

2020-08-21 Thread Arvind Sankar
On Fri, Aug 21, 2020 at 11:02:08AM -0700, Linus Torvalds wrote: > On Fri, Aug 21, 2020 at 10:54 AM Linus Torvalds > wrote: > > > > On Fri, Aug 21, 2020 at 10:29 AM Arvind Sankar > > wrote: > > > > > > This is why I'm saying clang's no-builtin-foo option is useful for > > > embedded: it doesn't p

Re: [PATCH 0/4] -ffreestanding/-fno-builtin-* patches

2020-08-21 Thread Linus Torvalds
On Fri, Aug 21, 2020 at 10:54 AM Linus Torvalds wrote: > > On Fri, Aug 21, 2020 at 10:29 AM Arvind Sankar wrote: > > > > 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 _

Re: [PATCH 0/4] -ffreestanding/-fno-builtin-* patches

2020-08-21 Thread Linus Torvalds
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

Re: [PATCH 0/4] -ffreestanding/-fno-builtin-* patches

2020-08-21 Thread Arvind Sankar
On Thu, Aug 20, 2020 at 04:33:03PM -0700, Linus Torvalds wrote: > On Thu, Aug 20, 2020 at 10:56 AM Arvind Sankar wrote: > > > > Clang's interpretation is more useful for embedded, since you can use > > -fno-builtin-foo and avoid calling __builtin_foo directly, and be > > guaranteed that there will

Re: [PATCH 0/4] -ffreestanding/-fno-builtin-* patches

2020-08-20 Thread Rasmus Villemoes
On 20/08/2020 19.56, Arvind Sankar wrote: > On Thu, Aug 20, 2020 at 04:56:02PM +0200, Rasmus Villemoes wrote: >> On 18/08/2020 23.41, Arvind Sankar wrote: >>> >>> Note that -fno-builtin-foo seems to mean slightly different things in >>> clang and gcc. From experimentation, clang will neither optimi

Re: [PATCH 0/4] -ffreestanding/-fno-builtin-* patches

2020-08-20 Thread Linus Torvalds
On Thu, Aug 20, 2020 at 10:56 AM Arvind Sankar wrote: > > Clang's interpretation is more useful for embedded, since you can use > -fno-builtin-foo and avoid calling __builtin_foo directly, and be > guaranteed that there will be no calls to foo that you didn't write > explicitly (outside of memcpy/

Re: [PATCH 0/4] -ffreestanding/-fno-builtin-* patches

2020-08-20 Thread Arvind Sankar
On Thu, Aug 20, 2020 at 03:41:33PM -0700, H. Peter Anvin wrote: > > I would prefer this to be a #pragma for a header file, rather than > having a very long command line for everything... > > -hpa > There is @option_file, though.

Re: [PATCH 0/4] -ffreestanding/-fno-builtin-* patches

2020-08-20 Thread H. Peter Anvin
On 2020-08-18 13:58, 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:

Re: [PATCH 0/4] -ffreestanding/-fno-builtin-* patches

2020-08-20 Thread Dávid Bolvanský
Yeah, gcc is doing weird things here : ( It is kinda sad that same flag does different things with gcc and clang. > Dňa 20. 8. 2020 o 19:56 užívateľ Arvind Sankar > napísal: > > On Thu, Aug 20, 2020 at 04:56:02PM +0200, Rasmus Villemoes wrote: >>> On 18/08/2020 23.41, Arvind Sankar wrote: >

Re: [PATCH 0/4] -ffreestanding/-fno-builtin-* patches

2020-08-20 Thread Arvind Sankar
On Thu, Aug 20, 2020 at 04:56:02PM +0200, Rasmus Villemoes wrote: > On 18/08/2020 23.41, Arvind Sankar wrote: > > > > 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 optimiz

Re: [PATCH 0/4] -ffreestanding/-fno-builtin-* patches

2020-08-20 Thread Rasmus Villemoes
On 18/08/2020 23.41, Arvind Sankar wrote: > 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 Torval

Re: [PATCH 0/4] -ffreestanding/-fno-builtin-* patches

2020-08-19 Thread Clement Courbet
On Tue, Aug 18, 2020 at 9:58 PM Nick Desaulniers wrote: On Tue, Aug 18, 2020 at 12:25 PM Nick Desaulniers wrote: > > On Tue, Aug 18, 2020 at 12:19 PM Linus Torvalds > wrote: > > > > And honestly, a compiler that uses 'bcmp' is just broken. WTH? It's > > the year 2020, we don't use bcmp. It's th

RE: [PATCH 0/4] -ffreestanding/-fno-builtin-* patches

2020-08-19 Thread David Laight
From: Arvind Sankar > Sent: 18 August 2020 23:26 ... > gcc-10 optimizes the generic memset implementation in there into a call > to memset. Now that's on x86 which doesn't use the generic > implementation, but this is just waiting to bite us. > > https://godbolt.org/z/6EhG15 Gah, if I want a call

Re: [PATCH 0/4] -ffreestanding/-fno-builtin-* patches

2020-08-18 Thread Arvind Sankar
On Tue, Aug 18, 2020 at 03:59:45PM -0700, Nick Desaulniers wrote: > On Tue, Aug 18, 2020 at 3:25 PM Arvind Sankar wrote: > > > > Another thing that needs to be fixed is that at least lib/string.c needs > > to be compiled with -ffreestanding. > > > > gcc-10 optimizes the generic memset implementati

Re: [PATCH 0/4] -ffreestanding/-fno-builtin-* patches

2020-08-18 Thread Arvind Sankar
On Tue, Aug 18, 2020 at 03:59:45PM -0700, Nick Desaulniers wrote: > On Tue, Aug 18, 2020 at 3:25 PM Arvind Sankar wrote: > > > > Another thing that needs to be fixed is that at least lib/string.c needs > > to be compiled with -ffreestanding. > > > > gcc-10 optimizes the generic memset implementati

Re: [PATCH 0/4] -ffreestanding/-fno-builtin-* patches

2020-08-18 Thread Nick Desaulniers
On Tue, Aug 18, 2020 at 3:05 PM Dávid Bolvanský wrote: > > st 19. 8. 2020 o 0:00 Nick Desaulniers napísal(a): > > > > On Tue, Aug 18, 2020 at 2:41 PM Arvind Sankar wrote: > > > > > > Note that -fno-builtin-foo seems to mean slightly different things in > > > clang and gcc. From experimentation,

Re: [PATCH 0/4] -ffreestanding/-fno-builtin-* patches

2020-08-18 Thread Nick Desaulniers
On Tue, Aug 18, 2020 at 3:25 PM Arvind Sankar wrote: > > Another thing that needs to be fixed is that at least lib/string.c needs > to be compiled with -ffreestanding. > > gcc-10 optimizes the generic memset implementation in there into a call > to memset. Now that's on x86 which doesn't use the g

Re: [PATCH 0/4] -ffreestanding/-fno-builtin-* patches

2020-08-18 Thread Arvind Sankar
On Mon, Aug 17, 2020 at 03:02:08PM -0700, 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 p

Re: [PATCH 0/4] -ffreestanding/-fno-builtin-* patches

2020-08-18 Thread Dávid Bolvanský
Here: https://godbolt.org/z/qjo5P6 st 19. 8. 2020 o 0:00 Nick Desaulniers napísal(a): > > On Tue, Aug 18, 2020 at 2:41 PM Arvind Sankar wrote: > > > > 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: > > > > >

Re: [PATCH 0/4] -ffreestanding/-fno-builtin-* patches

2020-08-18 Thread Nick Desaulniers
On Tue, Aug 18, 2020 at 2:41 PM Arvind Sankar wrote: > > 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

RE: [PATCH 0/4] -ffreestanding/-fno-builtin-* patches

2020-08-18 Thread David Laight
From: Nick Desaulniers > Sent: 18 August 2020 21:59 > > On Tue, Aug 18, 2020 at 1:27 PM Nick Desaulniers > wrote: ... > > > -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 d

Re: [PATCH 0/4] -ffreestanding/-fno-builtin-* patches

2020-08-18 Thread Dávid Bolvanský
So -fno-builtin-stpcpy is not ideal solution then.. gcc may implement this opt too and here we go again, red builds. We should either provide stpcpy implementation or fix few places and do not use sprintf there. > Dňa 18. 8. 2020 o 23:41 užívateľ Arvind Sankar > napísal: > > On Tue, Aug 18,

Re: [PATCH 0/4] -ffreestanding/-fno-builtin-* patches

2020-08-18 Thread Arvind Sankar
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

Re: [PATCH 0/4] -ffreestanding/-fno-builtin-* patches

2020-08-18 Thread Nick Desaulniers
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 semanti

Re: [PATCH 0/4] -ffreestanding/-fno-builtin-* patches

2020-08-18 Thread Nick Desaulniers
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 tim

Re: [PATCH 0/4] -ffreestanding/-fno-builtin-* patches

2020-08-18 Thread Arvind Sankar
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 co

Re: [PATCH 0/4] -ffreestanding/-fno-builtin-* patches

2020-08-18 Thread Nick Desaulniers
On Tue, Aug 18, 2020 at 12:25 PM Nick Desaulniers wrote: > > On Tue, Aug 18, 2020 at 12:19 PM 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 t

Re: [PATCH 0/4] -ffreestanding/-fno-builtin-* patches

2020-08-18 Thread Nick Desaulniers
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. Ah, ok then. Sorry I mischaracterized your position. > But I would like to go back > to the compiler authors and ge

Re: [PATCH 0/4] -ffreestanding/-fno-builtin-* patches

2020-08-18 Thread Nick Desaulniers
On Tue, Aug 18, 2020 at 12:19 PM 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

Re: [PATCH 0/4] -ffreestanding/-fno-builtin-* patches

2020-08-18 Thread Linus Torvalds
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 i

Re: [PATCH 0/4] -ffreestanding/-fno-builtin-* patches

2020-08-18 Thread H. Peter Anvin
On 2020-08-18 10:56, Nick Desaulniers wrote: >> >> 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 h

Re: [PATCH 0/4] -ffreestanding/-fno-builtin-* patches

2020-08-18 Thread Nick Desaulniers
On Mon, Aug 17, 2020 at 3:44 PM H. Peter Anvin wrote: > > 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

Re: [PATCH 0/4] -ffreestanding/-fno-builtin-* patches

2020-08-17 Thread H. Peter Anvin
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 embedd

[PATCH 0/4] -ffreestanding/-fno-builtin-* patches

2020-08-17 Thread Nick Desaulniers
-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 implementatio