ldc icon indicating copy to clipboard operation
ldc copied to clipboard

Wasm: missing DWARF info support

Open kassane opened this issue 1 year ago • 11 comments

Environment

OS: ArchLinux CPU: x86_64(zen3) LDC version: master (ref.: v1.40.0-beta6) Emscripten version: 3.1.73 (LLVM 20)

I have been attempting to get results in flamegraph for wasm and debugging too. However, the binary generated doesn't identify dwarf.

Flags added: -g --exception-model=wasm -wasm-enable-eh

output error
run-mrt
└─ run /home/kassane/.cache/zig/p/1220d2b37748757d43de92f0ef723b6a00c3cae4b6a9c582b607421704498a5cfd2b/upstream/emscripten/emrun
   └─ install generated/
      └─ emcc failure
warning: unknown subopcode 5 (this may be an unsupported version of DWARF)
warning: unknown subopcode 37 (this may be an unsupported version of DWARF)
warning: unknown subopcode 5 (this may be an unsupported version of DWARF)
warning: unknown subopcode 5 (this may be an unsupported version of DWARF)
warning: unknown subopcode 5 (this may be an unsupported version of DWARF)
warning: unknown subopcode 5 (this may be an unsupported version of DWARF)
warning: unknown subopcode 5 (this may be an unsupported version of DWARF)
warning: unknown subopcode 5 (this may be an unsupported version of DWARF)
warning: unknown subopcode 91 (this may be an unsupported version of DWARF)
warning: unknown subopcode 58 (this may be an unsupported version of DWARF)
warning: unknown subopcode 58 (this may be an unsupported version of DWARF)
warning: unknown subopcode 6 (this may be an unsupported version of DWARF)
Fatal: TODO: DW_LNE_define_file
emcc: error: '/home/kassane/.cache/zig/p/1220d2b37748757d43de92f0ef723b6a00c3cae4b6a9c582b607421704498a5cfd2b/upstream/bin/wasm-emscripten-finalize -g --dyncalls-i64 --pass-arg=legalize-js-interface-exported-helpers --dwarf /home/kassane/sokol-d/.zig-cache/o/77fae0c550cc9c7e0381a1aa0d73b9e8/mrt.wasm -o /home/kassane/sokol-d/.zig-cache/o/77fae0c550cc9c7e0381a1aa0d73b9e8/mrt.wasm --detect-features' failed (returned 1)

If replace --exception-model=wasm to --exception-model=dwarf

output error
run-mrt
└─ run /home/kassane/.cache/zig/p/1220d2b37748757d43de92f0ef723b6a00c3cae4b6a9c582b607421704498a5cfd2b/upstream/emscripten/emrun
   └─ install generated/
      └─ mrt failure
LLVM ERROR: -exception-model should be either 'none' or 'wasm'
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  ldc2      0x00005f47ee1492c7 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 39
1  ldc2      0x00005f47ee146e7c llvm::sys::RunSignalHandlers() + 188
2  ldc2      0x00005f47ee14996f
3  libc.so.6 0x00007d83eb9621d0
4  libc.so.6 0x00007d83eb9bb3f4
5  libc.so.6 0x00007d83eb962120 gsignal + 32
6  libc.so.6 0x00007d83eb9494c3 abort + 223
7  ldc2      0x00005f47ee0a88c9 llvm::report_fatal_error(llvm::Twine const&, bool) + 441
8  ldc2      0x00005f47ee0a8706
9  ldc2      0x00005f47eab2dff1
10 ldc2      0x00005f47ecf6c0b3 llvm::TargetPassConfig::addISelPasses() + 163
11 ldc2      0x00005f47ecbd765c llvm::LLVMTargetMachine::addPassesToEmitFile(llvm::legacy::PassManagerBase&, llvm::raw_pwrite_stream&, llvm::raw_pwrite_stream*, llvm::CodeGenFileType, bool, llvm::MachineModuleInfoWrapperPass*) + 140
12 ldc2      0x00005f47ee4faebd
13 ldc2      0x00005f47ee4fa736 writeModule(llvm::Module*, char const*) + 5398
14 ldc2      0x00005f47ee4f8418 ldc::CodeGenerator::writeAndFreeLLModule(char const*) + 1144
15 ldc2      0x00005f47ea22acfe codegenModules(Array<Module*>&) + 2014
16 ldc2      0x00005f47ea19c192 mars_tryMain(Param&, Array<char const*>&) + 1970
17 ldc2      0x00005f47ea22f440 cppmain() + 9392
18 ldc2      0x00005f47ee6b65fd _D2rt6dmain212_d_run_main2UAAamPUQgZiZ6runAllMFZv + 77
19 ldc2      0x00005f47ee6b63d4 _d_run_main2 + 468
20 ldc2      0x00005f47ee6b61ed _d_run_main + 141
21 ldc2      0x00005f47ee4f559d main + 717
22 libc.so.6 0x00007d83eb94ae08
23 libc.so.6 0x00007d83eb94aecc __libc_start_main + 140
24 ldc2      0x00005f47ea2318ae _start + 46
Error: Error executing /home/kassane/zig/ldc2-dd44cfa4-linux-x86_64/bin/ldc2: Aborted (core dumped)
error: the following command exited with error code 1:
/home/kassane/toolchains/ldc2-dd44cfa4-linux-x86_64/bin/ldmd2 -c -w -preview=rvaluerefparam -debug -d-debug -gc -g -gf -gs -vgc -vtls --exception-model=dwarf -wasm-enable-eh -verrors=context -boundscheck=on -vcolumns -of=/home/kassane/sokol-d/.zig-cache/o/e094abe10af921c31fe05f98f0b3f0fd/mrt.o -cache=/home/kassane/sokol-d/.zig-cache/o/8421b40b46fd6c6a24a1efb45da08831 -disable-verify -Hkeep-all-bodies -i=sokol -i=shaders -i=handmade -I./src /home/kassane/sokol-d/src/examples/mrt.d -L-allow-undefined -P-I/home/kassane/.cache/zig/p/1220d2b37748757d43de92f0ef723b6a00c3cae4b6a9c582b607421704498a5cfd2b/upstream/emscripten/cache/sysroot/include -Xcc=-DIMPL -Xcc=-DSOKOL_GLES3 -mtriple=wasm32-unknown-emscripten -mcpu=generic 

Expected

No error!

Reference

  • https://github.com/WebAssembly/debugging/issues/18
  • https://github.com/WebAssembly/debugging/issues/1

kassane avatar Dec 10 '24 14:12 kassane

The dwarf version can be customized via -dwarf-version.

kinke avatar Dec 10 '24 15:12 kinke

-dwarf-version=5 get:

warning: unsupported DWARF version (5)
emcc: error: '/home/kassane/.cache/zig/p/1220d2b37748757d43de92f0ef723b6a00c3cae4b6a9c582b607421704498a5cfd2b/upstream/bin/wasm-emscripten-finalize -g --dyncalls-i64 --pass-arg=legalize-js-interface-exported-helpers --dwarf /home/kassane/sokol-d/.zig-cache/o/1e52826a2383e678930d2511f19510f4/mrt.wasm -o /home/kassane/sokol-d/.zig-cache/o/1e52826a2383e678930d2511f19510f4/mrt.wasm --detect-features' failed (received SIGABRT (-6))

-dwarf-version=4 get:

warning: unknown subopcode 5 (this may be an unsupported version of DWARF)
warning: unknown subopcode 37 (this may be an unsupported version of DWARF)
warning: unknown subopcode 5 (this may be an unsupported version of DWARF)
warning: unknown subopcode 5 (this may be an unsupported version of DWARF)
warning: unknown subopcode 5 (this may be an unsupported version of DWARF)
warning: unknown subopcode 5 (this may be an unsupported version of DWARF)
warning: unknown subopcode 5 (this may be an unsupported version of DWARF)
warning: unknown subopcode 5 (this may be an unsupported version of DWARF)
warning: unknown subopcode 91 (this may be an unsupported version of DWARF)
warning: unknown subopcode 58 (this may be an unsupported version of DWARF)
warning: unknown subopcode 58 (this may be an unsupported version of DWARF)
warning: unknown subopcode 6 (this may be an unsupported version of DWARF)
Fatal: TODO: DW_LNE_define_file
emcc: error: '/home/kassane/.cache/zig/p/1220d2b37748757d43de92f0ef723b6a00c3cae4b6a9c582b607421704498a5cfd2b/upstream/bin/wasm-emscripten-finalize -g --dyncalls-i64 --pass-arg=legalize-js-interface-exported-helpers --dwarf /home/kassane/sokol-d/.zig-cache/o/27a23c060d380acccbb71e1bfcd940a5/mrt.wasm -o /home/kassane/sokol-d/.zig-cache/o/27a23c060d380acccbb71e1bfcd940a5/mrt.wasm --detect-features' failed (returned 1)

kassane avatar Dec 10 '24 15:12 kassane

So looks like emcc requires v5 then. I doubt any of this is LDC-related, all Emscripten toolchain specifics.

kinke avatar Dec 10 '24 16:12 kinke

So looks like emcc requires v5 then. I doubt any of this is LDC-related, all Emscripten toolchain specifics.

emcc + zig works.

Some toolchains have succeeded in doing this and some haven't. For example, zig automatically emits dwarf 5 into debug mode, rust hasn't fully solved the wasm-pack (https://github.com/rustwasm/wasm-pack/issues/1351) problem yet and C and C++ emscripten works normally in debug mode too.

--- edit

fix: rust emit Dwarf in debug, too. ref.: https://code.visualstudio.com/docs/nodejs/nodejs-debugging#_debugging-webassembly

kassane avatar Dec 10 '24 16:12 kassane

Well AFAICT from your output is that your emcc (which version?) doesn't support DWARF 5. warning: unsupported DWARF version (5) doesn't come from LDC itself (nor from LLVM I guess), but probably from emcc which then aborts. https://github.com/emscripten-core/emscripten/issues/14241 mentions that v5 is required for wasm. And in https://issues.chromium.org/issues/40888941, they use emcc -gdwarf-5. That should be analogous to -g -dwarf-version=5 with LDC.

kinke avatar Dec 10 '24 17:12 kinke

emcc (which version?) doesn't support DWARF 5

Emscripten version: 3.1.73 (LLVM 20)

kassane avatar Dec 10 '24 17:12 kassane

Hmm, testing -gc instead of -g might be worth a try (using C++ as DWARF language then instead of D).

kinke avatar Dec 10 '24 19:12 kinke

Hmm, testing -gc instead of -g

Same error, here!!

But, in my test replaced -g from emcc to -gsource-map to extracting dwarf map, works.

EMCC_DEBUG=1

shared:DEBUG: successfully executed llvm-objcopy /home/kassane/sokol-d/.zig-cache/o/1d4093d9132d19456afa339ce9cb9584/mrt.wasm /home/kassane/sokol-d/.zig-cache/o/1d4093d9132d19456afa339ce9cb9584/mrt.wasm --remove-section=.debug* --remove-section=producers
extract_metadata:DEBUG: no start/stop symbols found for section: em_asm
shared:DEBUG: successfully executed wasm-opt --version
shared:DEBUG: successfully executed wasm-emscripten-finalize -g --dyncalls-i64 --pass-arg=legalize-js-interface-exported-helpers --dwarf --output-source-map-url=mrt.wasm.map /home/kassane/sokol-d/.zig-cache/o/1d4093d9132d19456afa339ce9cb9584/mrt.wasm -o /home/kassane/sokol-d/.zig-cache/o/1d4093d9132d19456afa339ce9cb9584/mrt.wasm --detect-features --input-source-map=/home/kassane/sokol-d/.zig-cache/o/1d4093d9132d19456afa339ce9cb9584/mrt.wasm.map --output-source-map=/home/kassane/sokol-d/.zig-cache/o/1d4093d9132d19456afa339ce9cb9584/mrt.wasm.map
building:DEBUG: saving debug copy /tmp/emscripten_temp/emcc-03-wasm-emscripten-finalize.wasm

Check object

llvm-dwarfdump .zig-cache/o/eeee9973a88fce373cb2a65fda350905/mrt.o | head -n 10
.zig-cache/o/eeee9973a88fce373cb2a65fda350905/mrt.o:    file format WASM

.debug_info contents:
0x00000000: Compile Unit: length = 0x0000678d, format = DWARF32, version = 0x0004, abbr_offset = 0x0000, addr_size = 0x04 (next unit at 0x00006791)

0x0000000b: DW_TAG_compile_unit
              DW_AT_producer    ("LDC 1.40.0-git-dd44cfa (LLVM 19.1.3)")
              DW_AT_language    (DW_LANG_D)
              DW_AT_name        ("./src/examples/shaders/mrt.d")
              DW_AT_stmt_list   (0x00000000)

kassane avatar Dec 10 '24 19:12 kassane

But, in my test replaced -g from emcc to -gsource-map to extracting dwarf map, works.

add: emcc -gsource-map -gdwarf-5 + ldc2 -gc -dwarf-version=5

warning: unsupported DWARF version (5)
unsupported form
UNREACHABLE executed at /b/s/w/ir/cache/builder/emscripten-releases/binaryen/third_party/llvm-project/DWARFFormValue.cpp:349!
emcc: error: 'wasm-emscripten-finalize -g --dyncalls-i64 --pass-arg=legalize-js-interface-exported-helpers --dwarf --output-source-map-url=mrt.wasm.map /home/kassane/sokol-d/.zig-cache/o/18739005f3e46e38d8e34fcc469463e0/mrt.wasm -o /home/kassane/sokol-d/.zig-cache/o/18739005f3e46e38d8e34fcc469463e0/mrt.wasm --detect-features --input-source-map=/home/kassane/sokol-d/.zig-cache/o/18739005f3e46e38d8e34fcc469463e0/mrt.wasm.map --output-source-map=/home/kassane/sokol-d/.zig-cache/o/18739005f3e46e38d8e34fcc469463e0/mrt.wasm.map' failed (received SIGABRT (-6))

kassane avatar Dec 10 '24 19:12 kassane

Hmm, testing -gc instead of -g

Same error, here!!

Couldn't that be because the flag is spelled --gc ? There's also --write-experimental-debuginfo which is llvm-specific.

leecommamichael avatar Feb 25 '25 22:02 leecommamichael

There's also --write-experimental-debuginfo which is llvm-specific.

Sorry I'm late. I also tested this flag (with/out --gc) and the result was no change.

But, in my test replaced -g from emcc to -gsource-map to extracting dwarf map, works.

This, works!

kassane avatar Apr 30 '25 16:04 kassane