Shared object error in rPackages.Seurat

I’ve packaged and committed several things into NixPkgs during the last few months, in an effort to move all my workflow to NixOS. It’s been a great experience.

I’m a bit stuck with this issue, though. It’s coming from an R package that is already in Nix:

$ nix-shell -p R rPackages.Seurat

This runs for a while, and ends up with an error:

installing to /nix/store/sj1prdhla6yn8j9m3mxwrw6r98yj272y-r-Seurat-2.3.0/library/Seurat/libs
** R
** data
*** moving datasets to lazyload DB
** inst
** byte-compile and prepare package for lazy loading
Error in dyn.load(file, DLLpath = DLLpath, ...) :
  unable to load shared object '/nix/store/k5372w0p46ki7cx4qdnz80a9n9zh9mfy-r-SDMTools-1.1-221/library/SDMTools/libs/SDMTools.so':
  /nix/store/k5372w0p46ki7cx4qdnz80a9n9zh9mfy-r-SDMTools-1.1-221/library/SDMTools/libs/SDMTools.so: undefined symbol: X
ERROR: lazy loading failed for package 'Seurat'
* removing '/nix/store/sj1prdhla6yn8j9m3mxwrw6r98yj272y-r-Seurat-2.3.0/library/Seurat'
builder for '/nix/store/5ql9gnzhh0vdwybk4mwv1b3clmirr3j7-r-Seurat-2.3.0.drv' failed with exit code 1
error: build of '/nix/store/5ql9gnzhh0vdwybk4mwv1b3clmirr3j7-r-Seurat-2.3.0.drv' failed

Any ideas? Thanks

After looking into the issue carefully, it looks odd. I managed to get an Arch Linux Docker inside Nix with a working SDMTools R package.

The only differences seem to come from the dynamic symbol table (viewed with objdump). In the broken Nix version, the symbol “b” is missing, and it’s been replaced by “X”. In the working Arch version, the symbol “b” is there.

Symbol “b” originates from SDMTools/src/vincenty.geodesics.c:

//define some global constants
double a = 6378137, b = 6356752.3142,  f = 1/298.257223563;  // WGS-84 ellipsiod

Are these differences in the generated .so arising from, perhaps, Nix using different compilation and linking flags?

Output of working SDMTools in Arch Linux, objdump -TC /usr/lib/R/library/SDMTools/libs/SDMTools.so

0000000000000000      DO *UND*  0000000000000000              R_NilValue
0000000000000000      DF *UND*  0000000000000000              Rf_allocVector
0000000000000000  w   D  *UND*  0000000000000000              _ITM_deregisterTMCloneTable
0000000000000000      DF *UND*  0000000000000000              R_IsNA
0000000000000000      D  *UND*  0000000000000000              sincos
0000000000000000      DF *UND*  0000000000000000              REAL
0000000000000000      D  *UND*  0000000000000000              atan2
0000000000000000      DF *UND*  0000000000000000  GLIBC_2.2.5 fclose
0000000000000000      DF *UND*  0000000000000000  GLIBC_2.4   __stack_chk_fail
0000000000000000      DO *UND*  0000000000000000              R_NaReal
0000000000000000      DF *UND*  0000000000000000  GLIBC_2.2.5 fputc
0000000000000000      DF *UND*  0000000000000000              Rf_allocMatrix
0000000000000000      DF *UND*  0000000000000000              Rf_unprotect
0000000000000000  w   D  *UND*  0000000000000000              __gmon_start__
0000000000000000      DF *UND*  0000000000000000              R_CHAR
0000000000000000      D  *UND*  0000000000000000              atan
0000000000000000      DF *UND*  0000000000000000              INTEGER
0000000000000000      D  *UND*  0000000000000000              tan
0000000000000000      DF *UND*  0000000000000000              Rf_length
0000000000000000      D  *UND*  0000000000000000              cos
0000000000000000      DF *UND*  0000000000000000              Rf_protect
0000000000000000      DF *UND*  0000000000000000  GLIBC_2.2.5 fopen
0000000000000000      DF *UND*  0000000000000000              STRING_ELT
0000000000000000      DF *UND*  0000000000000000              Rf_coerceVector
0000000000000000      DO *UND*  0000000000000000              R_NaInt
0000000000000000      D  *UND*  0000000000000000              sqrt
0000000000000000      DF *UND*  0000000000000000  GLIBC_2.2.5 fwrite
0000000000000000      DF *UND*  0000000000000000  GLIBC_2.3.4 __fprintf_chk
0000000000000000  w   D  *UND*  0000000000000000              _ITM_registerTMCloneTable
0000000000000000      DF *UND*  0000000000000000              Rf_getAttrib
0000000000000000      DO *UND*  0000000000000000              R_DimSymbol
0000000000000000  w   DF *UND*  0000000000000000  GLIBC_2.2.5 __cxa_finalize
0000000000206018 g    DO .data  0000000000000008  Base        f
0000000000002e00 g    DF .text  00000000000005cc  Base        Slope
0000000000206050 g    DO .bss   0000000000000004  Base        ncol
0000000000004180 g    DF .text  0000000000000673  Base        Dist
0000000000206008 g    DO .data  0000000000000008  Base        epsilon
0000000000003a00 g    DF .text  0000000000000775  Base        Dest
0000000000001230 g    DF .text  0000000000000121  Base        ContourTracing
0000000000004800 g    DF .text  00000000000002e9  Base        writeascdata
00000000000015e0 g    DF .text  000000000000019d  Base        getmin
0000000000206030 g    D  .data  0000000000000000  Base        _edata
0000000000206048 g    DO .bss   0000000000000008  Base        out
0000000000001360 g    DF .text  000000000000027b  Base        ccl
00000000000029d0 g    DF .text  0000000000000429  Base        pip
0000000000001a00 g    DF .text  0000000000000617  Base        projectedPS
0000000000206040 g    DO .bss   0000000000000008  Base        ans
0000000000002020 g    DF .text  00000000000009a9  Base        geographicPS
0000000000001170 g    DF .text  00000000000000b2  Base        Tracer
0000000000206058 g    D  .bss   0000000000000000  Base        _end
0000000000004aec g    DF .fini  0000000000000000  Base        _fini
0000000000206010 g    DO .data  0000000000000008  Base        TWOPI
0000000000206030 g    D  .bss   0000000000000000  Base        __bss_start
0000000000206054 g    DO .bss   0000000000000004  Base        nrow
0000000000206038 g    DO .bss   0000000000000008  Base        data
0000000000001780 g    DF .text  000000000000027d  Base        movewindow
0000000000001090 g    DF .init  0000000000000000  Base        _init
0000000000206028 g    DO .data  0000000000000008  Base        a
0000000000206020 g    DO .data  0000000000000008  Base        b
0000000000004b80 g    DO .rodata        0000000000000008  Base        small_num
00000000000033d0 g    DF .text  0000000000000625  Base        Aspect

Output of broken SDMTools in NixOs, objdump -TC /nix/store/k5372w0p46ki7cx4qdnz80a9n9zh9mfy-r-SDMTools-1.1-221/library/SDMTools/libs/SDMTools.so

0000000000000000      DO *UND*  0000000000000000              R_NaInt
0000000000000000      DF *UND*  0000000000000000              Rf_length
0000000000000000      DF *UND*  0000000000000000              Rf_allocMatrix
0000000000000000  w   D  *UND*  0000000000000000              _ITM_deregisterTMCloneTable
0000000000000000  w   DF *UND*  0000000000000000  GLIBC_2.2.5 __cxa_finalize
0000000000000000      DF *UND*  0000000000000000              Rf_getAttrib
0000000000000000      DO *UND*  0000000000000000              R_NaReal
0000000000000000      DF *UND*  0000000000000000  GLIBC_2.3.4 __fprintf_chk
0000000000000000      DF *UND*  0000000000000000  GLIBC_2.4   __stack_chk_fail
0000000000000000      DF *UND*  0000000000000000              atan2
0000000000000000      DF *UND*  0000000000000000              REAL
0000000000000000      DF *UND*  0000000000000000              R_CHAR
0000000000000000  w   D  *UND*  0000000000000000              __gmon_start__
0000000000000000      DF *UND*  0000000000000000  GLIBC_2.2.5 fclose
0000000000000000      DF *UND*  0000000000000000              sqrt
0000000000000000      DF *UND*  0000000000000000              Rf_protect
0000000000000000      DF *UND*  0000000000000000              Rf_allocVector
0000000000000000      DF *UND*  0000000000000000              tan
0000000000000000      DF *UND*  0000000000000000              STRING_ELT
0000000000000000      DF *UND*  0000000000000000              sincos
0000000000000000      DF *UND*  0000000000000000  GLIBC_2.2.5 fputc
0000000000000000      DF *UND*  0000000000000000              INTEGER
0000000000000000      DF *UND*  0000000000000000              R_IsNA
0000000000000000      DF *UND*  0000000000000000              cos
0000000000000000      DO *UND*  0000000000000000              R_NilValue
0000000000000000  w   D  *UND*  0000000000000000              _ITM_registerTMCloneTable
0000000000000000      DF *UND*  0000000000000000              Rf_unprotect
0000000000000000      DF *UND*  0000000000000000  GLIBC_2.2.5 fwrite
0000000000000000      DO *UND*  0000000000000000              R_DimSymbol
0000000000000000      DF *UND*  0000000000000000              atan
0000000000000000      DF *UND*  0000000000000000  GLIBC_2.2.5 fopen
0000000000000000      DF *UND*  0000000000000000              Rf_coerceVector
0000000000206008 g    DO .data  0000000000000008  Base        epsilon
0000000000001580 g    DF .text  00000000000000b5  Base        Tracer
0000000000003180 g    DF .text  000000000000053e  Base        Slope
0000000000004d40 g    DF .fini  0000000000000000  Base        _fini
0000000000002420 g    DF .text  000000000000094e  Base        geographicPS
00000000000012c8 g    DF .init  0000000000000000  Base        _init
00000000000019f0 g    DF .text  0000000000000191  Base        getmin
0000000000206030 g    D  .bss   0000000000000000  Base        __bss_start
0000000000206040 g    DO .bss   0000000000000008  Base        data
0000000000206048 g    DO .bss   0000000000000004  Base        nrow
0000000000206028 g    DO .data  0000000000000008  Base        a
0000000000206058 g    D  .bss   0000000000000000  Base        _end
0000000000206020 g    DO .data  0000000000000008  Base        X
0000000000001b90 g    DF .text  0000000000000245  Base        movewindow
0000000000001640 g    DF .text  0000000000000121  Base        ContourTracing
0000000000206030 g    D  .data  0000000000000000  Base        _edata
0000000000002d70 g    DF .text  0000000000000405  Base        pip
0000000000206018 g    DO .data  0000000000000008  Base        f
0000000000003c80 g    DF .text  00000000000007a2  Base        Dest
0000000000206050 g    DO .bss   0000000000000008  Base        ans
0000000000004de0 g    DO .rodata        0000000000000008  Base        small_num
00000000000036c0 g    DF .text  00000000000005ba  Base        Aspect
000000000020604c g    DO .bss   0000000000000004  Base        ncol
0000000000206010 g    DO .data  0000000000000008  Base        TWOPI
0000000000004ab0 g    DF .text  000000000000028e  Base        writeascdata
0000000000004430 g    DF .text  0000000000000672  Base        Dist
0000000000001de0 g    DF .text  0000000000000634  Base        projectedPS
0000000000001770 g    DF .text  0000000000000272  Base        ccl
0000000000206038 g    DO .bss   0000000000000008  Base        out

I don’t have much experience with R packaging but I noticed that the nix-shell command did a bunch of rebuilds, which means that the package is also failing on Hydra and not publishing the binary cache.

https://hydra.nixos.org/job/nixpkgs/r-updates/rPackages.Seurat.x86_64-linux

Yes. In fact I also saw an old NixPkgs repo by @domenkozar where both SDMTools and jsonlite are already annotated as suffering this peculiar undefined symbol X error:

https://git.stoo.org/infra/nixpkgs/blob/9b7b2ce8eb855b99598183b06bbd2f021e01d359/pkgs/development/r-modules/default.nix

I think it’s caused by some build parameters, as I’m able to build the package by hand and it works both in an Arch Linux Docker and in a FHS User Environment. I’ve not been able to bisect the exact cause, though.

This issue is likely related to: Weird undefined symbol error after patchelf · Issue #45 · NixOS/patchelf · GitHub

Not sure why only a few R packages are affected.