Skip to content

Commit

Permalink
[link.py] Be explicit about if/when we expand -l flag. NFC
Browse files Browse the repository at this point in the history
In most cases we prefer to leave it up to the linker to do this.
  • Loading branch information
sbc100 committed Jan 8, 2025
1 parent 9096999 commit 4f73509
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions tools/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
from .utils import read_file, write_file, delete_file
from .utils import removeprefix, exit_with_error
from .shared import in_temp, safe_copy, do_replace, OFormat
from .shared import DEBUG, WINDOWS, DYNAMICLIB_ENDINGS, STATICLIB_ENDINGS
from .shared import DEBUG, WINDOWS, DYNAMICLIB_ENDINGS
from .shared import unsuffixed, unsuffixed_basename, get_file_suffix
from .settings import settings, default_setting, user_settings, JS_ONLY_SETTINGS, DEPRECATED_SETTINGS
from .minimal_runtime_shell import generate_minimal_runtime_html
Expand Down Expand Up @@ -2808,7 +2808,6 @@ def map_to_js_libs(library_name):
def process_libraries(state):
new_flags = []
libraries = []
suffixes = STATICLIB_ENDINGS + DYNAMICLIB_ENDINGS
system_libs_map = system_libs.Library.get_usable_variations()

# Find library files
Expand All @@ -2835,16 +2834,23 @@ def process_libraries(state):
if js_libs is not None:
continue

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

if path:
new_flags.append((i, path))
continue
if found_dylib:
continue

new_flags.append((i, flag))

Expand Down

0 comments on commit 4f73509

Please sign in to comment.