This is the mail archive of the systemtap@sourceware.org mailing list for the systemtap 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: Question regarding userspace tracing memcpy in glibc


On Fri, Nov 26, 2010 at 11:58 PM, Frank Ch. Eigler <fche@redhat.com> wrote:
>
> holger wrote:
>
>> [...]
>> I have an application that is spending some time copying structs with
>> memcpy. I wanted to use systemtap to figure out who is calling memcpy,
>> [...]
>> $ stap -e 'probe process("/lib/libc.so.6").function("memcpy") {printf();...}'
>> [...]
>> $ stap -e 'probe process("/lib/libc.so.6").function("__memcpy_ssse3")..
>> [...]
>
> Right.  These are assembly language functions, with no dwarf data,
> just a symbol table entry.  We ought to be able to attach to them
> anyway though, equivalently to ...

I believe the problem is much worse.  Usually no functions are called
for memcpy (GCC implements them as intrinsics).  E.g. info node
"(gcc)C Dialect Options" says (while explaining -fno-builtin, a switch
to turn off this behaviour):

     GCC normally generates special code to handle certain built-in
     functions more efficiently; for instance, calls to `alloca' may
     become single instructions that 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.

Compiling some short test programs (on x86-64) with memcpy show a
variety of ways to implement memcpy, none of which involves calling a
function.  Indeed, when the length of a short buffer is known at
compile time, GCC simply generates an unrolled loop of MOVQ
instructions!

[...]

HTH,
-- 
Ariel.


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