I'm currently working on a project where I need to track the usage of several system calls and low-level functions like mmap
, brk
, sbrk
. So far, I've been doing this using function interposition: I write a wrapper function with the same name as the function I'm replacing (mmap
for example), and I load it in a program by setting the LD_PRELOAD
environment variable. I call the real function through a pointer that I load with dlsym
.
Unfortunately, one of the functions I want to wrap, sbrk
, is used internally by dlsym
, so the program crashes when I try to load the symbol. sbrk
is not a system call in Linux, so I can't simply use syscall
to call it indirectly.
So my question is, how can I call a library function from a wrapper function of the same name without using dlsym
? Is there any compiler trick (using gcc) that lets me refer to the original function?