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

tito farmatito at tiscali.it
Thu Jan 29 19:57:30 UTC 2015


On Thursday 29 January 2015 19:09:33 Matthias Andree wrote:
> 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.
> 
> 
> 

Hi,
maybe we could try it the in another way:

use bb_memcpy in the code

and put in libbb.h or another .h file

#ifdef  HAVE_MEMPCPY
#define bb_mempcpy                   mempcpy
#else
void bb_mempcpy(void *dest, const void *src, size_t len)
{
       return memcpy(dest, src, len) + len;
}
#endif

just my 0.2 cents.

Ciao, 
Tito


More information about the busybox mailing list