Skip to content

Commit d766ef1

Browse files
authored
Fix some source map and name section behavior (#23182)
1) This causes -g0 to fullyl override -gsource-map (removing the name section) when it comes later on the command line 2) -gsplit-dwarf and -gsource-map work together resulting in dwarf, source maps and name section together.
1 parent ff1e239 commit d766ef1

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

emcc.py

+10
Original file line numberDiff line numberDiff line change
@@ -1268,6 +1268,13 @@ def consume_arg_file():
12681268
if is_int(requested_level):
12691269
# the -gX value is the debug level (-g1, -g2, etc.)
12701270
settings.DEBUG_LEVEL = validate_arg_level(requested_level, 4, 'invalid debug level: ' + arg)
1271+
if settings.DEBUG_LEVEL == 0:
1272+
# Set these explicitly so -g0 overrides previous -g on the cmdline
1273+
settings.GENERATE_DWARF = 0
1274+
settings.GENERATE_SOURCE_MAP = 0
1275+
settings.EMIT_NAME_SECTION = 0
1276+
elif settings.DEBUG_LEVEL > 1:
1277+
settings.EMIT_NAME_SECTION = 1
12711278
# if we don't need to preserve LLVM debug info, do not keep this flag
12721279
# for clang
12731280
if settings.DEBUG_LEVEL < 3:
@@ -1298,17 +1305,20 @@ def consume_arg_file():
12981305
settings.GENERATE_DWARF = 1
12991306
elif requested_level == 'source-map':
13001307
settings.GENERATE_SOURCE_MAP = 1
1308+
settings.EMIT_NAME_SECTION = 1
13011309
newargs[i] = '-g'
13021310
else:
13031311
# Other non-integer levels (e.g. -gline-tables-only or -gdwarf-5) are
13041312
# usually clang flags that emit DWARF. So we pass them through to
13051313
# clang and make the emscripten code treat it like any other DWARF.
13061314
settings.GENERATE_DWARF = 1
1315+
settings.EMIT_NAME_SECTION = 1
13071316
# In all cases set the emscripten debug level to 3 so that we do not
13081317
# strip during link (during compile, this does not make a difference).
13091318
settings.DEBUG_LEVEL = 3
13101319
elif check_flag('-profiling') or check_flag('--profiling'):
13111320
settings.DEBUG_LEVEL = max(settings.DEBUG_LEVEL, 2)
1321+
settings.EMIT_NAME_SECTION = 1
13121322
elif check_flag('-profiling-funcs') or check_flag('--profiling-funcs'):
13131323
settings.EMIT_NAME_SECTION = 1
13141324
elif newargs[i] == '--tracing' or newargs[i] == '--memoryprofiler':

test/test_other.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -3095,8 +3095,7 @@ def test_dwarf_sourcemap_names(self):
30953095
# TODO: It seems odd that -gsource-map leaves behind a name section. Should it?
30963096
(['-gsource-map'], False, True, True),
30973097
(['-g1', '-Oz', '-gsource-map'], False, True, True),
3098-
# -g0 does not override -gsource-map but does remove name section. TODO: should it?
3099-
(['-gsource-map', '-g0'], False, True, False),
3098+
(['-gsource-map', '-g0'], False, False, False),
31003099
# --emit-symbol-map should not affect the results
31013100
(['--emit-symbol-map', '-gsource-map'], False, True, True),
31023101
(['--emit-symbol-map'], False, False, False),
@@ -3105,7 +3104,7 @@ def test_dwarf_sourcemap_names(self):
31053104
(['-sASYNCIFY=1', '-gsource-map'], False, True, True),
31063105
(['-g', '-gsource-map'], True, True, True),
31073106
(['-g2', '-gsource-map'], False, True, True),
3108-
# (['-gsplit-dwarf', '-gsource-map'], True, True, True), TODO this currently fails!
3107+
(['-gsplit-dwarf', '-gsource-map'], True, True, True),
31093108
(['-gsource-map', '-sWASM_BIGINT', '-sERROR_ON_WASM_CHANGES_AFTER_LINK'], False, True, True),
31103109
]:
31113110
print(flags, expect_dwarf, expect_sourcemap, expect_names)

tools/emscripten.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -501,12 +501,14 @@ def finalize_wasm(infile, outfile, js_syms):
501501

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

505506
if settings.WASM2JS:
506507
# wasm2js requires full legalization (and will do extra wasm binary
507508
# later processing later anyhow)
508509
modify_wasm = True
509510
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:
511+
need_name_section = True
510512
args.append('-g')
511513
if settings.WASM_BIGINT:
512514
args.append('--bigint')
@@ -568,12 +570,18 @@ def finalize_wasm(infile, outfile, js_syms):
568570
infile]
569571
shared.check_call(cmd)
570572

571-
if not settings.GENERATE_DWARF or not settings.EMIT_PRODUCERS_SECTION:
572-
# For sections we no longer need, strip now to speed subsequent passes
573+
# For sections we no longer need, strip now to speed subsequent passes.
574+
# If Binaryen is not needed, this is also our last chance to strip.
575+
strip_sections = []
576+
if not settings.EMIT_PRODUCERS_SECTION:
577+
strip_sections += ['producers']
578+
if not need_name_section:
579+
strip_sections += ['name']
580+
581+
if strip_sections or not settings.GENERATE_DWARF:
573582
building.save_intermediate(outfile, 'strip.wasm')
574-
sections = ['producers'] if not settings.EMIT_PRODUCERS_SECTION else []
575583
building.strip(infile, outfile, debug=not settings.GENERATE_DWARF,
576-
sections=sections)
584+
sections=strip_sections)
577585

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

0 commit comments

Comments
 (0)