Skip to content

Add compatibility for source maps with v8's stack frame format - #8762

Merged
quantum5 merged 5 commits into
emscripten-core:incomingfrom
quantum5:v8-offset-hack
Jun 13, 2019
Merged

quantum5 merged 5 commits into
emscripten-core:incomingfrom
quantum5:v8-offset-hack

Conversation

@quantum5

@quantum5 quantum5 commented Jun 7, 2019 •

Copy link
Copy Markdown
Member

This change also makes __builtin_return_address return consistent results on all engines.

Consider null-read.c:

int main(void) {
    int *a = 0, b;
    b = *a;
}

Let's compile it with UBSan, enable debug info, turn on stack trace printing by changing the environment:

$ emcc -g4 -fsanitize=null null-read.c
$ perl -pi -e "s/(?<=ENV=){}/{'UBSAN_OPTIONS': 'print_stacktrace=1'}/" a.out.js

Stack traces display properly on all major engines with original file and line number:

$ node a.out.js 
null-read.c:3:9: runtime error: load of null pointer of type 'int'
    #0 0x72f in main /.../null-read.c:3:9
    #1 0x80001890 in Object.Module._main /.../a.out.js:6288:32

$ d8 a.out.js 
null-read.c:3:9: runtime error: load of null pointer of type 'int'
    #0 0x72f in main /.../null-read.c:3:9
    #1 0x80001890 in Object.Module._main a.out.js:6288:32

$ sm a.out.js 
null-read.c:3:9: runtime error: load of null pointer of type 'int'
    #0 0x72f in main /.../null-read.c:3:9
    #1 0x80001890 in Module._main a.out.js:6288:32
    #2 0x80001985 in callMain a.out.js:6533:22
    #3 0x800019bf in doRun a.out.js:6591:49
    #4 0x800019cd in run a.out.js:6605:5
    #5 0x8000196e in runCaller a.out.js:6510:29
    #6 0x800005e7 in removeRunDependency a.out.js:1511:7
    #7 0x800006ff in receiveInstance a.out.js:1791:5
    #8 0x80000715 in receiveInstantiatedSource a.out.js:1813:5

@quantum5
quantum5 requested review from aheejin, kripken and tlively June 7, 2019 17:21
Comment thread src/preamble.js Resolved
Comment thread src/wasm_offset_converter.js Resolved
Comment thread src/preamble.js Resolved
Comment thread src/wasm_offset_converter.js Resolved
Comment thread src/wasm_offset_converter.js Resolved
Comment thread src/wasm_offset_converter.js Resolved
@quantum5
quantum5 requested a review from kripken June 12, 2019 21:04

@kripken kripken left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm with that last comment resolved

Comment thread src/wasm_offset_converter.js Outdated
// since functions defined in the module are numbered after all imports
var count = unsignedLEB128();

while (count --> 0) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This --> notation seems surprising... it's (count--) > 0, correct? might be clearer as count-- > 0 so it doesn't look like an arrow.

@quantum5
quantum5 merged commit cb04f26 into emscripten-core:incoming Jun 13, 2019
@quantum5
quantum5 deleted the v8-offset-hack branch June 18, 2019 01:00
belraquib pushed a commit to belraquib/emscripten that referenced this pull request Dec 23, 2020
…ipten-core#8762)

This change allows source maps to work on v8 builds with v8 bug
https://crbug.com/v8/9172.

This change also makes `__builtin_return_address` return consistent results on
all engines.
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

Successfully merging this pull request may close these issues.

2 participants