I have an executable which links to a static library (.a).
I want to provide a hook by overriding a function part of this static
library.
Eg: I have a function "int blkstart(int i)" in this static library.
I want to override this by having another function which is exactly
similar in signature including name.
When somebody call this function, control should automatically come to
my overriddent function. Inside this function, based on certain
conditions, I would like to call the original function in the static
library.
I tried using dlsym and dlopen APIs under SUN Solaris, but it didn't
work as I suppose it is not meant for static library.
Also I think this is the reason why it didn't work with static lib:
Since static lib (.a) doesn't have identity at runtime like dlls, only
the first available symbol was taken by linker during linking time and
ignores any duplicate symbols available in any other
static libs. At runtime, there is no way we can get the address of the
duplicate
function residing in the static library. Even running "nm <exe>" shows
only one
symbol which is the overloaded one (as in the make file, I have .o
file ahead of
-l<static-lib>). Basically at runtime, dlsym() can never resolve the
duplicate function address as to start with, it was part of a static
lib and linker ignores it as it has already resolved that symbol from
the overloaded function.
I would like to know if there is any other approach to fix this
problem. Note that I don't have freedom to convert this static lib to
dynamic one.