Skip to content

Commit 90f2c57

Browse files
authored
[link.py] Be explicit about if/when we expand -l flag. NFC (emscripten-core#23336)
In most cases we prefer to leave it up to the linker to do this.
1 parent 6b81620 commit 90f2c57

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

tools/link.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
from .utils import read_file, write_file, delete_file
3737
from .utils import removeprefix, exit_with_error
3838
from .shared import in_temp, safe_copy, do_replace, OFormat
39-
from .shared import DEBUG, WINDOWS, DYNAMICLIB_ENDINGS, STATICLIB_ENDINGS
39+
from .shared import DEBUG, WINDOWS, DYNAMICLIB_ENDINGS
4040
from .shared import unsuffixed, unsuffixed_basename, get_file_suffix
4141
from .settings import settings, default_setting, user_settings, JS_ONLY_SETTINGS, DEPRECATED_SETTINGS
4242
from .minimal_runtime_shell import generate_minimal_runtime_html
@@ -2812,7 +2812,6 @@ def map_to_js_libs(library_name):
28122812

28132813
def process_libraries(state):
28142814
new_flags = []
2815-
suffixes = STATICLIB_ENDINGS + DYNAMICLIB_ENDINGS
28162815
system_libs_map = system_libs.Library.get_usable_variations()
28172816

28182817
# Process `-l` and `--js-library` flags
@@ -2843,16 +2842,23 @@ def process_libraries(state):
28432842
if js_libs is not None:
28442843
continue
28452844

2846-
path = None
2847-
for suff in suffixes:
2848-
name = 'lib' + lib + suff
2849-
path = find_library(name, state.lib_dirs)
2850-
if path:
2851-
break
2845+
if not settings.RELOCATABLE:
2846+
# Normally we can rely on the native linker to expand `-l` args.
2847+
# However, emscripten also supports `.so` files that are actually just
2848+
# regular object file. This means we need to support `.so` files even
2849+
# when statically linking. The native linker (wasm-ld) will otherwise
2850+
# ignore .so files in this mode.
2851+
found_dylib = False
2852+
for ext in DYNAMICLIB_ENDINGS:
2853+
name = 'lib' + lib + ext
2854+
path = find_library(name, state.lib_dirs)
2855+
if path:
2856+
found_dylib = True
2857+
new_flags.append((i, path))
2858+
break
28522859

2853-
if path:
2854-
new_flags.append((i, path))
2855-
continue
2860+
if found_dylib:
2861+
continue
28562862

28572863
new_flags.append((i, flag))
28582864

0 commit comments

Comments
 (0)