[R-pkg-devel] DllInfo & native routine registration
Dirk Eddelbuettel
edd at debian.org
Tue May 9 16:51:48 CEST 2017
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 | edd at debian.org
More information about the R-package-devel
mailing list