Skip to content

Commit 4082634

Browse files
dschuffpull[bot]
authored andcommitted
Strip code section from separate-dwarf file (#17257)
Other custom sections need to stay in the file so that the DWARF data can be interpreted by tools such as llvm-dwarfdump. Fixes #13084
1 parent 5912e98 commit 4082634

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

emcc.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3409,7 +3409,8 @@ def phase_binaryen(target, options, wasm_target):
34093409
# we are not running wasm-opt. if we need to strip certain sections
34103410
# then do so using llvm-objcopy which is fast and does not rewrite the
34113411
# code (which is better for debug info)
3412-
building.strip(wasm_target, wasm_target, debug=strip_debug, producers=strip_producers)
3412+
sections = ['producers'] if strip_producers else []
3413+
building.strip(wasm_target, wasm_target, debug=strip_debug, sections=sections)
34133414
building.save_intermediate(wasm_target, 'strip.wasm')
34143415

34153416
if settings.EVAL_CTORS:

tests/test_other.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8635,8 +8635,8 @@ def test_separate_dwarf(self):
86358635
if not debug_wasm.has_name_section():
86368636
self.fail('name section not found in separate dwarf file')
86378637
for sec in debug_wasm.sections():
8638-
# TODO: check for absence of code section (see
8639-
# https://github.com/emscripten-core/emscripten/issues/13084)
8638+
if sec.type == webassembly.SecType.CODE:
8639+
self.fail(f'section of type "{sec.type}" found in separate dwarf file')
86408640
if sec.name and sec.name != 'name' and not sec.name.startswith('.debug'):
86418641
self.fail(f'non-debug section "{sec.name}" found in separate dwarf file')
86428642

tools/building.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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
12351233
def 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'\x13external_debug_info' # section name, including prefixed size

0 commit comments

Comments
 (0)