Skip to content

Commit 1b8b227

Browse files
authored
[link.py] Remove the need to pass newargs around. NFC (#23317)
All the use cases in `link.py` can be satisfied by the existing `orig_args` which is part of the compiler state.
1 parent c75230c commit 1b8b227

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

emcc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ def run(args):
660660
exit_with_error('--post-link requires a single input file')
661661
# Delay import of link.py to avoid processing this file when only compiling
662662
from tools import link
663-
link.run_post_link(input_files[0][1], options, state, newargs)
663+
link.run_post_link(input_files[0][1], options, state)
664664
return 0
665665

666666
## Compile source code to object files
@@ -669,7 +669,7 @@ def run(args):
669669
if state.mode == Mode.COMPILE_AND_LINK:
670670
# Delay import of link.py to avoid processing this file when only compiling
671671
from tools import link
672-
return link.run(linker_inputs, options, state, newargs)
672+
return link.run(linker_inputs, options, state)
673673
else:
674674
logger.debug('stopping after compile phase')
675675
return 0

tools/link.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ def check_browser_versions():
636636

637637

638638
@ToolchainProfiler.profile_block('linker_setup')
639-
def phase_linker_setup(options, state, newargs): # noqa: C901, PLR0912, PLR0915
639+
def phase_linker_setup(options, state): # noqa: C901, PLR0912, PLR0915
640640
"""Future modifications should consider refactoring to reduce complexity.
641641
642642
* The McCabe cyclomatiic complexity is currently 251 vs 10 recommended.
@@ -898,7 +898,7 @@ def phase_linker_setup(options, state, newargs): # noqa: C901, PLR0912, PLR0915
898898
# PURE_WASI, or when we are linking without standard libraries because
899899
# STACK_OVERFLOW_CHECK depends on emscripten_stack_get_end which is defined
900900
# in libcompiler-rt.
901-
if not settings.PURE_WASI and '-nostdlib' not in newargs and '-nodefaultlibs' not in newargs:
901+
if not settings.PURE_WASI and '-nostdlib' not in state.orig_args and '-nodefaultlibs' not in state.orig_args:
902902
default_setting('STACK_OVERFLOW_CHECK', max(settings.ASSERTIONS, settings.STACK_OVERFLOW_CHECK))
903903

904904
# For users that opt out of WARN_ON_UNDEFINED_SYMBOLS we assume they also
@@ -1537,7 +1537,7 @@ def phase_linker_setup(options, state, newargs): # noqa: C901, PLR0912, PLR0915
15371537

15381538
sanitize = set()
15391539

1540-
for arg in newargs:
1540+
for arg in state.orig_args:
15411541
if arg.startswith('-fsanitize='):
15421542
sanitize.update(arg.split('=', 1)[1].split(','))
15431543
elif arg.startswith('-fno-sanitize='):
@@ -1576,7 +1576,7 @@ def phase_linker_setup(options, state, newargs): # noqa: C901, PLR0912, PLR0915
15761576
settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE.append('$UTF8ArrayToString')
15771577

15781578
if sanitize & UBSAN_SANITIZERS:
1579-
if '-fsanitize-minimal-runtime' in newargs:
1579+
if '-fsanitize-minimal-runtime' in state.orig_args:
15801580
settings.UBSAN_RUNTIME = 1
15811581
else:
15821582
settings.UBSAN_RUNTIME = 2
@@ -1791,7 +1791,7 @@ def get_full_import_name(name):
17911791
settings.EMSCRIPTEN_VERSION = utils.EMSCRIPTEN_VERSION
17921792
settings.SOURCE_MAP_BASE = options.source_map_base or ''
17931793

1794-
settings.LINK_AS_CXX = (shared.run_via_emxx or settings.DEFAULT_TO_CXX) and '-nostdlib++' not in newargs
1794+
settings.LINK_AS_CXX = (shared.run_via_emxx or settings.DEFAULT_TO_CXX) and '-nostdlib++' not in state.orig_args
17951795

17961796
# WASMFS itself is written in C++, and needs C++ standard libraries
17971797
if settings.WASMFS:
@@ -1866,13 +1866,13 @@ def get_full_import_name(name):
18661866

18671867

18681868
@ToolchainProfiler.profile_block('calculate system libraries')
1869-
def phase_calculate_system_libraries(linker_arguments, newargs):
1869+
def phase_calculate_system_libraries(state, linker_arguments):
18701870
extra_files_to_link = []
18711871
# Link in ports and system libraries, if necessary
18721872
if not settings.SIDE_MODULE:
18731873
# Ports are always linked into the main module, never the side module.
18741874
extra_files_to_link += ports.get_libs(settings)
1875-
extra_files_to_link += system_libs.calculate(newargs)
1875+
extra_files_to_link += system_libs.calculate(state.orig_args)
18761876
linker_arguments.extend(extra_files_to_link)
18771877

18781878

@@ -3109,14 +3109,14 @@ def phase_calculate_linker_inputs(options, state, linker_inputs):
31093109
return linker_args
31103110

31113111

3112-
def run_post_link(wasm_input, options, state, newargs):
3112+
def run_post_link(wasm_input, options, state):
31133113
settings.limit_settings(None)
3114-
target, wasm_target = phase_linker_setup(options, state, newargs)
3114+
target, wasm_target = phase_linker_setup(options, state )
31153115
process_libraries(state, [])
31163116
phase_post_link(options, state, wasm_input, wasm_target, target, {})
31173117

31183118

3119-
def run(linker_inputs, options, state, newargs):
3119+
def run(linker_inputs, options, state):
31203120
# We have now passed the compile phase, allow reading/writing of all settings.
31213121
settings.limit_settings(None)
31223122

@@ -3126,7 +3126,7 @@ def run(linker_inputs, options, state, newargs):
31263126
if options.output_file and options.output_file.startswith('-'):
31273127
exit_with_error(f'invalid output filename: `{options.output_file}`')
31283128

3129-
target, wasm_target = phase_linker_setup(options, state, newargs)
3129+
target, wasm_target = phase_linker_setup(options, state)
31303130

31313131
# Link object files using wasm-ld or llvm-link (for bitcode linking)
31323132
linker_arguments = phase_calculate_linker_inputs(options, state, linker_inputs)
@@ -3141,7 +3141,7 @@ def run(linker_inputs, options, state, newargs):
31413141
logger.debug('stopping after linking to object file')
31423142
return 0
31433143

3144-
phase_calculate_system_libraries(linker_arguments, newargs)
3144+
phase_calculate_system_libraries(state, linker_arguments)
31453145

31463146
js_syms = {}
31473147
if (not settings.SIDE_MODULE or settings.ASYNCIFY) and not shared.SKIP_SUBPROCS:

0 commit comments

Comments
 (0)