Skip to content

Commit 91643e8

Browse files
authored
Fix filter_out_dynamic_libs WRT to -soname (#23558)
The `filter_out_dynamic_libs` was incorrectly removing the `libfoo.so` flag from `-soname libfoo.so` which means that next argument was then being treated as the soname. Fixes: #23555
1 parent 02fbbe2 commit 91643e8

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

test/test_other.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12836,6 +12836,11 @@ def test_shared_flag(self):
1283612836
self.assertContained('warning: -shared/-r used with executable output suffix', err)
1283712837
self.run_js('out.js')
1283812838

12839+
def test_shared_soname(self):
12840+
self.run_process([EMCC, '-shared', '-Wl,-soname', '-Wl,libfoo.so.13', test_file('hello_world.c'), '-lc', '-o', 'libfoo.so'])
12841+
self.run_process([EMCC, '-sSTRICT', 'libfoo.so'])
12842+
self.assertContained('hello, world!', self.run_js('a.out.js'))
12843+
1283912844
def test_shared_and_side_module_flag(self):
1284012845
# Test that `-shared` and `-sSIDE_MODULE` flag causes wasm dylib generation without a warning.
1284112846
err = self.run_process([EMCC, '-shared', '-sSIDE_MODULE', test_file('hello_world.c'), '-o', 'out.foo'], stderr=PIPE).stderr

tools/link.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2876,17 +2876,17 @@ def replacement(self):
28762876
return '<script>\n%s\n</script>' % self.inline
28772877

28782878

2879-
def filter_out_dynamic_libs(options, inputs):
2879+
def filter_out_fake_dynamic_libs(options, inputs):
28802880
# Filters out "fake" dynamic libraries that are really just intermediate object files.
2881-
def check(input_file):
2882-
if get_file_suffix(input_file) in DYLIB_EXTENSIONS and not building.is_wasm_dylib(input_file):
2881+
def is_fake_dylib(input_file):
2882+
if get_file_suffix(input_file) in DYLIB_EXTENSIONS and os.path.exists(input_file) and not building.is_wasm_dylib(input_file):
28832883
if not options.ignore_dynamic_linking:
28842884
diagnostics.warning('emcc', 'ignoring dynamic library %s because not compiling to JS or HTML, remember to link it when compiling to JS or HTML at the end', os.path.basename(input_file))
2885-
return False
2886-
else:
28872885
return True
2886+
else:
2887+
return False
28882888

2889-
return [f for f in inputs if check(f)]
2889+
return [f for f in inputs if not is_fake_dylib(f)]
28902890

28912891

28922892
def filter_out_duplicate_dynamic_libs(inputs):
@@ -3072,7 +3072,7 @@ def phase_calculate_linker_inputs(options, state, linker_inputs):
30723072
# "fake" dynamic libraries, since otherwise we will end up with
30733073
# multiple copies in the final executable.
30743074
if options.oformat == OFormat.OBJECT or options.ignore_dynamic_linking:
3075-
linker_args = filter_out_dynamic_libs(options, linker_args)
3075+
linker_args = filter_out_fake_dynamic_libs(options, linker_args)
30763076
else:
30773077
linker_args = filter_out_duplicate_dynamic_libs(linker_args)
30783078

0 commit comments

Comments
 (0)