LD_PRELOAD just can intercept dynamic symbols, is there any way which can intercept the normal symbols?
nm -D /usr/lib64/libc-2.17.so shows the dynamic symbols. And these symbols can be intercepted by using LD_PRELOAD.
But I have no idea how to intercept normal symbols(nm libc-2.17.so shows all normal symbols).
eg: __opendirat is a normal symbol not a dynamic symbol, I have tried to re-write the function in my own test.cpp and used LD_PRELOAD to intercept. But there is an error when using LD_DEBUG:
/lib/libc.so.6: error: symbol lookup error: undefined symbol: __opendirat (fatal)
The terms that you are using are a bit confusing.
There are two main kinds of symbol visibility. Local (for instance "t" for functions as shown ny
nm) and global or extern (for instance "T" for functions as shown bynm).Since local functions can only be called from within the library they use static linkage.
Global functions can be called from outside of the library, and so they have dynamic linkage.
It's not possible (at least not with simple techniques like LD_PRELOAD) to replace static functions in dynamic libraries.