Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 4 Aug 2017 11:35:16 +1000 (EST)
From:      Bruce Evans <brde@optusnet.com.au>
To:        Joerg Sonnenberger <joerg@bec.de>
Cc:        Bruce Evans <brde@optusnet.com.au>, Ngie Cooper <ngie@freebsd.org>,  svn-src-head@freebsd.org, svn-src-all@freebsd.org,  src-committers@freebsd.org
Subject:   Re: svn commit: r321969 - in head/sys/boot: arm/at91/libat91 arm/ixp425/boot2 i386/boot2
Message-ID:  <20170804111543.V1186@besplex.bde.org>
In-Reply-To: <20170803124627.GB2734@britannica.bec.de>
References:  <201708030527.v735R5dg041043@repo.freebsd.org> <20170803173421.C2203@besplex.bde.org> <20170803124627.GB2734@britannica.bec.de>

next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, 3 Aug 2017, Joerg Sonnenberger wrote:

> On Thu, Aug 03, 2017 at 05:53:43PM +1000, Bruce Evans wrote:
>> Freestanding versions (static and otherwise) cause problems with builtins.
>> -ffreestanding turns off all builtins.  The static memcpy used to be
>> ifdefed so as to use __builtin_memcpy instead of the static one if the
>> compiler is gcc.  That apparently broke with gcc-4.2, since the builtin
>> will call libc memcpy() in some cases, although memcpy() is unavailable
>> in the freestanding case.
>
> GCC always had a requirement that freestanding environment must provide
> certain functions (memcpy, memmove, memset, memcmp). At least memcpy and
> memset are regulary used for certain code constructs. While most calls
> will be inlined, it is not required.

I had forgotten about that bug.  boot2 doesn't have many fancy code
constructs, but it might have struct copying and gcc uses memcpy for
copying large structs.  clang-4.0 has the same bug.  Testing showed
1 bug nearby: for newer CPUs, it generates large code with several
movups's for small struct copies.  The bug is that -Os doesn't turn
this off.  But boot2 uses -march=i386 which does turn this off.  For
not so new CPUs like core2 where movups is slower than movaps but
movaps is unusable because the structs might not be aligned, it
normally generates large code with moves through integer registers,
but -Os works to turn this off.

The change for gcc-4.2 was apparently to support this.  The static
memcpy is not quite compatible, but is close enough and you can check
this in the generated code.  The problem is that it should be re-checked
for every change in the source code and compiler.

Bruce



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20170804111543.V1186>