There's no need to go through these steps if you're compiling the code yourself. If you want to override a library function like malloc, just define a function called malloc. Then make sure that the linker sees your function before the library function. For example, here I override pthread_create: <a href="https://github.com/scotts/streamflow/blob/master/override.c#L66" rel="nofollow">https://github.com/scotts/streamflow/blob/master/override.c#...</a><p>Note that I also figure out, at runtime, how to call the real version of pthread_create using the dlsym interface. I make sure that my pthread_create is the first one in the call chain by putting that object file before -lpthread when I link.<p>The LD_PRELOAD method is for when you <i>are not</i> compiling the code yourself. That is, the function you want to hijack is in a binary, and you can't re-compile that binary. Then you compile a shared library with your function, and use LD_PRELOAD to force the runtime linker to load your library first.