[Rd] Quote symbol names under EXPORTS in tmp.def on Windows

Kyle Baron kyleb at metrumrg.com
Fri Aug 12 08:15:33 CEST 2016


Attaching a proper patch for this issue.  I will post a bug report
whenever new registrations are allowed.

Best Regards,
Kyle


On Sat, Aug 6, 2016 at 11:51 PM, Kyle Baron <kyleb at metrumrg.com> wrote:
>
> I originally posted on this topic on a different thread:
> https://stat.ethz.ch/pipermail/r-devel/2016-August/072938.html
>
> These sources suggested that a safe practice might be to put double
> quotes around symbol names in EXPORTS in case the symbol name is the
> same as a linker keyword:
>    - https://sourceware.org/binutils/docs/ld/Symbols.html#Symbols
>    - https://msdn.microsoft.com/en-us/library/163abkbh.aspx
>
> I wasn't sure how that related specifically to what Rtools is using,
> but when I made the following change to winshlib.mk (double quotes
> around symbol names in tmp.def), I was able to compile code without
> issue and get symbols like BASE (or other keywords) exported.
>
>
> Kyle
>
>
>
>
> ## ${R_HOME}/share/make/winshlib.mk
> 6a7,8
> > ADDQU = 's/[^ ][^ ]*/"&"/g'
> >
> 17c19
> <     $(NM) $^ | $(SED) -n $(SYMPAT) $(NM_FILTER) >> tmp.def; \
> ---
> >     $(NM) $^ | $(SED) -n $(SYMPAT) $(NM_FILTER) | $(SED) $(ADDQU) >> tmp.def; \
>
>
>
> code <- '
>
> void BASE(int *nin, double *x) {
>    int n = nin[0];
>    for (int i=0; i<n; i++) x[i] = x[i] * x[i];
> }
>
> void rd(int *nin, double *x) {
>    int n = nin[0];
>    for (int i=0; i<n; i++) x[i] = x[i] * x[i];
> }
>
> double EXPORTS = 2.1;
> int LIBRARY = 3;
> '
>
> writeLines(code, "src1.c")
>
> system("R CMD SHLIB src1.c")
> dyn.load("src1.dll")
>
> is.loaded("EXPORTS",PACKAGE="src1")
> is.loaded("BASE",PACKAGE="src1")
> is.loaded("rd",PACKAGE="src1")
>
> dyn.unload("src1.dll")
>
>
>
> --
> Kyle Baron
> Metrum Research Group




-- 
Kyle Baron
Metrum Research Group
kyleb at metrumrg.com
-------------- next part --------------
Index: winshlib.mk
===================================================================
--- winshlib.mk	(revision 71059)
+++ winshlib.mk	(working copy)
@@ -4,6 +4,8 @@
 
 BASE = $(shell basename $(SHLIB) .dll)
 
+ADDQU = 's/[^ ][^ ]*/"&"/g'
+
 ## do it with explicit rules as packages might add dependencies to this target
 ## (attempts to do this GNUishly failed for parallel makes,
 ## but we do want the link targets echoed)
@@ -14,7 +16,7 @@
 	    $(SHLIB_LD) -shared $(DLLFLAGS) -o $@ $(BASE)-win.def $(OBJECTS) $(ALL_LIBS); \
 	  else \
 	    echo EXPORTS > tmp.def; \
-	    $(NM) $^ | $(SED) -n $(SYMPAT) $(NM_FILTER) >> tmp.def; \
+	    $(NM) $^ | $(SED) -n $(SYMPAT) $(NM_FILTER) | $(SED) $(ADDQU)  >> tmp.def; \
 	    echo $(SHLIB_LD) -shared $(DLLFLAGS) -o $@ tmp.def $(OBJECTS) $(ALL_LIBS); \
 	    $(SHLIB_LD) -shared $(DLLFLAGS) -o $@ tmp.def $(OBJECTS) $(ALL_LIBS); \
 	    $(RM) tmp.def; \


More information about the R-devel mailing list