@@ -203,15 +203,12 @@ def __init__(self, args):
203
203
self .has_dash_c = False
204
204
self .has_dash_E = False
205
205
self .has_dash_S = False
206
- self .libs = []
207
206
self .link_flags = []
208
207
self .lib_dirs = []
209
208
self .forced_stdlibs = []
210
209
211
210
212
211
def add_link_flag (state , i , f ):
213
- if f .startswith ('-l' ):
214
- state .libs .append ((i , f [2 :]))
215
212
if f .startswith ('-L' ):
216
213
state .lib_dirs .append (f [2 :])
217
214
@@ -487,6 +484,21 @@ def is_supported(f):
487
484
return results
488
485
489
486
487
+ def map_library_names (link_flags ):
488
+ system_libs_map = system_libs .Library .get_usable_variations ()
489
+
490
+ def map_flag (pair ):
491
+ flag = pair [1 ]
492
+ if flag .startswith ('-l' ):
493
+ name = 'lib' + strip_prefix (flag , '-l' )
494
+ if name in system_libs_map :
495
+ lib = system_libs_map [name ]
496
+ return (pair [0 ], '-l' + strip_prefix (lib .get_base_name (), 'lib' ))
497
+ return pair
498
+
499
+ return [map_flag (f ) for f in link_flags ]
500
+
501
+
490
502
def fix_windows_newlines (text ):
491
503
# Avoid duplicating \r\n to \r\r\n when writing out text.
492
504
if WINDOWS :
@@ -1054,7 +1066,7 @@ def run(args):
1054
1066
if state .mode == Mode .POST_LINK_ONLY :
1055
1067
settings .limit_settings (None )
1056
1068
target , wasm_target = phase_linker_setup (options , state , newargs , settings_map )
1057
- process_libraries (state .libs , state .lib_dirs , [])
1069
+ process_libraries (state .link_flags , state .lib_dirs , [])
1058
1070
if len (input_files ) != 1 :
1059
1071
exit_with_error ('--post-link requires a single input file' )
1060
1072
phase_post_link (options , state , input_files [0 ][1 ], wasm_target , target )
@@ -1115,11 +1127,10 @@ def run(args):
1115
1127
def phase_calculate_linker_inputs (options , state , linker_inputs ):
1116
1128
using_lld = not (options .oformat == OFormat .OBJECT and settings .LTO )
1117
1129
state .link_flags = filter_link_flags (state .link_flags , using_lld )
1130
+ state .link_flags = map_library_names (state .link_flags )
1118
1131
1119
1132
# Decide what we will link
1120
- consumed = process_libraries (state .libs , state .lib_dirs , linker_inputs )
1121
- # Filter out libraries that are actually JS libs
1122
- state .link_flags = [l for l in state .link_flags if l [0 ] not in consumed ]
1133
+ state .link_flags = process_libraries (state .link_flags , state .lib_dirs , linker_inputs )
1123
1134
1124
1135
# If we are linking to an intermediate object then ignore other
1125
1136
# "fake" dynamic libraries, since otherwise we will end up with
@@ -1245,7 +1256,7 @@ def phase_setup(options, state, newargs, settings_map):
1245
1256
# library and attempt to find a library by the same name in our own library path.
1246
1257
# TODO(sbc): Do we really need this feature? See test_other.py:test_local_link
1247
1258
libname = strip_prefix (unsuffixed_basename (arg ), 'lib' )
1248
- state . libs . append (( i , libname ) )
1259
+ add_link_flag ( state , i , '-l' + libname )
1249
1260
else :
1250
1261
input_files .append ((i , arg ))
1251
1262
elif arg .startswith ('-L' ):
@@ -1987,7 +1998,7 @@ def check_memory_setting(setting):
1987
1998
# When not declaring wasm module exports in outer scope one by one, disable minifying
1988
1999
# wasm module export names so that the names can be passed directly to the outer scope.
1989
2000
# Also, if using library_exports.js API, disable minification so that the feature can work.
1990
- if not settings .DECLARE_ASM_MODULE_EXPORTS or 'exports .js' in [x for _ , x in state .libs ]:
2001
+ if not settings .DECLARE_ASM_MODULE_EXPORTS or '-lexports .js' in [x for _ , x in state .link_flags ]:
1991
2002
settings .MINIFY_ASMJS_EXPORT_NAMES = 0
1992
2003
1993
2004
# Enable minification of wasm imports and exports when appropriate, if we
@@ -3507,13 +3518,17 @@ def find_library(lib, lib_dirs):
3507
3518
return None
3508
3519
3509
3520
3510
- def process_libraries (libs , lib_dirs , linker_inputs ):
3521
+ def process_libraries (link_flags , lib_dirs , linker_inputs ):
3522
+ new_flags = []
3511
3523
libraries = []
3512
- consumed = []
3513
3524
suffixes = STATICLIB_ENDINGS + DYNAMICLIB_ENDINGS
3514
3525
3515
3526
# Find library files
3516
- for i , lib in libs :
3527
+ for i , flag in link_flags :
3528
+ if not flag .startswith ('-l' ):
3529
+ new_flags .append ((i , flag ))
3530
+ continue
3531
+ lib = strip_prefix (flag , '-l' )
3517
3532
logger .debug ('looking for library "%s"' , lib )
3518
3533
3519
3534
path = None
@@ -3525,22 +3540,20 @@ def process_libraries(libs, lib_dirs, linker_inputs):
3525
3540
3526
3541
if path :
3527
3542
linker_inputs .append ((i , path ))
3528
- consumed .append (i )
3529
- else :
3530
- jslibs = building .map_to_js_libs (lib )
3531
- if jslibs is not None :
3532
- libraries += [(i , jslib ) for jslib in jslibs ]
3533
- consumed .append (i )
3534
- elif building .map_and_apply_to_settings (lib ):
3535
- consumed .append (i )
3543
+ continue
3544
+ jslibs = building .map_to_js_libs (lib )
3545
+ if jslibs is not None :
3546
+ libraries += [(i , jslib ) for jslib in jslibs ]
3547
+ elif not building .map_and_apply_to_settings (lib ):
3548
+ new_flags .append ((i , flag ))
3536
3549
3537
3550
settings .SYSTEM_JS_LIBRARIES += libraries
3538
3551
3539
3552
# At this point processing SYSTEM_JS_LIBRARIES is finished, no more items will be added to it.
3540
3553
# Sort the input list from (order, lib_name) pairs to a flat array in the right order.
3541
3554
settings .SYSTEM_JS_LIBRARIES .sort (key = lambda lib : lib [0 ])
3542
3555
settings .SYSTEM_JS_LIBRARIES = [lib [1 ] for lib in settings .SYSTEM_JS_LIBRARIES ]
3543
- return consumed
3556
+ return new_flags
3544
3557
3545
3558
3546
3559
class ScriptSource :
0 commit comments