@@ -1219,19 +1219,17 @@ def wasm2js(js_file, wasm_file, opt_level, minify_whitespace, use_closure_compil
12191219 return js_file
12201220
12211221
1222- def strip (infile , outfile , debug = False , producers = False ):
1222+ def strip (infile , outfile , debug = False , sections = None ):
12231223 cmd = [LLVM_OBJCOPY , infile , outfile ]
12241224 if debug :
12251225 cmd += ['--remove-section=.debug*' ]
1226- if producers :
1227- cmd += ['--remove-section=producers' ]
1226+ if sections :
1227+ cmd += ['--remove-section=' + section for section in sections ]
12281228 check_call (cmd )
12291229
12301230
12311231# extract the DWARF info from the main file, and leave the wasm with
12321232# debug into as a file on the side
1233- # TODO: emit only debug sections in the side file, and not the entire
1234- # wasm as well
12351233def emit_debug_on_side (wasm_file ):
12361234 # if the dwarf filename wasn't provided, use the default target + a suffix
12371235 wasm_file_with_dwarf = settings .SEPARATE_DWARF
@@ -1248,6 +1246,13 @@ def emit_debug_on_side(wasm_file):
12481246 shutil .move (wasm_file , wasm_file_with_dwarf )
12491247 strip (wasm_file_with_dwarf , wasm_file , debug = True )
12501248
1249+ # Strip code and data from the debug file to limit its size. The other known
1250+ # sections are still required to correctly interpret the DWARF info.
1251+ # TODO(dschuff): Also strip the DATA section? To make this work we'd need to
1252+ # either allow "invalid" data segment name entries, or maybe convert the DATA
1253+ # to a DATACOUNT section.
1254+ strip (wasm_file_with_dwarf , wasm_file_with_dwarf , sections = ['CODE' ])
1255+
12511256 # embed a section in the main wasm to point to the file with external DWARF,
12521257 # see https://yurydelendik.github.io/webassembly-dwarf/#external-DWARF
12531258 section_name = b'\x13 external_debug_info' # section name, including prefixed size
0 commit comments