On 9 May 2017 at 15:59, Hannes Mühleisen wrote:
| Hello R-package-devel,
| 
| I have just completed porting the MonetDBLite package to use registered 
native routines [1]. This worked fine except one minor issue: MonetDBLite (and 
I suppose other software) extensively uses dlsym to find its own internal 
functions. This used to rely on dlsym(dlopen(NULL, RTLD_NOW | RTLD_GLOBAL), 
“some symbol”). However, in line with the new registration requirement, I 
changed this to dlopen from the specific .so file that contains my package C 
code. However, for this to work, I need a full path to the .so file in the 
installed R package. 
| 
| Now, I found that (conveniently), that path is contained in the DllInfo 
structure that is passed to the registration function. All is well if I just 
use that path. However, the DllInfo structure is opaque with a non-public 
definition in Rdynpriv.h. I think thats fine, but would it be possible to 
export a simple function like
| 
| void* R_get_dllinfo_path(DllInfo *dll) {
|       return strdup(dll->path);
| }
| 
| so one can pull the library path for dlopen() purposes?

Here is what Rmpi does (and I am CCing Hao Yu as the 'openmpi.so.20' part is
yeat not upstream, but we needed it in Debian)

#ifdef OPENMPI
    if (!dlopen("libmpi.so.20", RTLD_GLOBAL | RTLD_LAZY) 
        && !dlopen("libmpi.so.1", RTLD_GLOBAL | RTLD_LAZY) 
        && !dlopen("libmpi.so.0", RTLD_GLOBAL | RTLD_LAZY)
        && !dlopen("libmpi.so", RTLD_GLOBAL | RTLD_LAZY)) {
        Rprintf("%s\n",dlerror());
        return AsInt(0);
    }
#endif

We have used this for maybe a decade -- dlopen() seems to just rely on
ldconfig and friends to resolve this.  [ And OpenMPI insists, or maybe
insisted ?, on scattering symbols over several shared libraries, requiring
the 'RTLD_GLOBAL | RTLD_LAZY' to set the proper bits. ]

Dirk

-- 
http://dirk.eddelbuettel.com | @eddelbuettel | e...@debian.org

______________________________________________
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel

Reply via email to