Question

I am trying to LD_PRELOAD functions such as mmap, read, open, clone etc..., but while some function do get LD_PRELOADed successfully, others don't. For example mmap, read and open are perfectly being preloaded but clone is not, while I know for sure clone is being called from my program as reported by strace, since I'm using pthreads. What is the reason for clone not being LD_PRELOADed here?

Was it helpful?

Solution

strace shows system calls; LD_PRELOAD overrides (C library) functions. This probably indicates that the clone system call is being invoked by a different function, without going through the clone function symbol (e.g. through internal linkage inside the C library, or invoking the system call directly).

Indeed, clone is not a Posix library function; it is a Linux implementation detail that happens to be exposed. The man page says:

The clone() and sys_clone calls are Linux-specific and should not be used in programs intended to be portable.

Instead you should LD_PRELOAD-override pthread_create etc.; on other platforms they may be implemented without clone.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top