Skip to content

Commit 35012ec

Browse files
authored
Use --keep-section=target_features linker flag (#20627)
This ensures that this sections is preserved even when `-Wl,--strip-all` is passed.
1 parent 1375c03 commit 35012ec

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

test/test_other.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14165,3 +14165,8 @@ def test_unused_destructor(self):
1416514165
self.do_runf(test_file('other/test_unused_destructor.c'), emcc_args=['-flto', '-O2'])
1416614166
# Verify that the string constant in the destructor is not included in the binary
1416714167
self.assertNotIn(b'hello from dtor', read_binary('test_unused_destructor.wasm'))
14168+
14169+
def test_strip_all(self):
14170+
# Test that even with `-Wl,--strip-all` the target features section is generated
14171+
# by wasm-ld so that later phases (e.g. wasm-opt) can read it.
14172+
self.do_runf('hello_world.c', emcc_args=['-Wl,--strip-all', '-pthread'])

tools/building.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,11 @@ def link_lld(args, target, external_symbols=None):
269269
if settings.STRICT:
270270
args.append('--fatal-warnings')
271271

272+
if '--strip-all' in args:
273+
# Tell wasm-ld to always generate a target_features section even if --strip-all
274+
# is passed.
275+
args.append('--keep-section=target_features')
276+
272277
cmd = [WASM_LD, '-o', target] + args
273278
for a in llvm_backend_args():
274279
cmd += ['-mllvm', a]

0 commit comments

Comments
 (0)