Re: dlsym interposition question
Re: dlsym interposition question
- Subject: Re: dlsym interposition question
- From: Ariel Burton <email@hidden>
- Date: Sun, 06 Oct 2013 18:29:44 -0400
This also doesn't quite do what I'm after.
How are you loading libfoo.dylib? Are you linking it with your
main program? Are you loading it with dlopen? Or are you
perlaoding it with DYLD_INSERT_LIBRARIES?
I played with your formula for the case where I load the library
with DYLD_INSERT_LIBRARIES. I found that the key RTLD flag that
made a difference was RTLD_FIRST. When I gave this in the main
program, dlsym did not find my interposing definition for getpid.
Perhaps to be clearer, how, when one is interposing a symbol,
can a main program find both the interposing definition and
also the definition that is being interposed?
Ariel Burton
==
On Sun 6 Oct 15:50, Stephen Checkoway wrote:
>
> On Oct 6, 2013, at 4:33 PM, Ariel Burton <email@hidden> 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 (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden