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

segmentation fault when running clang built wasm #7

Open
xyproto opened this issue Aug 1, 2018 · 2 comments
Open

segmentation fault when running clang built wasm #7

xyproto opened this issue Aug 1, 2018 · 2 comments

Comments

@xyproto
Copy link

xyproto commented Aug 1, 2018

When running wac on sha1sum.wasm from the vmir project, I get the following error:

./wac ~/clones/vmir/examples/prebuilt/sha1sum.wasm
zsh: segmentation fault (core dumped)  ./wac ~/clones/vmir/examples/prebuilt/sha1sum.wasm

I'm using:

  • latest master of wac, commit 1197a2d
  • 64-bit Arch Linux with the official gcc package (gcc 8.1.1)
  • lib32-libedit from AUR

When compiling with -O1 -g and using bt full in gdb, this is the output:

(gdb) r ~/clones/vmir/examples/prebuilt/sha1sum.wasm
Starting program: /home/afr/clones/wac/wac ~/clones/vmir/examples/prebuilt/sha1sum.wasm

Program received signal SIGSEGV, Segmentation fault.
0xf7dae279 in __memset_sse2 () from /usr/lib32/libc.so.6
(gdb) bt full
#0  0xf7dae279 in __memset_sse2 () from /usr/lib32/libc.so.6
No symbol table info available.
#1  0x565655b0 in thunk_out_i_iii (m=0xf7b2d010, function=0x5658b2b8, type=0x5658a6dc) at thunks.c:454
        res = <optimized out>
#2  0x5655fc11 in thunk_out (m=0xf7b2d010, fidx=2) at wa.c:544
        func = 0x5658b2b8
        type = 0x5658a6dc
        thunk_mask = 8454417
        p = <optimized out>
#3  0x565601e3 in interpret (m=0xf7b2d010) at wa.c:809
        block = <optimized out>
        prev_pages = <optimized out>
        sval = <optimized out>
        didx = <optimized out>
        delta = <optimized out>
        bytes = 0xf7fd0000 ""
        stack = 0xf7b2d074
        cur_pc = 492
        block = <optimized out>
        arg = <optimized out>
        val = <optimized out>
        fidx = <optimized out>
        tidx = <optimized out>
        cond = <optimized out>
        depth = <optimized out>
        count = <optimized out>
        flags = <optimized out>
        offset = <optimized out>
        addr = <optimized out>
        maddr = <optimized out>
        mem_end = <optimized out>
        depths = <optimized out>
        opcode = 16 '\020'
        a = <optimized out>
        b = <optimized out>
        c = 4294967104
        d = <optimized out>
        e = <optimized out>
        f = 6221221224307818496
        g = <optimized out>
        h = <optimized out>
        i = -1.03310949e+34
        j = <optimized out>
        k = <optimized out>
        l = 1.3447704791445071e-313
        overflow = false
#4  0x56563be8 in invoke (m=0xf7b2d010, entry=<optimized out>, argc=-1, argv=0xffffd0c0) at wa.c:1997
        fidx = 6
        type = 0x5658a6a0
        result = <optimized out>
#5  0x5655eec7 in main (argc=<optimized out>, argv=<optimized out>) at wac.c:63
        mod_path = <optimized out>
        entry = <optimized out>
        line = <optimized out>
        repl = 0
        debug = 0
        res = 0
        option_index = 0
        c = <optimized out>
        long_options = {{name = 0x5657545c "repl", has_arg = 0, flag = 0xffffcfac, val = 1}, {name = 0x56575461 "debug", has_arg = 0, flag = 0xffffcfb0, val = 1}, {name = 0x0, has_arg = 0, flag = 0x0, val = 0}}
        opts = {disable_memory_bounds = false, mangle_table_index = false, dlsym_trim_underscore = false}
        m = <optimized out>
(gdb)

The problematic line could be line 454 in thunks.c?

@kanaka
Copy link
Owner

kanaka commented Aug 1, 2018

I suspect the linkage isn't setup the way wac/wace is expecting so the libc memset is being called with an invalid pointer. I've only tested C programs built the way I describe in the README.md (using a recent version of binaryen and emscripten). I.e. like this:

emcc $(CFLAGS) -s WASM=1 -s SIDE_MODULE=1 -s LEGALIZE_JS_FFI=0 prog.c -o prog.wasm

The prebuilt sha1sum.wasm file in vmir was built using clang/llvm via LLVM IR form. I would actually have been surprised if that worked without tweaks. It's probably something that we want to get working although I won't have time to work on this any time in the near future although I would be happy to take a pull request and answer specific questions about why wac/wace work the way they do.

@kanaka kanaka changed the title segmentation fault (core dumped) ./wac segmentation fault when running clang built wasm Aug 1, 2018
@xyproto
Copy link
Author

xyproto commented Aug 1, 2018

Ok, thanks for the response. :)

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

2 participants