1

Investigating a segfault in my code, looking for GetBuiltinsCount in the V8 source code leads me to this comment:

/**
 * NativesStore stores the 'native' (builtin) JS libraries.
 *
 * NativesStore needs to be initialized before using V8, usually by the
 * embedder calling v8::SetNativesDataBlob, which calls SetNativesFromFile
 * below.
 */

How am I, the embedder supposed to use v8::SetNativesDataBlob?

The d8 interpreter does call this method, but it's not at all clear what it's doing and why. The basic samples do not call this method.

Boinst
  • 3,365
  • 2
  • 38
  • 60
  • 1
    Is that the complete stack trace? It doesn't start in your code? Have you tried running a debug build in a debugger to confirm the crash isn't actually because of something you did? If you build with extra warnings enabled, do you get any warnings? – Some programmer dude Jun 30 '15 at 05:37
  • @JoachimPileborg, I left out the frames showing my own code, they are not interesting. The crash literally happens on the line where I call `Isolate::New()`. This is a debug build, compiled warning-free. I will run in gdb now to see if that gives me any useful info, but I doubt it. This code is running fine on some systems but not others. – Boinst Jun 30 '15 at 05:53
  • 1
    Running "fine on some systems but not others" is a typical sign of *undefined behavior*. Try enabling even *more* warnings when building, like e.g. `-Wall -Wextra -pedantic` on GCC. – Some programmer dude Jun 30 '15 at 05:57
  • That's good advice. I'll try with `pedantic`. I already have `-Wall` and `-Wextra`. – Boinst Jun 30 '15 at 06:08
  • 2
    And if you don't find anything wrong with your code, even after stepping through your code line by line to make sure it works, there *could* be a bug in V8. It's big and complicated and complex, and all big, complicated and complex pieces of code have bugs in them, so don't be afraid to report it to the V8 project as such if you can't find anything in your code. Even better would be if you could pinpoint what and where in their code the problem is. Also, when reporting bugs it's even more important to create a [MCVE](http://stackoverflow.com/help/mcve) then when asking questions here on SO. – Some programmer dude Jun 30 '15 at 06:14

1 Answers1

0

A bit over a year later, I find myself back at this question, and now I know the answer.

You can compile V8 with external startup data ("snapshot") or without.

If you compiled with snapshot data, call V8::InitializeExternalStartupData as shown in the Hello World example code. You don't call v8::SetNativesDataBlob directly.

Otherwise, the solution is to compile without snapshot data. Then, you don't need to call either of the aforementioned functions at all. Here's one answer on how to configure this in your build process. Note, using snapshot data decreases process start-up time.

Community
  • 1
  • 1
Boinst
  • 3,365
  • 2
  • 38
  • 60