On Mon, 14 Jan 2019, Geert Uytterhoeven wrote:

> On Fri, Dec 21, 2018 at 7:21 AM Finn Thain <fth...@telegraphics.com.au> wrote:
> > On Thu, 20 Dec 2018, John Paul Adrian Glaubitz wrote:
> > > On 12/20/18 12:16 AM, Finn Thain wrote:
> > > > Andreas said the error happened when the new compiler expanded a 
> > > > __bultin_strcmp call to a strcmp call. 
> > > > https://lore.kernel.org/lkml/87in513wbt....@igel.home/
> > > >
> > > > The new compiler seems to assume that a strcmp symbol exists in 
> > > > the final link. I don't see how that kind of assumption is valid 
> > > > here.
> > > >
> > > > So I think the real bug is the lack of -ffreestanding. That 
> > > > omission allows the compiler to assume that libc is available in 
> > > > the final link. (At least, I imagine that's what the compiler 
> > > > authors had in mind.) Anyway, the use of -ffreestanding certainly 
> > > > avoids this optimization.
> 
> Yeah, during the kernel history, several other architectures started 
> using -ffreestanding, to avoid similar replacements behind our back. So 
> there is definitely prior art for starting to use that.
> 

These commits are interesting.

72fbfb260197    [MIPS] Fix optimization for size build.
fec468b0c9e0    [PATCH] uml: add -ffreestanding to CFLAGS
6edfba1b33c7    [PATCH] x86_64: Don't define string functions to builtin
b2444d34a0e7    [XTENSA] Add freestanding option to CFLAGS

I get the impression that people were reluctant to use -ffreestanding...

> >
> > This patch seems to work fine but may have implications for both 680x0 
> > and Coldfire. It will make some optimizations unavailable but I 
> > haven't tried to measure that effect. It could be a hard sell if it 
> > harms performance.
> 
> With gcc 7.3.0, it increases the kernel image size for atari_defconfig 
> by ca. 300 bytes (which is an 0.01% increase). But -ffreestanding allows 
> to switch to gcc 8.2.0, which reduces the same kernel by ca 7.5 KiB 
> again.
> 

If there is a performance drop caused by -ffreestanding, perhaps some 
optimizations be done using semantic patches instead. I could imagine that 
most sensible optimizations involving libc calls would also make sense 
when written as high-level program transformations.

> Finn, can you please submit your patch with a proper SoB?

OK. -ffreestanding implies -fno-builtin, so we may need more of these:
#define foo(z) __builtin_foo(z)
...depending on the optimizations available in gcc 8.

-- 

> Thanks!
> 
> 
> Gr{oetje,eeting}s,
> 
>                         Geert
> 
> --
> Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- 
> ge...@linux-m68k.org
> 
> In personal conversations with technical people, I call myself a hacker. But
> when I'm talking to journalists I just say "programmer" or something like 
> that.
>                                 -- Linus Torvalds
> 

Reply via email to