Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segfault on make_context #32

Closed
sjewo opened this issue Jan 20, 2017 · 20 comments
Closed

Segfault on make_context #32

sjewo opened this issue Jan 20, 2017 · 20 comments

Comments

@sjewo
Copy link

sjewo commented Jan 20, 2017

Hi! I run into a segfault while initializing with 'v8()'.

I'm using Archlinux, R 3.3.2 with Intel MKL and V8 3.14.5.7-2. I tested this on a second system with Archlinux, R 3.3.2-2 (Package from Archlinux) and V8 3.14 and V8 3.15 from AUR and get the same results.

I attached debug output from lldb. Any idea how to fix this?

Thanks a lot!

(lldb) target create "/usr/lib64/R/bin/exec/R"
Current executable set to '/usr/lib64/R/bin/exec/R' (x86_64).
(lldb) run
Process 5270 launched: '/usr/lib64/R/bin/exec/R' (x86_64)

R version 3.3.2 (2016-10-31) -- "Sincere Pumpkin Patch"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-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.

NULL
> library(V8)
> v8()
Process 5270 stopped
* thread #1: tid = 5270, 0x00007fffe9b28030 libv8.so`___lldb_unnamed_symbol7623$$libv8.so + 32, name = 'R', stop reason = signal SIGSEGV: invalid address (fault address: 0x18)
    frame #0: 0x00007fffe9b28030 libv8.so`___lldb_unnamed_symbol7623$$libv8.so + 32
libv8.so`___lldb_unnamed_symbol7623$$libv8.so:
->  0x7fffe9b28030 <+32>: movq   0x18(%rsi), %rdx
    0x7fffe9b28034 <+36>: movq   (%rsi), %rbx
    0x7fffe9b28037 <+39>: movq   %rdx, %rax
    0x7fffe9b2803a <+42>: movq   %rdx, %rcx
(lldb) bt
* thread #1: tid = 5270, 0x00007fffe9b28030 libv8.so`___lldb_unnamed_symbol7623$$libv8.so + 32, name = 'R', stop reason = signal SIGSEGV: invalid address (fault address: 0x18)
  * frame #0: 0x00007fffe9b28030 libv8.so`___lldb_unnamed_symbol7623$$libv8.so + 32
    frame #1: 0x00007fffe9b280d3 libv8.so`___lldb_unnamed_symbol7624$$libv8.so + 35
    frame #2: 0x00007fffe99d3130 libv8.so`___lldb_unnamed_symbol2390$$libv8.so + 560
    frame #3: 0x00007fffe99d81ea libv8.so`___lldb_unnamed_symbol2447$$libv8.so + 26
    frame #4: 0x00007fffe99dcaa2 libv8.so`___lldb_unnamed_symbol2504$$libv8.so + 962
    frame #5: 0x00007fffe9a43fdc libv8.so`___lldb_unnamed_symbol4366$$libv8.so + 1228
    frame #6: 0x00007fffe9946c4e libv8.so`___lldb_unnamed_symbol82$$libv8.so + 46
    frame #7: 0x00007fffe994aa16 libv8.so`v8::ObjectTemplate::New(v8::Handle<v8::FunctionTemplate>) + 86
    frame #8: 0x00007fffe994ad7b libv8.so`v8::ObjectTemplate::New() + 11
    frame #9: 0x00007fffe9ef1261 V8.so`make_context(bool) + 33
    frame #10: 0x00007fffe9ef0fd2 V8.so`V8_make_context + 130
    frame #11: 0x00007ffff784667c libR.so`___lldb_unnamed_symbol825$$libR.so + 284
    frame #12: 0x00007ffff7808daa libR.so`Rf_eval + 1850
    frame #13: 0x00007ffff7849886 libR.so`___lldb_unnamed_symbol842$$libR.so + 918
    frame #14: 0x00007ffff7808f41 libR.so`Rf_eval + 2257
    frame #15: 0x00007ffff7835317 libR.so`Rf_applyClosure + 999
    frame #16: 0x00007ffff78088c1 libR.so`Rf_eval + 593
    frame #17: 0x00007ffff7806f7b libR.so`___lldb_unnamed_symbol722$$libR.so + 59
    frame #18: 0x00007ffff7808f41 libR.so`Rf_eval + 2257
    frame #19: 0x00007ffff7849886 libR.so`___lldb_unnamed_symbol842$$libR.so + 918
    frame #20: 0x00007ffff7808f41 libR.so`Rf_eval + 2257
    frame #21: 0x00007ffff7835317 libR.so`Rf_applyClosure + 999
    frame #22: 0x00007ffff78088c1 libR.so`Rf_eval + 593
    frame #23: 0x00007ffff7849886 libR.so`___lldb_unnamed_symbol842$$libR.so + 918
    frame #24: 0x00007ffff7808f41 libR.so`Rf_eval + 2257
    frame #25: 0x00007ffff78062dd libR.so`___lldb_unnamed_symbol715$$libR.so + 1437
    frame #26: 0x00007ffff780af08 libR.so`___lldb_unnamed_symbol727$$libR.so + 5560
    frame #27: 0x00007ffff78087b3 libR.so`Rf_eval + 323
    frame #28: 0x00007ffff7835317 libR.so`Rf_applyClosure + 999
    frame #29: 0x00007ffff78088c1 libR.so`Rf_eval + 593
    frame #30: 0x00007ffff78062dd libR.so`___lldb_unnamed_symbol715$$libR.so + 1437
    frame #31: 0x00007ffff780af08 libR.so`___lldb_unnamed_symbol727$$libR.so + 5560
    frame #32: 0x00007ffff78087b3 libR.so`Rf_eval + 323
    frame #33: 0x00007ffff7835317 libR.so`Rf_applyClosure + 999
    frame #34: 0x00007ffff780ac1f libR.so`___lldb_unnamed_symbol727$$libR.so + 4815
    frame #35: 0x00007ffff78087b3 libR.so`Rf_eval + 323
    frame #36: 0x00007ffff7835317 libR.so`Rf_applyClosure + 999
    frame #37: 0x00007ffff780ac1f libR.so`___lldb_unnamed_symbol727$$libR.so + 4815
    frame #38: 0x00007ffff78087b3 libR.so`Rf_eval + 323
    frame #39: 0x00007ffff7835317 libR.so`Rf_applyClosure + 999
    frame #40: 0x00007ffff78088c1 libR.so`Rf_eval + 593
    frame #41: 0x00007ffff7806e4f libR.so`___lldb_unnamed_symbol721$$libR.so + 191
    frame #42: 0x00007ffff7808f41 libR.so`Rf_eval + 2257
    frame #43: 0x00007ffff7849886 libR.so`___lldb_unnamed_symbol842$$libR.so + 918
    frame #44: 0x00007ffff7808f41 libR.so`Rf_eval + 2257
    frame #45: 0x00007ffff7835317 libR.so`Rf_applyClosure + 999
    frame #46: 0x00007ffff78088c1 libR.so`Rf_eval + 593
    frame #47: 0x00007ffff784b6ee libR.so`Rf_ReplIteration + 558
    frame #48: 0x00007ffff784b47c libR.so`___lldb_unnamed_symbol854$$libR.so + 172
    frame #49: 0x00007ffff787e800 libR.so`run_Rmainloop + 96
    frame #50: 0x000000000040531c R`main + 92
    frame #51: 0x00007ffff6b29291 libc.so.6`__libc_start_main + 241
    frame #52: 0x00000000004051ea R`_start + 42
@jeroen
Copy link
Owner

jeroen commented Jan 20, 2017

Hm I've never seen this. Other people have used V8 on arch just fine. Could it be that arch has recently updated it's compilers but has not yet rebuilt the libv8 package yet in aur?

@sjewo
Copy link
Author

sjewo commented Jan 20, 2017

I did compile V8 myself from source, so this shouldn't be a compiler issue. My collegue @JanMarvin also tried to use the package on Archlinux and got a segfault:

> v8()

 *** caught segfault ***
address 0x18, cause 'memory not mapped'

Traceback:
 1: .Call("V8_make_context", PACKAGE = "V8", set_console)
 2: make_context(private$console)
 3: reset()
 4: eval(expr, envir, enclos)
 5: eval(quote({    eval <- function(src) {        get_str_output(context_eval(join(src), private$context))    }    validate <- function(src) {        context_validate(join(src), private$context)    }    call <- function(fun, ..., auto_unbox = TRUE) {        stopifnot(is.character(fun))        stopifnot(this$validate(c("fun=", fun)))        jsargs <- list(...)        if (!is.null(names(jsargs))) {            stop("Named arguments are not supported in JavaScript.")        }        jsargs <- vapply(jsargs, function(x) {            if (is.atomic(x) && inherits(x, "JS_EVAL")) {                as.character(x)            } else {                toJSON(x, auto_unbox = auto_unbox)            }        }, character(1))        jsargs <- paste(jsargs, collapse = ",")        src <- paste0("JSON.stringify((", fun, ")(", jsargs,             "));")        out <- this$eval(src)        get_json_output(out)    }    source <- function(file) {        if (is.character(file) && length(file) == 1 && grepl("^https?://",             file)) {            file <- curl(file, open = "r")            on.exit(close(file))        }        this$eval(readLines(file, encoding = "UTF-8", warn = FALSE))    }    get <- function(name, ...) {        stopifnot(is.character(name))        get_json_output(this$eval(c("JSON.stringify(", name,             ")")), ...)    }    assign <- function(name, value, auto_unbox = TRUE, ...) {        stopifnot(is.character(name))        obj <- if (inherits(value, "JS_EVAL")) {            invisible(this$eval(paste("var", name, "=", value)))        } else {            invisible(this$eval(paste("var", name, "=", toJSON(value,                 auto_unbox = auto_unbox, ...))))        }    }    reset <- function() {        private$context <- make_context(private$console)        private$created <- Sys.time()        if (length(global)) {            context_eval(paste("var", global, "= this;", collapse = "\n"),                 private$context)        }        if (isTRUE(typed_arrays)) {            context_enable_typed_arrays(private$context)        }        invisible()    }    console <- function() {        this$eval("")        message("This is V8 version ", version(), ". Press ESC or CTRL+C to exit.")        on.exit(message("Exiting V8 console."))        buffer <- character()        has_history <- !inherits(try(savehistory(tempfile()),             silent = T), "try-error")        if (has_history) {            savehistory()            on.exit(loadhistory(), add = TRUE)            histfile <- ".V8history"            if (file.exists(histfile)) {                loadhistory(histfile)            } else {                file.create(histfile)            }        }        rc.options(custom.completer = function(env) {            env$comps <- tab_complete(this, env$token)        })        on.exit({            rc.options(custom.completer = NULL)        }, add = TRUE)        repeat {            prompt <- ifelse(length(buffer), "  ", "~ ")            if (nchar(line <- readline(prompt))) {                buffer <- c(buffer, line)            }            if (identical(buffer, "exit")) break            if (length(buffer) && (this$validate(buffer) || !nchar(line))) {                if (has_history) {                  write(buffer, histfile, append = TRUE)                  loadhistory(histfile)                }                tryCatch(cat(undefined_to_null(this$eval(buffer))),                   error = function(e) {                    message(e$message)                  })                buffer <- character()            }        }    }    reset()    lockEnvironment(environment(), TRUE)    structure(environment(), class = c("V8", "environment"))}), new.env())
 6: eval(expr, envir, enclos)
 7: eval(expr, p)
 8: eval.parent(substitute(eval(quote(expr), envir)))
 9: local({    eval <- function(src) {        get_str_output(context_eval(join(src), private$context))    }    validate <- function(src) {        context_validate(join(src), private$context)    }    call <- function(fun, ..., auto_unbox = TRUE) {        stopifnot(is.character(fun))        stopifnot(this$validate(c("fun=", fun)))        jsargs <- list(...)        if (!is.null(names(jsargs))) {            stop("Named arguments are not supported in JavaScript.")        }        jsargs <- vapply(jsargs, function(x) {            if (is.atomic(x) && inherits(x, "JS_EVAL")) {                as.character(x)            }            else {                toJSON(x, auto_unbox = auto_unbox)            }        }, character(1))        jsargs <- paste(jsargs, collapse = ",")        src <- paste0("JSON.stringify((", fun, ")(", jsargs,             "));")        out <- this$eval(src)        get_json_output(out)    }    source <- function(file) {        if (is.character(file) && length(file) == 1 && grepl("^https?://",             file)) {            file <- curl(file, open = "r")            on.exit(close(file))        }        this$eval(readLines(file, encoding = "UTF-8", warn = FALSE))    }    get <- function(name, ...) {        stopifnot(is.character(name))        get_json_output(this$eval(c("JSON.stringify(", name,             ")")), ...)    }    assign <- function(name, value, auto_unbox = TRUE, ...) {        stopifnot(is.character(name))        obj <- if (inherits(value, "JS_EVAL")) {            invisible(this$eval(paste("var", name, "=", value)))        }        else {            invisible(this$eval(paste("var", name, "=", toJSON(value,                 auto_unbox = auto_unbox, ...))))        }    }    reset <- function() {        private$context <- make_context(private$console)        private$created <- Sys.time()        if (length(global)) {            context_eval(paste("var", global, "= this;", collapse = "\n"),                 private$context)        }        if (isTRUE(typed_arrays)) {            context_enable_typed_arrays(private$context)        }        invisible()    }    console <- function() {        this$eval("")        message("This is V8 version ", version(), ". Press ESC or CTRL+C to exit.")        on.exit(message("Exiting V8 console."))        buffer <- character()        has_history <- !inherits(try(savehistory(tempfile()),             silent = T), "try-error")        if (has_history) {            savehistory()            on.exit(loadhistory(), add = TRUE)            histfile <- ".V8history"            if (file.exists(histfile)) {                loadhistory(histfile)            }            else {                file.create(histfile)            }        }        rc.options(custom.completer = function(env) {            env$comps <- tab_complete(this, env$token)        })        on.exit({            rc.options(custom.completer = NULL)        }, add = TRUE)        repeat {            prompt <- ifelse(length(buffer), "  ", "~ ")            if (nchar(line <- readline(prompt))) {                buffer <- c(buffer, line)            }            if (identical(buffer, "exit"))                 break            if (length(buffer) && (this$validate(buffer) || !nchar(line))) {                if (has_history) {                  write(buffer, histfile, append = TRUE)                  loadhistory(histfile)                }                tryCatch(cat(undefined_to_null(this$eval(buffer))),                   error = function(e) {                    message(e$message)                  })                buffer <- character()            }        }    }    reset()    lockEnvironment(environment(), TRUE)    structure(environment(), class = c("V8", "environment"))})
10: v8()

Possible actions:
1: abort (with core dump, if enabled)
2: normal R exit
3: exit R without saving workspace
4: exit R saving workspace
Selection:

@jeroen
Copy link
Owner

jeroen commented Jan 20, 2017

That's very strange. Can you test if libv8 itself is fine? I think it comes with a command line utility called d8 which you can use to run some JS code.

@sjewo
Copy link
Author

sjewo commented Jan 20, 2017

Good point - d8 segfaults too. So this is a problem with libv8 (I didn't know how to test the library).

d8[2113]: segfault at 18 ip 00007f0e60be0030 sp 00007ffde63590b0 error 4 in libv8.so.3.14.5[7f0e609a0000+3d1000]

@jeroen
Copy link
Owner

jeroen commented Jan 20, 2017

Do you have multilple versions of libv8 installed on the system?

@sjewo
Copy link
Author

sjewo commented Jan 20, 2017

No, just 3.14.5

find / -name "libv8.so*"

/usr/lib/libv8.so.3.14.5
/usr/lib/libv8.so

@jeroen
Copy link
Owner

jeroen commented Jan 20, 2017

Hmm well then something is wrong with the library :/ Perhaps it doensn't work well with the latest compilers. Try building from: https://github.com/v8-314

@jeroen
Copy link
Owner

jeroen commented Jan 20, 2017

I'm closing this issue because it is not a problem in the R bindings but in your build of libv8. You'll have to talk to the AUR maintainer or v8 developers to figure out what's going on....

@jeroen jeroen closed this as completed Jan 20, 2017
@sjewo
Copy link
Author

sjewo commented Jan 20, 2017

Just for reference: v8 needs a patch to compile with gcc 6 (thanks to @JanMarvin for finding the patch!). I attached a working PKGBUILD using the code form https://github.com/v8-314

# $Id$
# Maintainer: Sebastian Jeworutzki <sebastian.jeworutzki@rub.de>
# Based on a PKGBUILD from:  Kaiting Chen <kaitocracy@gmail.com>
# Contributor: tocer <tocer.deng@gmail.com>

pkgname=v8-3.14
pkgver=3.14.5.10
pkgrel=2
pkgdesc='A fast and modern javascript engine (old 3.14 version required for plv8)'
arch=('i686' 'x86_64')
url='http://code.google.com/p/v8'
license=('BSD')
depends=('gcc-libs' 'readline' 'gyp-git' 'valgrind')
makedepends=('subversion' 'python2')
source=("https://github.com/v8-314/v8/archive/3.14.zip"
"patch::https://bugzilla.redhat.com/attachment.cgi?id=1164037")
md5sums=('9d0fc7ffa2be8cac2f2c40d7c6d42544'
         '59793aec59364ec74a3c84d894dc71d8')

provides=('v8')
conflicts=('v8')

[[ "$CARCH" = 'i686' ]]   && ARCH=ia32
[[ "$CARCH" = 'x86_64' ]] && ARCH=x64

build() {
  cd $pkgname
  mkdir -p build/gyp/

  ln -fs /usr/bin/gyp build/gyp/gyp 

  # The world isn't ready for python2
  export PYTHON=python2
  find build/ test/ tools/ src/ -type f \
    -exec sed -e 's_^#!/usr/bin/env python$_&2_' \
              -e 's_^\(#!/usr/bin/python2\).[45]$_\1_' \
              -e 's_^#!/usr/bin/python$_&2_' \
              -e "s_'python'_'python2'_" -i {} \;
  sed -i 's/python /python2 /' Makefile

  # Delete non working test
   sed -i '/THREADED_TEST(Regress260106)/,+8d'  test/cctest/test-api.cc
  
   msg "patch for gcc 6"
 # Use "-fno-delete-null-pointer-checks" to workaround GCC 6.x compatibility
 # deps patch from https://bugzilla.redhat.com/attachment.cgi?id=1164037
   sed -i 's/\/v8\//\//g' ../patch
   patch -p1 < ../patch

  # -Werror causes errors with newer versions of GCC
  sed -i 's/-Werror//' build/standalone.gypi build/common.gypi

  make $ARCH.release library=shared console=readline snapshot=off extrachecks=off werror=off debuggersupport=on
}

package() {
  cd $pkgname

  install -Dm755 out/$ARCH.release/d8 $pkgdir/usr/bin/d8
  install -Dm755 out/$ARCH.release/lib.target/libv8.so $pkgdir/usr/lib/libv8.so.3.14.5

  install -d $pkgdir/usr/include
  install -Dm644 include/*.h $pkgdir/usr/include

  install -d $pkgdir/usr/share/licenses/v8
  install -m644 LICENSE* ${pkgdir}/usr/share/licenses/v8
}

@jeroen
Copy link
Owner

jeroen commented Jan 20, 2017

For the full list of patches see also:

@pat-s
Copy link

pat-s commented Nov 15, 2017

@sjewo aur/v8-3.14 installs and also R package v8 but it results in segfault errors. Do you currently have a working v8 build?

@jeroen
Copy link
Owner

jeroen commented Nov 15, 2017

Can someone try to report this upstream to the arch maintainers?

@pat-s
Copy link

pat-s commented Nov 15, 2017

I'm currently building the patch from @sjewo and if its works I will foward it to the AUR maintainer.

Edit: Works and I will report this tomorrow :)

@pat-s
Copy link

pat-s commented Nov 15, 2017

hm, works for installing jsonvalidate but geojsonlint throws the next error :/

* installing *source* package ‘geojsonlint’ ...
** package ‘geojsonlint’ successfully unpacked and MD5 sums checked
** R
** data
*** moving datasets to lazyload DB
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded

 *** caught segfault ***
address 0x18, cause 'memory not mapped'

Traceback:
 1: .Call("V8_context_eval", PACKAGE = "V8", src, ctx)
 2: context_eval(join(src), private$context)
 3: identical(str, "undefined")

@jeroen
Copy link
Owner

jeroen commented Nov 15, 2017

You can also try building this one: https://github.com/v8-314/v8

@JanMarvin
Copy link
Contributor

I have an arch linux PKGBUILD based on the debian package lying around that appears to be working. I'll mail you a copy @pat-s

@dickoa
Copy link

dickoa commented Jan 20, 2018

@JanMarvin I would also be interested since I also have the same issue @pat-s has: v8-3.14 and the R package seems to work but I can't load jsonvalidate or geojsonlint.
Thanks

@jeroen
Copy link
Owner

jeroen commented Jan 21, 2018

Are you also on arch Linux?

@pat-s
Copy link

pat-s commented Mar 4, 2018

I uploaded a fixed version for the "v8-3.14" AUR package as the original maintainer orphaned it.

Thanks to @JanMarvin for the source!

@liuxch5
Copy link

liuxch5 commented Jul 6, 2019

I solve this problem by this
sudo apt remove libv8*
sudo aptitude install libnode-dev
hope this could help you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants