Created attachment 2052 [details]
patch to enable dyn.load(deep=TRUE)
The dyn.load call to dlopen does not support the RTLD_DEEPBIND flag, which specifies that a shared object should check its own symbols before resolving against the global symbol table. Letting users set this flag would allow, for example, a shared object linked statically against the ILP64 interface of MKL BLAS to be used with R built against LP64 MKL BLAS to compute the dot product of two long vectors. Without this change, the cblas_ddot call resolves to the LP64 symbol already loaded by R, and does not work correctly. (I was not able to compile R with ILP64, which I believe is expected.)
The attached patch implements and documents a "deep" argument to dyn.load to enable this behavior. The tests run under "make check" appear to work with this patch on my RHEL7.2 Linux box. I made the corresponding changes for Windows, but don't have a compiler handy to test.
The first test case (dot.c) is a real-life MKL example, and the second test case (dot_nomkl.c) is a more contrived example of a name collision between a shared object and the default libRblas (but does not require MKL to reproduce). Instructions for compiling and testing are included in the attachments as comments.
Created attachment 2053 [details]
dot.c MKL-based test case
Created attachment 2054 [details]
dot_nomkl.c non-MKL test case