statnet / lolog

Latent Order Logistic (LOLOG) Graph Models
Other
5 stars 1 forks source link

segfault installing example package #1

Closed nfultz closed 6 years ago

nfultz commented 6 years ago

I tried installing the example package, it compiles just fine but then fails to load. ??? :(

nfultz@neal-SH97:~$R CMD INSTALL R/x86_64-pc-linux-gnu-library/3.4/lolog/examplePackage/LologExtension 
* installing to library '/home/nfultz/R/x86_64-pc-linux-gnu-library/3.4'
* installing *source* package 'LologExtension' ...
** libs
g++  -I/usr/share/R/include -DNDEBUG  -I"/home/nfultz/R/x86_64-pc-linux-gnu-library/3.4/Rcpp/include" -I"/home/nfultz/R/x86_64-pc-linux-gnu-library/3.4/lolog/include" -I"/home/nfultz/R/x86_64-pc-linux-gnu-library/3.4/BH/include"    -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c MinDegree.cpp -o MinDegree.o
g++  -I/usr/share/R/include -DNDEBUG  -I"/home/nfultz/R/x86_64-pc-linux-gnu-library/3.4/Rcpp/include" -I"/home/nfultz/R/x86_64-pc-linux-gnu-library/3.4/lolog/include" -I"/home/nfultz/R/x86_64-pc-linux-gnu-library/3.4/BH/include"    -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c RcppExports.cpp -o RcppExports.o
g++  -I/usr/share/R/include -DNDEBUG  -I"/home/nfultz/R/x86_64-pc-linux-gnu-library/3.4/Rcpp/include" -I"/home/nfultz/R/x86_64-pc-linux-gnu-library/3.4/lolog/include" -I"/home/nfultz/R/x86_64-pc-linux-gnu-library/3.4/BH/include"    -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c lolog_hello_world.cpp -o lolog_hello_world.o
g++ -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o LologExtension.so MinDegree.o RcppExports.o lolog_hello_world.o -L/usr/lib/R/lib -lR
installing to /home/nfultz/R/x86_64-pc-linux-gnu-library/3.4/LologExtension/libs
** R
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded

 *** caught segfault ***
address (nil), cause 'memory not mapped'

Traceback:
 1: doTryCatch(return(expr), name, parentenv, handler)
 2: tryCatchOne(expr, names, parentenv, handlers[[1L]])
 3: tryCatchList(expr, classes, parentenv, handlers)
 4: tryCatch(fun(libname, pkgname), error = identity)
 5: runHook(".onLoad", env, package.lib, package)
 6: loadNamespace(package, lib.loc)
 7: doTryCatch(return(expr), name, parentenv, handler)
 8: tryCatchOne(expr, names, parentenv, handlers[[1L]])
 9: tryCatchList(expr, classes, parentenv, handlers)
10: tryCatch({    attr(package, "LibPath") <- which.lib.loc    ns <- loadNamespace(package, lib.loc)    env <- attachNamespace(ns, pos = pos, deps)}, error = function(e) {    P <- if (!is.null(cc <- conditionCall(e)))         paste(" in", deparse(cc)[1L])    else ""    msg <- gettextf("package or namespace load failed for %s%s:\n %s",         sQuote(package), P, conditionMessage(e))    if (logical.return)         message(paste("Error:", msg), domain = NA)    else stop(msg, call. = FALSE, domain = NA)})
11: library(pkg_name, lib.loc = lib, character.only = TRUE, logical.return = TRUE)
12: withCallingHandlers(expr, packageStartupMessage = function(c) invokeRestart("muffleMessage"))
13: suppressPackageStartupMessages(library(pkg_name, lib.loc = lib,     character.only = TRUE, logical.return = TRUE))
14: doTryCatch(return(expr), name, parentenv, handler)
15: tryCatchOne(expr, names, parentenv, handlers[[1L]])
16: tryCatchList(expr, classes, parentenv, handlers)
17: tryCatch(expr, error = function(e) {    call <- conditionCall(e)    if (!is.null(call)) {        if (identical(call[[1L]], quote(doTryCatch)))             call <- sys.call(-4L)        dcall <- deparse(call)[1L]        prefix <- paste("Error in", dcall, ": ")        LONG <- 75L        msg <- conditionMessage(e)        sm <- strsplit(msg, "\n")[[1L]]        w <- 14L + nchar(dcall, type = "w") + nchar(sm[1L], type = "w")        if (is.na(w))             w <- 14L + nchar(dcall, type = "b") + nchar(sm[1L],                 type = "b")        if (w > LONG)             prefix <- paste0(prefix, "\n  ")    }    else prefix <- "Error : "    msg <- paste0(prefix, conditionMessage(e), "\n")    .Internal(seterrmessage(msg[1L]))    if (!silent && identical(getOption("show.error.messages"),         TRUE)) {        cat(msg, file = outFile)        .Internal(printDeferredWarnings())    }    invisible(structure(msg, class = "try-error", condition = e))})
18: try(suppressPackageStartupMessages(library(pkg_name, lib.loc = lib,     character.only = TRUE, logical.return = TRUE)))
19: tools:::.test_load_package("LologExtension", "/home/nfultz/R/x86_64-pc-linux-gnu-library/3.4")
An irrecoverable exception occurred. R is aborting now ...
Segmentation fault (core dumped)
ERROR: loading failed
* removing '/home/nfultz/R/x86_64-pc-linux-gnu-library/3.4/LologExtension'

explicitly building the package first didn't help either:

nfultz@neal-SH97:~$R CMD build R/x86_64-pc-linux-gnu-library/3.4/lolog/examplePackage/LologExtension 
* checking for file 'R/x86_64-pc-linux-gnu-library/3.4/lolog/examplePackage/LologExtension/DESCRIPTION' ... OK
* preparing 'LologExtension':
* checking DESCRIPTION meta-information ... OK
* cleaning src
* checking for LF line-endings in source and make files and shell scripts
* checking for empty or unneeded directories
* building 'LologExtension_1.0.tar.gz'

nfultz@neal-SH97:~$R CMD INSTALL LologExtension_1.0.tar.gz 
* installing to library '/home/nfultz/R/x86_64-pc-linux-gnu-library/3.4'
* installing *source* package 'LologExtension' ...
** libs
g++  -I/usr/share/R/include -DNDEBUG  -I"/home/nfultz/R/x86_64-pc-linux-gnu-library/3.4/Rcpp/include" -I"/home/nfultz/R/x86_64-pc-linux-gnu-library/3.4/lolog/include" -I"/home/nfultz/R/x86_64-pc-linux-gnu-library/3.4/BH/include"    -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c MinDegree.cpp -o MinDegree.o
g++  -I/usr/share/R/include -DNDEBUG  -I"/home/nfultz/R/x86_64-pc-linux-gnu-library/3.4/Rcpp/include" -I"/home/nfultz/R/x86_64-pc-linux-gnu-library/3.4/lolog/include" -I"/home/nfultz/R/x86_64-pc-linux-gnu-library/3.4/BH/include"    -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c RcppExports.cpp -o RcppExports.o
g++  -I/usr/share/R/include -DNDEBUG  -I"/home/nfultz/R/x86_64-pc-linux-gnu-library/3.4/Rcpp/include" -I"/home/nfultz/R/x86_64-pc-linux-gnu-library/3.4/lolog/include" -I"/home/nfultz/R/x86_64-pc-linux-gnu-library/3.4/BH/include"    -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c lolog_hello_world.cpp -o lolog_hello_world.o
g++ -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o LologExtension.so MinDegree.o RcppExports.o lolog_hello_world.o -L/usr/lib/R/lib -lR
installing to /home/nfultz/R/x86_64-pc-linux-gnu-library/3.4/LologExtension/libs
** R
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded

 *** caught segfault ***
address (nil), cause 'memory not mapped'

Traceback:
 1: doTryCatch(return(expr), name, parentenv, handler)
 2: tryCatchOne(expr, names, parentenv, handlers[[1L]])
 3: tryCatchList(expr, classes, parentenv, handlers)
 4: tryCatch(fun(libname, pkgname), error = identity)
 5: runHook(".onLoad", env, package.lib, package)
 6: loadNamespace(package, lib.loc)
 7: doTryCatch(return(expr), name, parentenv, handler)
 8: tryCatchOne(expr, names, parentenv, handlers[[1L]])
 9: tryCatchList(expr, classes, parentenv, handlers)
10: tryCatch({    attr(package, "LibPath") <- which.lib.loc    ns <- loadNamespace(package, lib.loc)    env <- attachNamespace(ns, pos = pos, deps)}, error = function(e) {    P <- if (!is.null(cc <- conditionCall(e)))         paste(" in", deparse(cc)[1L])    else ""    msg <- gettextf("package or namespace load failed for %s%s:\n %s",         sQuote(package), P, conditionMessage(e))    if (logical.return)         message(paste("Error:", msg), domain = NA)    else stop(msg, call. = FALSE, domain = NA)})
11: library(pkg_name, lib.loc = lib, character.only = TRUE, logical.return = TRUE)
12: withCallingHandlers(expr, packageStartupMessage = function(c) invokeRestart("muffleMessage"))
13: suppressPackageStartupMessages(library(pkg_name, lib.loc = lib,     character.only = TRUE, logical.return = TRUE))
14: doTryCatch(return(expr), name, parentenv, handler)
15: tryCatchOne(expr, names, parentenv, handlers[[1L]])
16: tryCatchList(expr, classes, parentenv, handlers)
17: tryCatch(expr, error = function(e) {    call <- conditionCall(e)    if (!is.null(call)) {        if (identical(call[[1L]], quote(doTryCatch)))             call <- sys.call(-4L)        dcall <- deparse(call)[1L]        prefix <- paste("Error in", dcall, ": ")        LONG <- 75L        msg <- conditionMessage(e)        sm <- strsplit(msg, "\n")[[1L]]        w <- 14L + nchar(dcall, type = "w") + nchar(sm[1L], type = "w")        if (is.na(w))             w <- 14L + nchar(dcall, type = "b") + nchar(sm[1L],                 type = "b")        if (w > LONG)             prefix <- paste0(prefix, "\n  ")    }    else prefix <- "Error : "    msg <- paste0(prefix, conditionMessage(e), "\n")    .Internal(seterrmessage(msg[1L]))    if (!silent && identical(getOption("show.error.messages"),         TRUE)) {        cat(msg, file = outFile)        .Internal(printDeferredWarnings())    }    invisible(structure(msg, class = "try-error", condition = e))})
18: try(suppressPackageStartupMessages(library(pkg_name, lib.loc = lib,     character.only = TRUE, logical.return = TRUE)))
19: tools:::.test_load_package("LologExtension", "/home/nfultz/R/x86_64-pc-linux-gnu-library/3.4")
An irrecoverable exception occurred. R is aborting now ...
Segmentation fault (core dumped)
ERROR: loading failed
* removing '/home/nfultz/R/x86_64-pc-linux-gnu-library/3.4/LologExtension'
> sessionInfo()
R version 3.4.4 (2018-03-15)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.4 LTS

Matrix products: default
BLAS: /usr/lib/openblas-base/libblas.so.3
LAPACK: /usr/lib/libopenblasp-r0.2.18.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] colorout_1.1-2

loaded via a namespace (and not attached):
[1] compiler_3.4.4
ifellows commented 6 years ago

I'll have to look into this further. The only thing odd I see you doing is installing directly from your R library. It is meant to be first extracted with lologPackageSkeleton and then installed. I've checked that

R CMD INSTALL lolog/inst/examplePackage/LologExtension

works on my system. But it seems

R CMD INSTALL /Library/Frameworks/R.framework/Versions/3.4/Resources/library/lolog/examplePackage/LologExtension

also works. So it is perhaps a platform difference.

R version 3.4.0 (2017-04-21)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS  10.13.4

Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] compiler_3.4.0
nfultz commented 6 years ago

My best guess right now is that registerMinDegree is getting called before it is ready?

Might consider using C init hooks a la https://github.com/jeroen/openssl/blob/master/src/onload.c rather than .onload in zzz.R

ifellows commented 6 years ago

I've been unable to reproduce this yet, but I don't have an ubuntu system where I am right now so that is the likely cause.

I could move registration into R_init, but that would break Rcpp::compileAttributes and make extension packages a pain to develop in RStudio. I've made some edits to the way the c++ registration code was called in the extension package. Neal, can you try again using the ext branch of lolog and see if the changes make any difference?

ifellows commented 6 years ago

I was able to reproduce on an ubuntu machine. This is fixed by #2 .