1.23.0 FreeBSD build fails: 1 showstopper mempcpy(), 1 sendfile() incompat.

Matthias Andree mandree at FreeBSD.org
Thu Jan 29 18:09:33 UTC 2015


Am 29.01.2015 um 16:40 schrieb Denys Vlasenko:
> On Wed, Jan 28, 2015 at 10:50 PM, Matthias Andree <mandree at freebsd.org> wrote:
>>> Matthias, please get current git, uncomment this line,
>>> and confirm that it builds for you. Let me know the version
>>> of FreeBSD which needs it (newer ones may grow their own
>>> mempcpy(), we need to be ready for that).
>>
>> That works.
>>
>> Additionally:
>>
>> 1. You need to add #include <string.h> to obtain memcpy() in the
>> replacement, and
> 
> Ok...
> 
>> 2. also add -fno-builtin-mempcpy to the compiler flags to quench
>> -Wshadow warnings that the mempcpy() shadows a GCC built-in.
> 
> I'm confused.
>  Do you _have_ mempcpy (the gcc-builtin one) provided by your toolchain,
> or do you NOT have mempcpy?
> 

Denys,

that got me stumped for a moment, too.  GCC knows the mempcpy() builtin
(depends on the language settings, default -std=gnu90 as of GCC 4.8),
but FreeBSD's libc does not offer the mempcpy() implementation (depends
on its libc).

Now, GCC builtins reserve the right to resort to library callsif there
is no optimization gained. Official wording cited below.

(Remember that GCC defaults to -std=gnu90 which is why the mempcpy()
extension/builtin is visible internally within the compiler, triggering
the warning.)

So, upon actual code generation, GCC figures the code doesn't benefit
from the builtin and emits a regular call to memcpy() instead.  I
confirmed that by compiling with -save-temps and reading the resulting
.s assembly file, by looking at the nm -s output, and it's evident the
linker error we were getting.

I have not found a way to force GCC to use its builtin and avoid the
call.  -ffreestanding suggests itself, but is insufficient.  Even
patching the source to read ... = __builtin_memcpy() causes GCC to emit
a call to memcpy.


Where it is an adequate substitute, FreeBSD has been providing stpcpy()
for over 13 years (since FreeBSD 4.4, released in 2001-09) and all
supported FreeBSD releases carry it.  It is part of The Open Group Base
Specifications since Issue 7.


Quoting the GCC 4.8.4 info pages:

> 3.4 Options Controlling C Dialect
[...]
> `-fno-builtin'
> `-fno-builtin-FUNCTION'
>      Don't recognize built-in functions that do not begin with
>      `__builtin_' as prefix.  *Note Other built-in functions provided
>      by GCC: Other Builtins, for details of the functions affected,
>      including those which are not built-in functions when `-ansi' or
>      `-std' options for strict ISO C conformance are used because they
>      do not have an ISO standard meaning.
> 
>      GCC normally generates special code to handle certain built-in
>      functions more efficiently; for instance, calls to `alloca' may
>      become single instructions which adjust the stack directly, and
>      calls to `memcpy' may become inline copy loops.  The resulting
>      code is often both smaller and faster, but since the function
>      calls no longer appear as such, you cannot set a breakpoint on
>      those calls, nor can you change the behavior of the functions by
>      linking with a different library.  
[...]
>      With the `-fno-builtin-FUNCTION' option only the built-in function
>      FUNCTION is disabled.  FUNCTION must not begin with `__builtin_'.
>      If a function is named that is not built-in in this version of
>      GCC, this option is ignored. 

[...]

> 6.55 Other Built-in Functions Provided by GCC
[...]
>  GCC includes built-in versions of many of the functions in the standard
> C library.  The versions prefixed with `__builtin_' are always treated
> as having the same meaning as the C library function even if you
> specify the `-fno-builtin' option.  (*note C Dialect Options::) Many of
> these functions are only optimized in certain cases; if they are not
> optimized in a particular case, a call to the library function is
> emitted.

>  Outside strict ISO C mode (`-ansi', `-std=c90', `-std=c99' or
> `-std=c11'), the functions `_exit', `alloca', `bcmp', `bzero',
[...]
> `jnf', `jnl', `jn', `lgammaf_r', `lgammal_r', `lgamma_r', `mempcpy',
[...]
> `strcasecmp', `strdup', `strfmon', `strncasecmp', `strndup', `toascii',
> `y0f', `y0l', `y0', `y1f', `y1l', `y1', `ynf', `ynl' and `yn' may be
> handled as built-in functions.  All these functions have corresponding
> versions prefixed with `__builtin_', which may be used even in strict
> C90 mode.

Hope that helps.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: OpenPGP digital signature
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20150129/5659ed60/attachment.asc>


More information about the busybox mailing list