This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: __builtin_* expansion to outcalls vs name space issues


On Tue, 5 Feb 2013, Roland McGrath wrote:

> If any call to __builtin_foobar can be expected sometimes to generate a
> call to foobar, then what's the point of having the __builtin_foobar names
> in the first place?

It allows the compiler optimizations to be used, where beneficial, in 
cases where the compiler could not assume anything about a direct call to 
foobar (for example, in a kernel built with -ffreestanding, only the 
__builtin_* names are built in, and it's reasonable then to have selective 
macro definitions of foobar to __builtin_foobar in cases where the kernel 
defines and uses the function with the standard semantics).  (It also 
allows uses in static initializers, when the call can be folded to a 
constant.)

The GCC documentation says:

  GCC includes built-in versions of many of the functions in the standard
  C library.  The versions prefixed with @code{__builtin_} are always
  treated as having the same meaning as the C library function even if you
  specify the @option{-fno-builtin} option.  (@pxref{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.

> > Yes.  Declaring mempcpy with __asm__ ("__mempcpy") should cause 
> > __builtin_mempcpy to generate a call to __mempcpy.
> 
> I cannot figure out how to make that happen.  Can you post a patch that
> accomplishes this?

I haven't tested this in the form of a glibc patch, but for example

#include <stddef.h>

void *mempcpy (void *dest, const void *src, size_t n) __asm__ ("__mempcpy");

void *
wrap_builtin_memcpy (void *dest, const void *src, size_t n)
{
  return __builtin_mempcpy (dest, src, n);
}

generates such a call to __mempcpy with the 4.6 (Ubuntu) and 4.7 (vanilla 
FSF GCC) compilers I have to hand.

-- 
Joseph S. Myers
joseph@codesourcery.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]