Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1268,6 +1268,13 @@ def consume_arg_file():
if is_int(requested_level):
# the -gX value is the debug level (-g1, -g2, etc.)
settings.DEBUG_LEVEL = validate_arg_level(requested_level, 4, 'invalid debug level: ' + arg)
if settings.DEBUG_LEVEL == 0:
# Set these explicitly so -g0 overrides previous -g on the cmdline
settings.GENERATE_DWARF = 0
settings.GENERATE_SOURCE_MAP = 0
settings.EMIT_NAME_SECTION = 0
elif settings.DEBUG_LEVEL > 1:
settings.EMIT_NAME_SECTION = 1
# if we don't need to preserve LLVM debug info, do not keep this flag
# for clang
if settings.DEBUG_LEVEL < 3:
Expand Down Expand Up @@ -1298,17 +1305,20 @@ def consume_arg_file():
settings.GENERATE_DWARF = 1
elif requested_level == 'source-map':
settings.GENERATE_SOURCE_MAP = 1
settings.EMIT_NAME_SECTION = 1
newargs[i] = '-g'
else:
# Other non-integer levels (e.g. -gline-tables-only or -gdwarf-5) are
# usually clang flags that emit DWARF. So we pass them through to
# clang and make the emscripten code treat it like any other DWARF.
settings.GENERATE_DWARF = 1
settings.EMIT_NAME_SECTION = 1
# In all cases set the emscripten debug level to 3 so that we do not
# strip during link (during compile, this does not make a difference).
settings.DEBUG_LEVEL = 3
elif check_flag('-profiling') or check_flag('--profiling'):
settings.DEBUG_LEVEL = max(settings.DEBUG_LEVEL, 2)
settings.EMIT_NAME_SECTION = 1
elif check_flag('-profiling-funcs') or check_flag('--profiling-funcs'):
settings.EMIT_NAME_SECTION = 1
elif newargs[i] == '--tracing' or newargs[i] == '--memoryprofiler':
Expand Down
5 changes: 2 additions & 3 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -3095,8 +3095,7 @@ def test_dwarf_sourcemap_names(self):
# TODO: It seems odd that -gsource-map leaves behind a name section. Should it?
(['-gsource-map'], False, True, True),
(['-g1', '-Oz', '-gsource-map'], False, True, True),
# -g0 does not override -gsource-map but does remove name section. TODO: should it?
(['-gsource-map', '-g0'], False, True, False),
(['-gsource-map', '-g0'], False, False, False),
# --emit-symbol-map should not affect the results
(['--emit-symbol-map', '-gsource-map'], False, True, True),
(['--emit-symbol-map'], False, False, False),
Expand All @@ -3105,7 +3104,7 @@ def test_dwarf_sourcemap_names(self):
(['-sASYNCIFY=1', '-gsource-map'], False, True, True),
(['-g', '-gsource-map'], True, True, True),
(['-g2', '-gsource-map'], False, True, True),
# (['-gsplit-dwarf', '-gsource-map'], True, True, True), TODO this currently fails!
(['-gsplit-dwarf', '-gsource-map'], True, True, True),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great to see these TODOs fixed!

(['-gsource-map', '-sWASM_BIGINT', '-sERROR_ON_WASM_CHANGES_AFTER_LINK'], False, True, True),
]:
print(flags, expect_dwarf, expect_sourcemap, expect_names)
Expand Down
16 changes: 12 additions & 4 deletions tools/emscripten.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,12 +501,14 @@ def finalize_wasm(infile, outfile, js_syms):

# if we don't need to modify the wasm, don't tell finalize to emit a wasm file
modify_wasm = False
need_name_section = False

if settings.WASM2JS:
# wasm2js requires full legalization (and will do extra wasm binary
# later processing later anyhow)
modify_wasm = True
if settings.DEBUG_LEVEL >= 2 or settings.ASYNCIFY_ADD or settings.ASYNCIFY_ADVISE or settings.ASYNCIFY_ONLY or settings.ASYNCIFY_REMOVE or settings.EMIT_SYMBOL_MAP or settings.EMIT_NAME_SECTION:
need_name_section = True
args.append('-g')
if settings.WASM_BIGINT:
args.append('--bigint')
Expand Down Expand Up @@ -568,12 +570,18 @@ def finalize_wasm(infile, outfile, js_syms):
infile]
shared.check_call(cmd)

if not settings.GENERATE_DWARF or not settings.EMIT_PRODUCERS_SECTION:
# For sections we no longer need, strip now to speed subsequent passes
# For sections we no longer need, strip now to speed subsequent passes.
# If Binaryen is not needed, this is also our last chance to strip.
strip_sections = []
if not settings.EMIT_PRODUCERS_SECTION:
strip_sections += ['producers']
if not need_name_section:
strip_sections += ['name']

if strip_sections or not settings.GENERATE_DWARF:
building.save_intermediate(outfile, 'strip.wasm')
sections = ['producers'] if not settings.EMIT_PRODUCERS_SECTION else []
building.strip(infile, outfile, debug=not settings.GENERATE_DWARF,
sections=sections)
sections=strip_sections)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code gives me a headache! LGTM though

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the possible combinations of debug options is pretty bad. But I think this (and the previous change, which added all those tests in test_other) is an improvement because it's now more explicit in the emscripten code rather than part of the behavior being implicit with Binaryen.


metadata = get_metadata(outfile, outfile, modify_wasm, args)

Expand Down
Loading