Skip to content

Commit df352fc

Browse files
authored
Strip non-debug sections from separate-dwarf file (#16110)
When using -gseparate-dwarf, emscripten strips the DWARF sections from the main wasm output file, and writes a second file (foo.debug.wasm) with the DWARF sections. Currently that file also contains a copy of all the other sections as well, but this is unncessary and just wastes space. Fixes #13084
1 parent db77c76 commit df352fc

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

tests/test_other.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8269,6 +8269,16 @@ def test_separate_dwarf(self):
82698269
self.assertNotIn(b'subdir/output.wasm.debug.wasm', wasm)
82708270
self.assertNotIn(bytes(os.path.join('subdir', 'output.wasm.debug.wasm'), 'ascii'), wasm)
82718271

8272+
# Check that the dwarf file has only dwarf and name sections
8273+
debug_wasm = webassembly.Module('subdir/output.wasm.debug.wasm')
8274+
if not debug_wasm.has_name_section():
8275+
self.fail('name section not found in separate dwarf file')
8276+
for sec in debug_wasm.sections():
8277+
if sec.type != webassembly.SecType.CUSTOM:
8278+
self.fail(f'non-custom section type {sec.type} found in separate dwarf file')
8279+
elif sec.name != 'name' and not sec.name.startswith('.debug'):
8280+
self.fail(f'non-debug section "{sec.name}" found in separate dwarf file')
8281+
82728282
def test_separate_dwarf_with_filename(self):
82738283
self.run_process([EMCC, test_file('hello_world.c'), '-gseparate-dwarf=with_dwarf.wasm'])
82748284
self.assertNotExists('a.out.wasm.debug.wasm')

tools/building.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,6 +1241,10 @@ def emit_debug_on_side(wasm_file, wasm_file_with_dwarf):
12411241
shutil.move(wasm_file, wasm_file_with_dwarf)
12421242
strip(wasm_file_with_dwarf, wasm_file, debug=True)
12431243

1244+
# Strip the non-debug sections out of the DWARF file
1245+
check_call([LLVM_OBJCOPY, wasm_file_with_dwarf, '--only-keep-debug',
1246+
'--keep-section', 'name'])
1247+
12441248
# embed a section in the main wasm to point to the file with external DWARF,
12451249
# see https://yurydelendik.github.io/webassembly-dwarf/#external-DWARF
12461250
section_name = b'\x13external_debug_info' # section name, including prefixed size

0 commit comments

Comments
 (0)