[petsc-dev] PetscDLSym called on an empty handle
Dmitry Karpeev
karpeev at mcs.anl.gov
Thu Aug 5 20:05:49 CDT 2010
On Thu, Aug 5, 2010 at 7:48 PM, Lisandro Dalcin <dalcinl at gmail.com> wrote:
> On 5 August 2010 18:07, Dmitry Karpeev <karpeev at mcs.anl.gov> wrote:
> >
> >
> > On Thu, Aug 5, 2010 at 4:00 PM, Lisandro Dalcin <dalcinl at gmail.com>
> wrote:
> >>
> >> On 5 August 2010 13:40, Dmitry Karpeev <karpeev at mcs.anl.gov> wrote:
> >> > What is the intended behavior of PetscDLSym when called on an empty
> >> > handle:
> >> > PetscDLSym(handle=PETSC_NULL, symbol, &value)
> >> > My understanding was that this should look for symbol in the symbol
> >> > table of
> >> > the main executable.
> >> > This is based on what happens in the Windows case (#ifdef
> >> > PETSC_HAVE_WINDOWS_H),
> >> > but when using dlopen (#ifdef PETSC_HAVE_DLFCN_H), this probably won't
> >> > behave correctly,as currently implemented.
> >> > This is because the above call will boil down to
> >> > value = dlsym((dlhandle_t)0, symbol),
> >> > which on many systems returns NULL (e.g., on Ubuntu 9.10).
> >>
> >> Look at your dlfch.h header file.. Does it have the line below?:
> >>
> >> # define RTLD_DEFAULT ((void *) 0)
> >
> > Yes. Ah, I see: my problem was that the symbol wasn't being exported,
> not
> > that the null handle wasn't referring to the executable.
>
> Yep
>
> > I guess I can
> > change it to use RTLD_DEFAULT, but that would require changes to
> configure.
>
> Using RTLD_DEFAULT is the right way to do it.
>
> > Also, this may be less portable: OSX uses a different define for the
> default
> > handle, so configure would have to
> > test for that too. I wonder what OSX does for dlopen(0,flags)?
> >
>
> It likely fails with "invalid handle passed to dlsym()"
> (http://www.opensource.apple.com/source/dyld/dyld-132.13/src/dyldAPIs.cpp)
>
The implementation of dlsym from the link above seems to imply that
RTLD_DEFAULT on OSX
means "search EVERYTHING", not just the main executable. No? Some of that
Apple-specific
code is impenetrable to me. If I'm right, then this is contrary to the way
Linux interprets RTLD_DEFAULT.
The Apple equivalent seems to be RTLD_MAIN_ONLY.
Currently PetscDLSym(0,symbol,&value) is implemented to search the main
executable on Windows
(at least that's how I read that code, without being too familiar with the
Windows API).
So I assume that's what we want to do everywhere else, including on OSX.
This, in turn, means using RTLD_DEFAULT on Linux, RTLD_MAIN_ONLY on Apple.
Dmitry.
>
> --
> Lisandro Dalcin
> ---------------
> CIMEC (INTEC/CONICET-UNL)
> Predio CONICET-Santa Fe
> Colectora RN 168 Km 472, Paraje El Pozo
> Tel: +54-342-4511594 (ext 1011)
> Tel/Fax: +54-342-4511169
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-dev/attachments/20100805/e47bd150/attachment.html>
More information about the petsc-dev
mailing list