Skip to content

Commit 78214a9

Browse files
authored
Followup to variable renaming in emscripten-core#13921 (emscripten-core#13923)
For consistency with emscripten-core#13921 also rename some args and locals in the linking-related functions in building.py. The first argument to these functions are linker arguments that include both files and flags so just calling them args I think is clearer.
1 parent 4e33590 commit 78214a9

File tree

1 file changed

+38
-39
lines changed

1 file changed

+38
-39
lines changed

tools/building.py

Lines changed: 38 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -334,12 +334,12 @@ def llvm_backend_args():
334334
return args
335335

336336

337-
def link_to_object(linker_inputs, target):
337+
def link_to_object(args, target):
338338
# link using lld unless LTO is requested (lld can't output LTO/bitcode object files).
339339
if not settings.LTO:
340-
link_lld(linker_inputs + ['--relocatable'], target)
340+
link_lld(args + ['--relocatable'], target)
341341
else:
342-
link_bitcode(linker_inputs, target)
342+
link_bitcode(args, target)
343343

344344

345345
def link_llvm(linker_inputs, target):
@@ -462,25 +462,23 @@ def link_lld(args, target, external_symbol_list=None):
462462
check_call(cmd)
463463

464464

465-
def link_bitcode(files, target, force_archive_contents=False):
465+
def link_bitcode(args, target, force_archive_contents=False):
466466
# "Full-featured" linking: looks into archives (duplicates lld functionality)
467-
actual_files = []
467+
input_files = [a for a in args if not a.startswith('-')]
468+
files_to_link = []
468469
# Tracking unresolveds is necessary for .a linking, see below.
469470
# Specify all possible entry points to seed the linking process.
470471
# For a simple application, this would just be "main".
471472
unresolved_symbols = set([func[1:] for func in settings.EXPORTED_FUNCTIONS])
472473
resolved_symbols = set()
473474
# Paths of already included object files from archives.
474475
added_contents = set()
475-
has_ar = False
476-
for f in files:
477-
if not f.startswith('-'):
478-
has_ar = has_ar or is_ar(make_paths_absolute(f))
476+
has_ar = any(is_ar(make_paths_absolute(f)) for f in input_files)
479477

480478
# If we have only one archive or the force_archive_contents flag is set,
481479
# then we will add every object file we see, regardless of whether it
482480
# resolves any undefined symbols.
483-
force_add_all = len(files) == 1 or force_archive_contents
481+
force_add_all = len(input_files) == 1 or force_archive_contents
484482

485483
# Considers an object file for inclusion in the link. The object is included
486484
# if force_add=True or if the object provides a currently undefined symbol.
@@ -506,7 +504,7 @@ def consider_object(f, force_add=False):
506504
# removing newly resolved symbols.
507505
unresolved_symbols.update(new_symbols.undefs.difference(resolved_symbols))
508506
unresolved_symbols.difference_update(provided)
509-
actual_files.append(f)
507+
files_to_link.append(f)
510508
return do_add
511509

512510
# Traverse a single archive. The object files are repeatedly scanned for
@@ -531,7 +529,7 @@ def consider_archive(f, force_add):
531529
logger.debug('done running loop of archive %s' % (f))
532530
return added_any_objects
533531

534-
read_link_inputs([x for x in files if not x.startswith('-')])
532+
read_link_inputs(input_files)
535533

536534
# Rescan a group of archives until we don't find any more objects to link.
537535
def scan_archive_group(group):
@@ -546,41 +544,42 @@ def scan_archive_group(group):
546544

547545
current_archive_group = None
548546
in_whole_archive = False
549-
for f in files:
550-
absolute_path_f = make_paths_absolute(f)
551-
if f.startswith('-'):
552-
if f in ['--start-group', '-(']:
547+
for a in args:
548+
if a.startswith('-'):
549+
if a in ['--start-group', '-(']:
553550
assert current_archive_group is None, 'Nested --start-group, missing --end-group?'
554551
current_archive_group = []
555-
elif f in ['--end-group', '-)']:
552+
elif a in ['--end-group', '-)']:
556553
assert current_archive_group is not None, '--end-group without --start-group'
557554
scan_archive_group(current_archive_group)
558555
current_archive_group = None
559-
elif f in ['--whole-archive', '-whole-archive']:
556+
elif a in ['--whole-archive', '-whole-archive']:
560557
in_whole_archive = True
561-
elif f in ['--no-whole-archive', '-no-whole-archive']:
558+
elif a in ['--no-whole-archive', '-no-whole-archive']:
562559
in_whole_archive = False
563560
else:
564561
# Command line flags should already be vetted by the time this method
565562
# is called, so this is an internal error
566-
assert False, 'unsupported link flag: ' + f
567-
elif is_ar(absolute_path_f):
568-
# Extract object files from ar archives, and link according to gnu ld semantics
569-
# (link in an entire .o from the archive if it supplies symbols still unresolved)
570-
consider_archive(absolute_path_f, in_whole_archive or force_add_all)
571-
# If we're inside a --start-group/--end-group section, add to the list
572-
# so we can loop back around later.
573-
if current_archive_group is not None:
574-
current_archive_group.append(absolute_path_f)
575-
elif is_bitcode(absolute_path_f):
576-
if has_ar:
577-
consider_object(f, force_add=True)
578-
else:
579-
# If there are no archives then we can simply link all valid object
580-
# files and skip the symbol table stuff.
581-
actual_files.append(f)
563+
exit_with_error('unsupported link flag: %s', a)
582564
else:
583-
exit_with_error('unknown file type: %s', f)
565+
lib_path = make_paths_absolute(a)
566+
if is_ar(lib_path):
567+
# Extract object files from ar archives, and link according to gnu ld semantics
568+
# (link in an entire .o from the archive if it supplies symbols still unresolved)
569+
consider_archive(lib_path, in_whole_archive or force_add_all)
570+
# If we're inside a --start-group/--end-group section, add to the list
571+
# so we can loop back around later.
572+
if current_archive_group is not None:
573+
current_archive_group.append(lib_path)
574+
elif is_bitcode(lib_path):
575+
if has_ar:
576+
consider_object(a, force_add=True)
577+
else:
578+
# If there are no archives then we can simply link all valid object
579+
# files and skip the symbol table stuff.
580+
files_to_link.append(a)
581+
else:
582+
exit_with_error('unknown file type: %s', a)
584583

585584
# We have to consider the possibility that --start-group was used without a matching
586585
# --end-group; GNU ld permits this behavior and implicitly treats the end of the
@@ -594,10 +593,10 @@ def scan_archive_group(group):
594593

595594
# Finish link
596595
# tolerate people trying to link a.so a.so etc.
597-
actual_files = unique_ordered(actual_files)
596+
files_to_link = unique_ordered(files_to_link)
598597

599-
logger.debug('emcc: linking: %s to %s', actual_files, target)
600-
link_llvm(actual_files, target)
598+
logger.debug('emcc: linking: %s to %s', files_to_link, target)
599+
link_llvm(files_to_link, target)
601600

602601

603602
def get_command_with_possible_response_file(cmd):

0 commit comments

Comments
 (0)