Dominick Samperi
2013-Dec-12 07:12 UTC
[Rd] R CMD INSTALL may create invalid DLL under Windows
Under Windows the make include share/make/winshlib.mk uses nm to grab symbols from object files to insert into a module definition file tmp.def that is used to create a package DLL. This works fine provided the DLL is only used via exported function entry points, which is the case currently, I suspect. But the pattern SYMPAT (defined in Makeconf) used to capture symbols includes non-function symbols of type's BCDR, not just T (.text or code). These symbols need to be flagged in the module definition file by adding the string DATA after the symbol name. If this is not done then a client of this DLL (another DLL or a main program) will not be able to import these variables correctly (using dllexport/dllimport decorations is another less convenient strategy). I have checked this with gcc 4.6.3 (shipped with Rtools), and also with gcc 4.8.1 (MinGW). In both cases if the value of a simple 'int' is fetched from a DLL where the int is exported without the DATA keyword, the result is garbage, and inserting the DATA keyword fixes the problem. Thus the fix here is very simple. Just modify winshlib.mk so that the DATA flag follows non-function symbols. Alternatively, only function symbols can be captured, in which case only SYMPAT needs to change. Dominick
Apparently Analagous Threads
- Windows 64bit package build requires underscore hack?
- Quote symbol names under EXPORTS in tmp.def on Windows
- Problem installing gdb into Rtools42
- rgl/webGL complains about Javascript, even in recent online docs?
- [Rcpp-devel] Loading a package using Rcpp Modules results in memory corruption