Skip to content

Commit 57c2989

Browse files
authored
Support -s compile file, which is the same as -Wl,-s. NFC (#20902)
Both clang and gcc pass `-s` directly on to the linker.
1 parent 0a3b753 commit 57c2989

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

emcc.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -789,9 +789,7 @@ def phase_setup(options, state, newargs):
789789
newargs[i] = ''
790790
newargs[i + 1] = ''
791791
elif arg == '-s':
792-
# -s and some other compiler flags are normally passed onto the linker
793-
# TODO(sbc): Pass this and other flags through when using lld
794-
# link_flags.append((i, arg))
792+
state.add_link_flag(i, newargs[i])
795793
newargs[i] = ''
796794
elif arg == '-':
797795
input_files.append((i, arg))

test/test_other.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14205,10 +14205,29 @@ def test_unused_destructor(self):
1420514205
self.assertNotIn(b'hello from dtor', read_binary('test_unused_destructor.wasm'))
1420614206

1420714207
def test_strip_all(self):
14208-
# Test that even with `-Wl,--strip-all` the target features section is generated
14209-
# by wasm-ld so that later phases (e.g. wasm-opt) can read it.
14208+
def has_debug_section(wasm):
14209+
with webassembly.Module('hello_world.wasm') as wasm:
14210+
return wasm.get_custom_section('.debug_info') is not None
14211+
14212+
# Use -O2 to ensure wasm-opt gets run
14213+
self.emcc_args += ['-g', '-O2']
14214+
14215+
# First, verify that `-g` produces a debug section
14216+
self.do_runf('hello_world.c')
14217+
self.assertTrue(has_debug_section('hello_world.wasm'))
14218+
14219+
# Test `-Wl,--strip-all` will strip the debug section, but that the
14220+
# the target features section is preserved so that later phases
14221+
# (e.g. wasm-opt) can read it.
1421014222
self.do_runf('hello_world.c', emcc_args=['-Wl,--strip-all', '-pthread'])
14223+
self.assertFalse(has_debug_section('hello_world.wasm'))
14224+
14225+
# Verify that `-Wl,-s` and `-s` also both have the same effect
1421114226
self.do_runf('hello_world.c', emcc_args=['-Wl,-s', '-pthread'])
14227+
self.assertFalse(has_debug_section('hello_world.wasm'))
14228+
14229+
self.do_runf('hello_world.c', emcc_args=['-s', '-pthread'])
14230+
self.assertFalse(has_debug_section('hello_world.wasm'))
1421214231

1421314232
def test_embind_no_duplicate_symbols(self):
1421414233
# Embind implementation lives almost entirely in headers, which have special rules

0 commit comments

Comments
 (0)