-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
SIDE_DEBUG option: emit DWARF in a wasm on the side #10568
Changes from 7 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -704,6 +704,7 @@ def replace_or_append_suffix(filename, new_suffix): | |
LLVM_INTERPRETER = os.path.expanduser(build_llvm_tool_path(exe_suffix('lli'))) | ||
LLVM_COMPILER = os.path.expanduser(build_llvm_tool_path(exe_suffix('llc'))) | ||
LLVM_DWARFDUMP = os.path.expanduser(build_llvm_tool_path(exe_suffix('llvm-dwarfdump'))) | ||
LLVM_OBJCOPY = os.path.expanduser(build_llvm_tool_path(exe_suffix('llvm-objcopy'))) | ||
WASM_LD = os.path.expanduser(build_llvm_tool_path(exe_suffix('wasm-ld'))) | ||
|
||
EMSCRIPTEN = path_from_root('emscripten.py') | ||
|
@@ -2756,6 +2757,27 @@ def wasm2js(js_file, wasm_file, opt_level, minify_whitespace, use_closure_compil | |
f.write(all_js) | ||
return js_file | ||
|
||
@staticmethod | ||
def emit_debug_on_side(wasm_file): | ||
# extract the DWARF info from the main file, and leave the wasm with | ||
# debug into as a file on the side | ||
# TODO: emit only debug sections in the side file, and not the entire | ||
# wasm as well | ||
wasm_file_with_dwarf = wasm_file + '.debug.wasm' | ||
shutil.move(wasm_file, wasm_file_with_dwarf) | ||
run_process([LLVM_OBJCOPY, '--remove-section=.debug*', wasm_file_with_dwarf, wasm_file]) | ||
|
||
# embed a section in the main wasm to point to the file with external DWARF, | ||
# see https://yurydelendik.github.io/webassembly-dwarf/#external-DWARF | ||
section_name = b'\x13external_debug_info' # section name, including prefixed size | ||
contents = asbytes(wasm_file_with_dwarf) | ||
section_size = len(section_name) + len(contents) | ||
with open(wasm_file, 'ab') as f: | ||
f.write(b'\0') # user section is code 0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This bit isn't necessary. The section header is created by objcopy. We only need the payload here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (the alternative of course would be to create the header here too and then just directly append to the file rather than using objcopy at all) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh oops, I didn't read it closely enough :D |
||
f.write(WebAssembly.lebify(section_size)) | ||
f.write(section_name) | ||
f.write(contents) | ||
|
||
@staticmethod | ||
def apply_wasm_memory_growth(js_file): | ||
logger.debug('supporting wasm memory growth with pthreads') | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this still suffer from the problem that -g after -gside negates the SIDE_DEBUG setting?
Actually looking at the code, I don't really see how that happens. FULL_DWARF will get set to 1, but then nothing unsets it when the -g is later processed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that flag mixup was something else I think. @pfaffe let me know if that's still an issue and if I can help there.
Overall
-g
can't override the two new flags we added, so this should be ok.