I want to intercept all file system access that occurs inside of dlopen(). At first, it would seem like LD_PRELOAD
or -Wl,-wrap,
would be viable solutions, but I have had trouble making them work due to some technical reasons:
ld.so has already mapped its own symbols by the time LD_PRELOAD is processed. It's not critical for me to intercept the initial loading, but the
_dl_*
worker functions are resolved at this time, so future calls go through them. I thinkLD_PRELOAD
is too late.Somehow
malloc
circumvents the issue above because themalloc()
inside of ld.so does not have a functionalfree()
, it just callsmemset()
.The file system worker functions, e.g.
__libc_read()
, contained inld.so
are static so I can't intercept them with-Wl,-wrap,__libc_read
.
This might all mean that I need to build my own ld.so
directly from source instead of linking it into a wrapper. The challenge there is that both libc
and rtld-libc
are built from the same source. I know that the macro IS_IN_rtld
is defined when building rtld-libc
, but how can I guarantee that there is only one copy of static data structures while still exporting a public interface function? (This is a glibc build system question, but I haven't found documentation of these details.)
Are there any better ways to get inside dlopen()
?
Note: I can't use a Linux-specific solution like FUSE
because this is for minimal "compute-node" kernels that do not support such things.