Figure out how to handle dlsym with RTLD_NEXT
The RTLD_NEXT parameter to dlsym has at least two issues with gotcha:
-
When the symbol being passed to dlsym isn't wrapped: the behavior of dlsym with RTLD_NEXT changes based on the caller library. Wrapping dlsym will break this. We need to simulate the bottom level call as if coming from the top level caller.
-
Calling dlsym with RTLD_NEXT can return a different "bottom-level symbol" than without. If the symbol is wrapped, should we return the same wrapper function with and without RTLD_NEXT? Should we support different stacks of wrappers?
This comment is to expand on the problem, for my own notes, as this issue is really thorny
An example of this problem is that somebody calls dlsym(RTLD_NEXT, "foo"), where "foo" has been wrapped by Gotcha. Gotcha can rather easily faithfully simulate RTLD_NEXT using the builtin_return_address call we make here. However, it doesn't yet return a wrapped version of that call.
Correct behavior should be returning a function stack with correct wrappers, whose bottom-most ("real") function is the correct RTLD_NEXT-function