Skip to content

Commit 23242cb

Browse files
authored
Skip -lfoo expansion for real dynamic libraries. NFC (#25871)
The code here expands `-lfoo` to `/path/to/libfoo.so` for fake shared libraries so that the linker can find them (it won't look for .so files otherwise when static linking).
1 parent 1509942 commit 23242cb

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

test/test_other.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8402,8 +8402,7 @@ def test_side_module_ignore(self):
84028402
self.run_process([EMCC, test_file('hello_world.c'), '-sSIDE_MODULE', '-o', 'libside.so'])
84038403

84048404
# Attempting to link statically against a side module (libside.so) should fail.
8405-
err = self.expect_fail([EMCC, '-L.', '-lside'])
8406-
self.assertContained(r'error: attempted static link of dynamic object \.[/\\]libside.so', err, regex=True)
8405+
self.assert_fail([EMCC, '-L.', '-lside'], 'wasm-ld: error: unable to find library -lside')
84078406

84088407
# But a static library in the same location (libside.a) should take precedence.
84098408
self.run_process([EMCC, test_file('hello_world.c'), '-c'])

tools/link.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2794,17 +2794,17 @@ def process_libraries(options, flags):
27942794
continue
27952795

27962796
static_lib = f'lib{lib}.a'
2797-
if not settings.RELOCATABLE and not find_library(static_lib, options.lib_dirs):
2797+
if not settings.RELOCATABLE and not settings.MAIN_MODULE and not find_library(static_lib, options.lib_dirs):
27982798
# Normally we can rely on the native linker to expand `-l` args.
2799-
# However, emscripten also supports `.so` files that are actually just
2800-
# regular object file. This means we need to support `.so` files even
2799+
# However, emscripten also supports fake `.so` files that are actually
2800+
# just regular object files. This means we need to support `.so` files even
28012801
# when statically linking. The native linker (wasm-ld) will otherwise
28022802
# ignore .so files in this mode.
28032803
found_dylib = False
28042804
for ext in DYLIB_EXTENSIONS:
28052805
name = 'lib' + lib + ext
28062806
path = find_library(name, options.lib_dirs)
2807-
if path:
2807+
if path and not building.is_wasm_dylib(path):
28082808
found_dylib = True
28092809
new_flags.append(path)
28102810
break

0 commit comments

Comments
 (0)