R.NET works with x86 but not x64

377 Views Asked by At

I'm trying to build and run the Hello World sample at the tutorial page at R.NET. When I force the program to run in x86 mode, it seems to do OK. However, when I run in x64, it stops very early on with the message, "[program] exited with code-1073740791" I've installed the latest version of R at The R Project and have ran the troubleshooting steps. The output I've gotten from the troubleshooting program is:

  • Is this process 64 bits? True
  • Info: caller provided rPath=null, rHome=null Info: R.NET looked for preset R_HOME env. var. Found null
  • Info: Found Windows registry key RDotNet.NativeLibrary.WindowsRegistryKey
  • Info: Found Windows registry key RDotNet.NativeLibrary.WindowsRegistryKey
  • Info: Found sub-key InstallPath under RDotNet.NativeLibrary.WindowsRegistryKey
  • Info: InstallPath value of key RDotNet.NativeLibrary.WindowsRegistryKey: C:\Program Files\R\R-4.0.3
  • Info: R.NET looked for platform-specific way (e.g. win registry). Found C:\Program Files\R\R-4.0.3
  • Info: R.NET trying to find rPath based on rHome; Deduced C:\Program Files\R\R-4.0.3\bin\x64
  • C:...\bin\x64\Debug\net5.0\ConsoleNet5R.exe (process 33500) exited with code -1073740791.

I have verified that there IS a file R.dll where it deduced it should be, "C:\Program Files\R\R-4.0.3\bin\x64". When I step through using my decompiler, it appears that it gets choked up at what is showing up for me as line 400 in REngine.cs, under the function "Initialize" at this.GetFunction<setup_Rmainloop>()(); It doesn't appear to throw an exception, it just stops. I'll be honest--I'm not sure what this line is supposed to be doing...

Any ideas what is going on? I can run in x86 mode if I have to, but I would like to use x64 if possible.

2

There are 2 best solutions below

1
karl On

This issue has been reported for a while.. I experienced the same with R-4.0.3 to R-4.0.5.

There is not such issue for R-4.0.2 and former versions (4.0.1, 4.0.0, 3.6, 3.5)

0
lrasmus On

I've done an analysis of this and tracked findings in one of the RDotNet GitHub issues where this was raised (https://github.com/rdotnet/rdotnet/issues/139#issuecomment-898699993).

This appears to be related to the Control Flow Guard security feature enabled in Windows 10. This doesn't happen in the R programs themselves because they are compiled using a different compiler (gcc via mingw) than Microsoft's. However, the CFG feature is enabled for .NET binaries and there is something (sorry, I don't know the actual underlying root cause) in a change within R 4.0.3 in setjmp/longjmp calls that is causing the crash (see: https://github.com/wch/r-source/blob/trunk/src/gnuwin32/fixed/h/psignal.h#L44-L51).

Although you would actually be disabling a security feature, I have had some luck for now in modifying my program after it is compiled (you can set this as a post-build event). You will need to run something like: link /EDIT /GUARD:NO <yourapp>.exe, which disables CFG.

Thanks to https://github.com/dotnet/runtime/issues/11899#issuecomment-502195325 for providing the instructions needed for this workaround, and https://www.trendmicro.com/en_us/research/16/j/control-flow-guard-improvements-windows-10-anniversary-update.html for providing the amazing analysis of CFG that led to an understanding of what was going on.