Skip to content

Commit d743092

Browse files
authored
Skip the search for dynamic libraries when static library exists (#23593)
This is a fix for a regression caused by #23336. Prior to #23336 all `-l` flags were expanded by emcc to full filenames, with `.a` files being searched for first. After #23336 we only expand the the paths of fake shared libraries which wasm-ld itself don't look for. Fixes: #23591
1 parent 3a8cb2a commit d743092

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

test/test_other.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6736,7 +6736,7 @@ def test(args, be_clean):
67366736
if be_clean:
67376737
assert len(clutter) == 0, 'should not leave clutter ' + str(clutter)
67386738
else:
6739-
assert len(clutter) == 2, 'should leave .o files'
6739+
assert len(clutter) == 2, 'should leave .o files'
67406740
test(['-o', 'c.so', '-r'], True)
67416741
test(['-o', 'c.js'], True)
67426742
test(['-o', 'c.html'], True)
@@ -9322,6 +9322,20 @@ def test_side_module_folder_deps(self):
93229322
self.run_process([EMCC, test_file('hello_world.c'), '-sSIDE_MODULE', '-o', 'subdir/libside2.so', '-L', 'subdir', '-lside1'])
93239323
self.run_process([EMCC, test_file('hello_world.c'), '-sMAIN_MODULE', '-o', 'main.js', '-L', 'subdir', '-lside2'])
93249324

9325+
@crossplatform
9326+
def test_side_module_ignore(self):
9327+
self.run_process([EMCC, test_file('hello_world.c'), '-sSIDE_MODULE', '-o', 'libside.so'])
9328+
9329+
# Attempting to link statically against a side module (libside.so) should fail.
9330+
err = self.expect_fail([EMCC, '-L.', '-lside'])
9331+
self.assertContained('error: attempted static link of dynamic object ./libside.so', err)
9332+
9333+
# But a static library in the same location (libside.a) should take precedence.
9334+
self.run_process([EMCC, test_file('hello_world.c'), '-c'])
9335+
self.run_process([EMAR, 'cr', 'libside.a', 'hello_world.o'])
9336+
self.run_process([EMCC, '-L.', '-lside'])
9337+
self.assertContained('hello, world!', self.run_js('a.out.js'))
9338+
93259339
@is_slow_test
93269340
@parameterized({
93279341
'': ([],),

tools/link.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2821,7 +2821,8 @@ def process_libraries(state):
28212821
settings.JS_LIBRARIES.append(os.path.abspath(path))
28222822
continue
28232823

2824-
if not settings.RELOCATABLE:
2824+
static_lib = f'lib{lib}.a'
2825+
if not settings.RELOCATABLE and not find_library(static_lib, state.lib_dirs):
28252826
# Normally we can rely on the native linker to expand `-l` args.
28262827
# However, emscripten also supports `.so` files that are actually just
28272828
# regular object file. This means we need to support `.so` files even

0 commit comments

Comments
 (0)