Segfault when compiling module
If you compile the AssemblyScript program:
export declare function test(): void
into WebAssembly (or use this one I already compiled):
asc test.ts --binaryFile test.wasm
Then into C:
w2c2 -o test.c test.wasm
you get a segfault:
fish: Job 1, '~/w2c2/w2c2 -o test.c test.wasm' terminated by signal SIGSEGV (Address boundary error)
Backtrace:
(gdb) backtrace
#0 wasmCWriteExports (file=0x5615678c32a0, module=0x5615678c3480, pretty=false, external=true) at c.c:3187
#1 0x0000561565bb8338 in wasmCWriteModuleDeclarations (file=0x5615678c32a0, module=0x5615678c3480, parallel=false, pretty=false) at c.c:3626
#2 0x0000561565bb8566 in wasmCWriteDeclarations (module=0x5615678c3480, singleFile=0x5615678c32a0, pretty=false) at c.c:3687
#3 0x0000561565bb8960 in wasmCWriteModule (module=0x5615678c3480, options=...) at c.c:4100
#4 0x0000561565bba9f2 in main (argc=4, argv=0x7ffcf43a12f8) at main.c:184
(gdb)
Happens here: https://github.com/turbolent/w2c2/blob/main/c.c#L3187
Wait, maybe I shouldn't have put the export, but it also crashes without that so I don't think that's the issue
functionIndex ends up being negative
This looks like it would be easy to fix but I don't understand the code properly so I can't
Actually the zip I posted doesn't seem to match my code, and I can't reproduce by compiling AssemblyScript now?
@Heath123 Did you end up being able to reproduce the problem? If so, could you provide a binary?
(module
(type $none_=>_none (func))
(import "module" "test" (func $module/test))
(memory $0 0)
(export "test" (func $module/test))
(export "memory" (memory $0))
)
binary: test.wasm.zip
@Heath123 Did you end up being able to reproduce the problem? If so, could you provide a binary?
The zip I attached does reproduce the issue, I just meant that it doesn’t match the AssemblyScript code I posted
```webassembly (module (type $none_=>_none (func)) (import "module" "test" (func $module/test)) (memory $0 0) (export "test" (func $module/test)) (export "memory" (memory $0)) )binary: test.wasm.zip
Thanks, it must be getting confused that it’s importing and exporting the same thing
@Heath123 @MaxGraey Thank you for reporting this bug and providing a reproducer