Skip to content

RcppDeepState optimization options #8

@FabrizioSandri

Description

@FabrizioSandri

I noticed that RcppDeepState wasn't able to find issues in some function of the testSAN package so I started to manually run and analyze each function one by one. I first tried to run RcppDeepState on the rcpp_write_index_outofbound function and, no matter of the seed, the result table was always empty. By manually running the binary file for the rcpp_write_index_outofbound function, I found that no error is thrown during the execution. After some tests I discovered that this problem is due to the use of optimization options in the compiler flags, when the command R CMD INSTALL is run for the package.

Proof of concept

To understand this problem and have a practical example, I copied the rcpp_write_index_outofbound function and added to it a main function that calls rcpp_write_index_outofbound with a parameter that will certainly smash the stack and cause an heap overflow. This is the result.

#include <iostream>
using namespace std;

// [[Rcpp::export]]
int rcpp_write_index_outofbound(int wbound){
  int x = wbound;
  int *stack_array = new int[100];
  stack_array[x+100] = 50;
  return 0; 
} 

int main(int argc, char** argv){
    int bigNumber = 1353252;
    rcpp_write_index_outofbound(bigNumber);
    cout << "Finished" << endl;
    return 0;
}

I tried to compile this program in two different ways. The first one using optimization options and the second one disabling optimizers. What I expect by each execution is a segmentation fault error, however the results are quite different:

$ g++ -o test -O2 test.cpp
$ ./test
Finished

$ g++ -o test test.cpp
$ ./test
[1]    9815 segmentation fault (core dumped)  ./test

Result and future work

As a result, we can conclude that RcppDeepState requires compiler optimizations to be disabled in order to operate at its maximum performance and detect subtler bugs. Since the change of optimization options involves the change of the CXXFLAGS in the ~/.R/Makevars file, I can conclude that this should be a prerequisite of using RcppDeepState.

Future work: I have to keep in mind that optimization options must be turned off in the Action's Docker-based system that I will create for RcppDeepState.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions