Background: I am developing a package that uses Rcpp and contains some C++ files. I would like to analyze my code with ASAN. I am struggling to build my package.
What I have done so far
- I am using
https://hub.docker.com/r/rocker/r-devel-sandocker container that comes with pre-built R (or RD) for working with ASAN. - Within this container, I could run a C++ script with
-fsanitize=addressflag to get a meaningful ASAN output. - My
src/Makevarsfiles look like the following (not all flags are relevant to this question):
CC = gcc -fsanitize=address -fno-omit-frame-pointer
CXX = g++
LDFLAGS = -fsanitize=address
PKG_CXXFLAGS = -fsanitize=address -fno-omit-frame-pointer -fno-sanitize-address-use-after-scope -D_GCL_RHACK_ -DGC_NO_MUTEX -m64 -ldl -lpthread -Wall -pipe -pedantic -Wno-unused -DNDEBUG -g -std=c++17
PKG_CFLAGS = -fsanitize=address -D_GCL_RHACK_ -fno-sanitize-address-use-after-scope
- To install, I do (from the directory containing my package directory
foo):
RD CMD build foo
RD CMD install -l temp_lib/ foo_1.0.tar.gz
The install command throws the following error (along with the last line of teh build)
-g -O2 -c loadpathutil.c -o loadpathutil.o
g++ -fsanitize=undefined,bounds-strict -fno-omit-frame-pointer -std=gnu++17 -shared -L/usr/local/lib/R/lib -L/usr/local/lib -o foo.so RcppExports.o Read.o Utilities.o Write.o gdxcc.o loadpathutil.o -L/usr/local/lib/R/lib -lR
** R
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded from temporary location
Error: package or namespace load failed for ‘foo’ in dyn.load(file, DLLpath = DLLpath, ...):
installing to /work/temp_lib/00LOCK-foo/00new/foo/libs
unable to load shared object '/work/temp_lib/00LOCK-foo/00new/foo/libs/foo.so':
/work/temp_lib/00LOCK-foo/00new/foo/libs/foo.so: undefined symbol: __asan_option_detect_stack_use_after_return
I understand that the final package shared object has to be somehow linked to ASAN but the suggested solutions LDFLAGS, PKG_LDFLAGS don't seem to help.
This the document I wrote for myself and that I used myself.
clang.apt-get install clangshould do the jobconfig.siteand add the following at the endmakeThen we can check if it actually works by running R in
bin/Rand triggering errors using the packagesanitizers.Then use R as usual and install your package as usual