Subject: Re: bug#21909: Segfault with eigen in R

From: [email-masked] (Ludovic Courtès)
Date: Fri, 20 Nov 2015 10:58:41 +0100

Kyle Meyer <[email-masked]> skribis:

> [email-masked] (Ludovic Courtès) writes:
>
>> I can reproduce the bug with:
>>
>>    guix environment --pure --ad-hoc r -- R
>
> [...]
>
>> Might be useful to report it upstream?
>
> Yes.  In preparing to do so, I figured that I should reproduce the issue
> with a build outside of Guix.  However, when I tried with a manual build
> on an Arch Linux system, the snippet ran fine.  This was with gcc
> version 5.2.0, so I switched the gfortran input of openblas over to
> gfortran-5, which seems to fix the issue.

Interesting.

> While the issue should still be reported upstream, would it be OK to
> update the gfortran input to gfortran-5?

The problem is that this leads to an R linked against GCC 4.9’s libgcc_s
and other run-time support libraries, and also against those of GCC 5.2,
via OpenBLAS.  I think we’d rather avoid it.

An additional data point:

--8<---------------cut here---------------start------------->8---
$ guix environment --pure --ad-hoc r valgrind -- R -d valgrind
/gnu/store/jb11p396a277rndb52da20ygdksccji8-r-3.2.2/bin/R: line 8: uname: command not found
==3198== Memcheck, a memory error detector
==3198== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==3198== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==3198== Command: /gnu/store/jb11p396a277rndb52da20ygdksccji8-r-3.2.2/lib/R/bin/exec/R
==3198== 

R version 3.2.2 (2015-08-14) -- "Fire Safety"
Copyright (C) 2015 The R Foundation for Statistical Computing
Platform: x86_64-unknown-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> M <- 50                                     
> N <- 500                                    
> eigen(crossprod(matrix(rnorm(M * N), M, N)))
==3198== Invalid read of size 8
==3198==    at 0x8E400E0: dgemv_t_SANDYBRIDGE (in /gnu/store/hw9p1zyn1nh8pbm1cl69nm0i391lk6c7-openblas-0.2.15/lib/libopenblasp-r0.2.15.so)
==3198==    by 0x183AED48: dlatrd_ (in /gnu/store/jb11p396a277rndb52da20ygdksccji8-r-3.2.2/lib/R/lib/libRlapack.so)
==3198==    by 0x18461F92: dsytrd_ (in /gnu/store/jb11p396a277rndb52da20ygdksccji8-r-3.2.2/lib/R/lib/libRlapack.so)
==3198==    by 0x184B9540: dsyevr_ (in /gnu/store/jb11p396a277rndb52da20ygdksccji8-r-3.2.2/lib/R/lib/libRlapack.so)
==3198==    by 0x1B742D5E: La_rs (in /gnu/store/jb11p396a277rndb52da20ygdksccji8-r-3.2.2/lib/R/modules/lapack.so)
==3198==    by 0x1B745B96: mod_do_lapack (in /gnu/store/jb11p396a277rndb52da20ygdksccji8-r-3.2.2/lib/R/modules/lapack.so)
==3198==    by 0x4F35635: bcEval (in /gnu/store/jb11p396a277rndb52da20ygdksccji8-r-3.2.2/lib/R/lib/libR.so)
==3198==    by 0x4F432DF: Rf_eval (in /gnu/store/jb11p396a277rndb52da20ygdksccji8-r-3.2.2/lib/R/lib/libR.so)
==3198==    by 0x4F48F4B: Rf_applyClosure (in /gnu/store/jb11p396a277rndb52da20ygdksccji8-r-3.2.2/lib/R/lib/libR.so)
==3198==    by 0x4F4345E: Rf_eval (in /gnu/store/jb11p396a277rndb52da20ygdksccji8-r-3.2.2/lib/R/lib/libR.so)
==3198==    by 0x4F6B0D9: Rf_ReplIteration (in /gnu/store/jb11p396a277rndb52da20ygdksccji8-r-3.2.2/lib/R/lib/libR.so)
==3198==    by 0x4F6B430: R_ReplConsole (in /gnu/store/jb11p396a277rndb52da20ygdksccji8-r-3.2.2/lib/R/lib/libR.so)
==3198==  Address 0xfb0 is not stack'd, malloc'd or (recently) free'd
==3198== 

 *** caught segfault ***
address 0xfb0, cause 'memory not mapped'
--8<---------------cut here---------------end--------------->8---

Here this suggests an R issue more than an OpenBLAS problem.

Ludo’.