[R-pkg-devel] help with ASAN
Dirk Eddelbuettel
edd @end|ng |rom deb|@n@org
Wed Mar 25 22:48:47 CET 2020
Steve,
Your message has me puzzled over a few things just like your previous message
from a few days ago.
On 25 March 2020 at 14:17, Steven Scott wrote:
| I'm trying to build an ASAN enabled version of my R library to help debug
| errors found by CRAN on my last submission. I'm tantalizingly close, but
| need some help figuring out what's wrong with my configuration.
|
| I'm using a docker container that I think contains a version of R built
| with the right options. I launch the docker container as so:
|
| docker run --cap-add SYS_PTRACE -e PASSWORD=<redacted> --rm -p 8787:8787 -v
| /home/steve/code/BOOM:/home/steve/code/BOOM -it rocker/r-devel-ubsan-clang
| /bin/bash
My goto alias for docker does a few of these but never the --cap-add (seems
like you may need it for profiling, likely not for asan/ubsan), the password,
or the port (but who knows, maybe you need them...). So I'd say
docker run --rm -v /home/steve/code/BOOM:/home/steve/code/BOOM \
-it rocker/r-devel-ubsan-clang /bin/bash
[ For completeness I have this
## docker run and mount
alias dkrr='docker run --rm -ti -v$(pwd):/work -w /work
and would then just do
dkrr rocker/r-devel-ubsan-clang bash
which has a lesser cognitive load. But I digress. ]
| In this container I have added a ~/.R/Makevars file with the following
| content:
| CC= clang -std=c99 -fsanitize=address -fno-omit-frame-pointer
| CXX= clang++ -std=c++11 -fsanitize=address -fno-omit-frame-pointer
| CXX11= clang++ -std=c++11 -fsanitize=address -fno-omit-frame-pointer
| FC = gfortran -fsanitize=address
For ASAN/UBSAN to work you should use the same setting as the compiled
'host'. As you benefit from a pre-made Docker container, its settings are
CC="clang -fsanitize=address,undefined -fno-sanitize=float-divide-by-zero -fno-omit-frame-pointer -fsanitize-address-use-after-scope" \
CXX="clang++ -stdlib=libc++ -fsanitize=address,undefined -fno-sanitize=float-divide-by-zero -fno-omit-frame-pointer -fsanitize-address-use-after-scope" \
per
https://github.com/rocker-org/r-devel-san-clang/blob/master/Dockerfile#L90-L91
so I recommend you use the same. I found all this mysterious enough back in
the day when I first set it up that I create a package with *known* triggers
for these detections so that I could be sure I had at least their detection
right. It is still at CRAN:
https://cran.r-project.org/package=sanitizers
These things to change with compiler releases and what not. If this Docker
container does not work, there is another very good one here
https://github.com/wch/r-debug
| When I build my package I get:
| (... expected compiler output truncated except for final compile and link
| step ... )
| clang++ -std=c++11 -fsanitize=address -fno-omit-frame-pointer -std=gnu++11
[...]
| /usr/local/lib/R/site-library/00LOCK-BoomSpikeSlab/00new/BoomSpikeSlab/libs/BoomSpikeSlab.so:
| undefined symbol: __asan_option_detect_stack_use_after_return
Looks like you also need to link with the ASAN library, possibly via -lasan.
My Dockerfile referenced above has
MAIN_LD="clang++ -stdlib=libc++ -fsanitize=undefined,address"
and it may be implied by the -fsanitize=... business.
Hth, Dirk
--
http://dirk.eddelbuettel.com | @eddelbuettel | edd using debian.org
More information about the R-package-devel
mailing list