GOTCHA icon indicating copy to clipboard operation
GOTCHA copied to clipboard

Figure out how to handle dlsym with RTLD_NEXT

Open mplegendre opened this issue 8 years ago • 1 comments

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?

mplegendre avatar Jun 15 '17 21:06 mplegendre

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

DavidPoliakoff avatar Sep 05 '17 22:09 DavidPoliakoff