Bug 17130

Summary: R CMD SHLIB fails when exported symbol name conflicts w/ ld keyword
Product: R Reporter: Kyle Baron <devtmp>
Component: Windows GUI / Window specificAssignee: R-core <R-core>
Status: CLOSED FIXED    
Severity: normal CC: devtmp, murdoch
Priority: P5    
Version: R 3.3.*   
Hardware: x86_64/x64/amd64 (64-bit)   
OS: Windows 64-bit   
Attachments: Patch to put double-quotes around symbol names in tmp.def
R test code

Description Kyle Baron 2016-08-12 16:24:47 UTC
Created attachment 2139 [details]
Patch to put double-quotes around symbol names in tmp.def

For example: BASE is a keyword so building a shared object on Windows
with a function called BASE fails:

code <- '
void BASE(int *nin, double *x) {
  int n = nin[0];
  int i;
  for (i=0; i<n; i++) x[i] = x[i] * x[i];
system("R CMD SHLIB test_base.c")

The output is:
 c:/Rtools/mingw_64/bin/gcc  -I"C:/PROGRA~1/R/R-33~1.1/include"
 -DNDEBUG     -I"d:/Compiler/gcc-4.9.3/local330/include"     -O2 -Wall
 -std=gnu99 -mtune=core2 -c test_base.c -o test_base.o
 c:/Rtools/mingw_64/bin/gcc -shared -s -static-libgcc -o test_base.dll
 tmp.def test_base.o -Ld:/Compiler/gcc-4.9.3/local330/lib/x64
 -Ld:/Compiler/gcc-4.9.3/local330/lib -LC:/PROGRA~1/R/R-33~1.1/bin/x64

 tmp.def:3: syntax error
 file format not recognized; treating as linker script
 syntax error collect2.exe: error: ld returned 1 exit status

In my testing, this happens with other ld keywords (LIBRARY, EXPORTS, NAME, SHARED, etc).

Putting double-quotes around symbol names under EXPORTS in the tmp.def
file created by winshlib.mk appeared to resolve the symbol name / keyword

Attaching a proposed patch for share/make/winshlib.mk and R script with test case.

My Windows testing done on:
R version 3.3.1 (2016-06-21)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows Server 2008 R2 x64 (build 7601) Service Pack 1

Reference: https://stat.ethz.ch/pipermail/r-devel/2016-August/072973.html
Comment 1 Kyle Baron 2016-08-12 16:26:58 UTC
Created attachment 2140 [details]
R test code
Comment 2 Duncan Murdoch 2016-08-12 16:47:19 UTC
Thanks.  I'll put your patch into R-devel and R-patched.