Skip to content

Instantly share code, notes, and snippets.

@knausb
Last active March 19, 2019 15:27
Show Gist options
  • Save knausb/0787d74bdbe3195cd02a48d30ee9c73b to your computer and use it in GitHub Desktop.
Save knausb/0787d74bdbe3195cd02a48d30ee9c73b to your computer and use it in GitHub Desktop.
rocker_asan
.Rproj.user
.Rhistory
.RData
.Ruserdata
.html
---
title: Address sanitizer in Rocker
author: Brian J. Knaus
license: GPL (>= 2)
---
I was informed by CRAN that my R package had a *stack overflow* problem and that I needed to address this.
This error was not produced during typical compilation or when using valgrind.
I was pretty sure my only path was to use the address sanitizer.
However, I had no experience doing this sort of thing.
Here I've tried to document the process I took with the hope it may help others.
## Why Rocker?
CRAN has documentated use of the address sanitizer in their Writing R extensions document [Using-Address-Sanitizer](https://cran.r-project.org/doc/manuals/r-devel/R-exts.html#Using-Address-Sanitizer).
An important part of enabling the address sanitizer is that R must be built from source with this option enabled.
This is a bit of work.
Docker provides the option of creating a containerized version of R, independent of your system R, for development.
Rocker contains Docker images that are relevant to R, including ones built with the address sanitizer.
So this appears to be an excellent option.
## Docker
The [Docker site](https://docs.docker.com/) has information on installing Docker.
Here we'll assume you have Docker installed.
In Debian Linux (including Ubuntu) this can be done as follows.
```{bash, eval = FALSE}
sudo apt install docker.io
```
Once installed, you'll have to make sure the daemon is running.
This can be accomplished with tht below commands.
```{bash, eval = FALSE}
service docker status
service docker start
service docker stop
```
Once running you can test your Docker system with the below commands.
```{bash, eval = FALSE}
sudo docker version
sudo docker ps # Installed images.
sudo docker run hello-world
```
And search for rocker.
```{bash, eval = FALSE}
sudo docker search rocker
```
## Rocker
The Rocker project includes containers for running R.
Some of this is documented here: [Docker for R](http://dirk.eddelbuettel.com/blog/2014/10/23/).
There is also a [Rocker Github](https://github.com/rocker-org/rocker) site for the images and documentation is on the [Rocker wiki](https://github.com/rocker-org/rocker/wiki).
## Install a Rocker image
```{bash, eval = FALSE}
sudo docker pull rocker/r-devel-san
sudo docker build github.com/rocker-org/r-devel-san-clang
```
## Starting and stoping a container
```{bash, eval = FALSE}
sudo docker run --name myR -i -t r-base /bin/bash
sudo docker run --name myRdevel -i -t rocker/r-devel-san /bin/bash
```
```{bash, eval = FALSE}
exit
```
## Adding software to your container
## Adding R packages
## Saving the state of your container
## Testing your R package with the address sanitizer
## Interpreting the address sanitizer's output
Version: 1.0
RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default
EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8
RnwWeave: Sweave
LaTeX: pdfLaTeX
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment