From djsamperi at gmail.com  Thu Dec 12 08:12:41 2013
From: djsamperi at gmail.com (Dominick Samperi)
Date: Thu, 12 Dec 2013 02:12:41 -0500
Subject: [Rd] R CMD INSTALL may create invalid DLL under Windows
Message-ID: <CADUbQ5i2depWPQKik2jrTPk5JxjH+CN9P0jQaR-w+JS7R-FeRw@mail.gmail.com>

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



[Rd] R CMD INSTALL may create invalid DLL under Windows
Dominick Samperi