Re: dlsym interposition question
On Oct 6, 2013, at 4:33 PM, Ariel Burton <ariel.burton@roguewave.com> wrote:
Firstly, I'm not sure I made this clear. What I want to do is to be able to locate the interposing implementation of getpid and the underlying system-provided implementation in the main program.
On ELF-like systems dlopening the dynamic library explicitly allows the definition in that library to be found. That's not happening here.
You can do that on Darwin too using RTLD_NOLOAD: void lookup_symbol(const char *name) { unsigned images = _dyld_image_count(); int num = 0; for (unsigned i = 0; i < images; ++i) { const char *path = _dyld_get_image_name(i); void *handle = dlopen(path, RTLD_LAZY | RTLD_LOCAL | RTLD_NOLOAD | RTLD_FIRST); void *sym = dlsym(handle, name); if (sym) printf("%d: %u %s %p\n", num++, i, path, sym); dlclose(handle); } } With this in both a library containing a getpid() (libfoo.dyld) and in the main executable linking to the library, calling lookup_symbol("getpid") prints: 0: 1 /private/tmp/libfoo.dyld 0x102896cf0 1: 2 /usr/lib/libSystem.B.dylib 0x7fff8edecc2c 2: 19 /usr/lib/system/libsystem_kernel.dylib 0x7fff8edecc2c Likewise, from both libfoo.dyld, printing the address of getpid gives getpid from main: 0x102896cf0 getpid from library: 0x102896cf0 Hope that helps some, -- Stephen Checkoway _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/darwin-dev/site_archiver%40lists.app... This email sent to site_archiver@lists.apple.com
participants (1)
-
Stephen Checkoway