This is an archive of the discontinued LLVM Phabricator instance.

[llvm-strip] Add WebAssembly support
AbandonedPublic

Authored by paolosev on Dec 20 2019, 3:07 PM.

Details

Summary

The DWARF debug info for a WebAssembly module is currently embedded within the module in a sequence custom sections, whose name matches the DWARF section name as defined in the DWARF standard (e.g. .debug_info or .debug_line).
It should be possible to export the debug info into a separate, external file and in that case a custom section named "external_debug_info" should be added to the original module. The "external_debug_info" section should contain an UTF-8 encoded URL to the external debug info file (see https://yurydelendik.github.io/webassembly-dwarf/ for more details).

This patch modifies llvm-strip and llvm-objcopy to also work with Wasm modules.
Several existing options should work also for Wasm files:

  • -g, --strip-debug, -S, --strip-all, --strip-all-gnu -x, --discard-all, --strip-unneeded (Remove all DWARF custom sections from a Wasm file).
  • -R, --remove-section (Remove the sections listed).
  • -j, --only-section (Remove all sections but the one listed).

Note that Wasm custom sections can be referred by their name, while the standard sections can be referred by their id (1:Type, 2: Import, ... 10: Code, and so on).

Two new options should be introduced, specific for Wasm modules:

--wasm-split-debug <wasm-sym-file> should behave like --split-dwo does for ELF files: extract the debug information into a separate file and strip the debug sections from the input file.
(Note: not sure if we could instead reuse the existing --split-dwo here, but we are not really dealing with DWO files, so that would be confusing).

--wasm-debug-info-url <dwarf-url> should be used to specify the URL of the DWARF debug info file created with --wasm-split-debug. This URL will be embedded in the "external_debug_info" custom section of the original file. If not specified, use the output file path of --wasm-split-debug as default value.

Diff Detail

Event Timeline

paolosev created this revision.Dec 20 2019, 3:07 PM

Is this an in-flight collision with https://reviews.llvm.org/D70930?

Doh! I didn't know there was this work ongoing.
I think we could maybe continue from there, once https://reviews.llvm.org/D70930 is merged; what I would like is to have something like --split-dwo that works with WASM files and only extracts DWARF sections.

It's worth also noting that if you want to contribute to the ongoing effort to add support for WASM in llvm-objcopy and llvm-strip, it's best to do it in small pieces (typically one option at a time), to make it easier to review, and don't forget to add testing!

paolosev abandoned this revision.Jan 10 2020, 3:37 PM