Skip to content

Commit

Permalink
Fix llvm backend debug info with opts (#8298)
Browse files Browse the repository at this point in the history
We invoke wasm-opt after finalize, and it needs to be given the source map, and told to emit one, as it changes the binary.

This wasn't noticed in testing because finalize did emit a .map file - it just got out of date later when the binary was changed, but the test just checks for its existence and how many items it has, and doesn't literally understand the source map format and check if things line up to the binary.
  • Loading branch information
kripken authored Mar 26, 2019
1 parent 279685d commit f323bec
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,7 @@ def optimizing(opts):
asm_target = unsuffixed(js_target) + '.asm.js' # might not be used, but if it is, this is the name
wasm_text_target = asm_target.replace('.asm.js', '.wast') # ditto, might not be used
wasm_binary_target = asm_target.replace('.asm.js', '.wasm') # ditto, might not be used
wasm_source_map_target = wasm_binary_target + '.map'

if final_suffix == '.html' and not options.separate_asm and 'PRECISE_F32=2' in settings_changes:
options.separate_asm = True
Expand Down Expand Up @@ -1925,7 +1926,7 @@ def get_final():
wasm_temp = temp_basename + '.wasm'
shutil.move(wasm_temp, wasm_binary_target)
if use_source_map(options):
shutil.move(wasm_temp + '.map', wasm_binary_target + '.map')
shutil.move(wasm_temp + '.map', wasm_source_map_target)

if shared.Settings.CYBERDWARF:
cd_target = final + '.cd'
Expand Down Expand Up @@ -2200,7 +2201,8 @@ def get_eliminate():

if shared.Settings.WASM:
do_binaryen(target, asm_target, options, memfile, wasm_binary_target,
wasm_text_target, misc_temp_files, optimizer)
wasm_text_target, wasm_source_map_target, misc_temp_files,
optimizer)

if shared.Settings.MODULARIZE:
modularize()
Expand Down Expand Up @@ -2593,7 +2595,8 @@ def separate_asm_js(final, asm_target):


def do_binaryen(target, asm_target, options, memfile, wasm_binary_target,
wasm_text_target, misc_temp_files, optimizer):
wasm_text_target, wasm_source_map_target, misc_temp_files,
optimizer):
global final
logger.debug('using binaryen')
binaryen_bin = shared.Building.get_binaryen_bin()
Expand Down Expand Up @@ -2657,7 +2660,7 @@ def do_binaryen(target, asm_target, options, memfile, wasm_binary_target,
if debug_info:
cmd += ['-g']
if use_source_map(options):
cmd += ['--source-map=' + wasm_binary_target + '.map']
cmd += ['--source-map=' + wasm_source_map_target]
cmd += ['--source-map-url=' + options.source_map_base + os.path.basename(wasm_binary_target) + '.map']
logger.debug('wasm-as (text => binary): ' + ' '.join(cmd))
shared.check_call(cmd)
Expand All @@ -2677,6 +2680,12 @@ def do_binaryen(target, asm_target, options, memfile, wasm_binary_target,
cmd += shared.Building.get_binaryen_feature_flags()
if debug_info:
cmd += ['-g'] # preserve the debug info
if use_source_map(options):
cmd += ['--input-source-map=' + wasm_source_map_target]
cmd += ['--output-source-map=' + wasm_source_map_target]
cmd += ['--output-source-map-url=' + options.source_map_base + os.path.basename(wasm_binary_target) + '.map']
if DEBUG:
shared.safe_copy(wasm_source_map_target, os.path.join(shared.get_emscripten_temp_dir(), os.path.basename(wasm_source_map_target) + '.pre-byn'))
logger.debug('wasm-opt on BINARYEN_PASSES: ' + ' '.join(cmd))
shared.check_call(cmd)
if shared.Settings.BINARYEN_SCRIPTS:
Expand Down

0 comments on commit f323bec

Please sign in to comment.