Hi Finn,

On Wed, Jan 16, 2019 at 1:39 AM Finn Thain <[email protected]> wrote:
> On Mon, 14 Jan 2019, Geert Uytterhoeven wrote:
> > On Fri, Dec 21, 2018 at 7:21 AM Finn Thain <[email protected]> 
> > 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/[email protected]/
> > > > >
> > > > > 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...

Probably there were some interactions with old compilers.
Note that some of the changes above were made when gcc 3.x was
still in wide use.

Oh, looks like I tried that a while ago, too
https://www.spinics.net/lists/linux-kbuild/msg07656.html

> > > 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.

Indeed.

> > 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.

It built fine for me with both 7.3.0 and 8.2.0.

Nevertheless, I've applied your patch to a separate branch, and pushed
it to kernel.org, so the autobuilders can exercise it.

Thanks!

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

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