Skip to content

Commit 223995c

Browse files
authored
Remove internal settings.LTO in favor of options.lto (#27422)
Followup to #27407 Because `settings.LTO` was an internal setting not used anywhere in JavaScript libraries or runtime code. This change removes `LTO` from `src/settings_internal.js` and stores `-flto` / `-fno-lto` state in `options.lto` on `EmccOptions` instead. In the long run I hope to use internal settings only for values that need to flow out the the JS compiler.
1 parent 00149c0 commit 223995c

9 files changed

Lines changed: 21 additions & 17 deletions

File tree

embuilder.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from contextlib import contextmanager
2222

2323
from tools import cache, ports, shared, system_libs, utils
24+
from tools.cmdline import options
2425
from tools.settings import settings
2526
from tools.system_libs import USE_NINJA
2627

@@ -232,7 +233,7 @@ def main():
232233
shared.check_sanity()
233234

234235
if args.lto:
235-
settings.LTO = args.lto
236+
options.lto = args.lto
236237

237238
if args.verbose:
238239
shared.PRINT_SUBPROCS = True

emcc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ def get_clang_command_asm():
524524
return compiler + compile.get_target_flags()
525525

526526
if state.mode == Mode.COMPILE_ONLY:
527-
if options.output_file and get_file_suffix(options.output_file) == '.bc' and not settings.LTO and '-emit-llvm' not in state.orig_args:
527+
if options.output_file and get_file_suffix(options.output_file) == '.bc' and not options.lto and '-emit-llvm' not in state.orig_args:
528528
diagnostics.warning('emcc', '.bc output file suffix used without -flto or -emit-llvm. Consider using .o extension since emcc will output an object file, not a bitcode file')
529529
if all(get_file_suffix(i) in ASSEMBLY_EXTENSIONS for i in options.input_files):
530530
cmd = get_clang_command_asm() + newargs

src/settings_internal.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,6 @@ var MINIFY_WASM_IMPORTED_MODULES = false;
152152
// Whether to minify exports from the Wasm module.
153153
var MINIFY_WASM_EXPORT_NAMES = true;
154154

155-
// Internal: value of -flto argument (either full or thin)
156-
var LTO = 0;
157155

158156
// Whether we may be accessing the address 2GB or higher. If so, then we need
159157
// to interpret incoming i32 pointers as unsigned.

test/test_other.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102

103103
from tools import building, cache, response_file, shared, utils, webassembly
104104
from tools.building import get_building_env
105+
from tools.cmdline import options
105106
from tools.link import binary_encode
106107
from tools.settings import settings
107108
from tools.shared import (
@@ -753,7 +754,7 @@ def test_print_search_dirs(self, args):
753754
libpath = output.split('libraries: =', 1)[1].strip()
754755
libpath = libpath.split(os.pathsep)
755756
libpath = [Path(p) for p in libpath]
756-
settings.LTO = '-flto' in args
757+
options.lto = 'full' if '-flto' in args else None
757758
settings.MEMORY64 = int('-m64' in args)
758759
expected = cache.get_lib_dir(absolute=True)
759760
self.assertIn(expected, libpath)
@@ -768,7 +769,7 @@ def test_print_libgcc_file_name(self, args):
768769
output = self.run_process([EMCC, '-print-libgcc-file-name'] + args, stdout=PIPE).stdout
769770
output2 = self.run_process([EMCC, '--print-libgcc-file-name'] + args, stdout=PIPE).stdout
770771
self.assertEqual(output, output2)
771-
settings.LTO = '-flto' in args
772+
options.lto = 'full' if '-flto' in args else None
772773
settings.MEMORY64 = int('-m64' in args)
773774
libdir = cache.get_lib_dir(absolute=True)
774775
expected = os.path.join(libdir, 'libclang_rt.builtins.a')
@@ -805,7 +806,7 @@ def test_print_file_name(self, args):
805806
output2 = self.run_process([EMCC, '--print-file-name=libc.a'] + args, stdout=PIPE).stdout.rstrip()
806807
self.assertEqual(output, output2)
807808
filename = Path(output)
808-
settings.LTO = '-flto' in args
809+
options.lto = 'full' if '-flto' in args else None
809810
settings.MEMORY64 = int('-m64' in args)
810811
self.assertContained(cache.get_lib_name('libc.a'), str(filename))
811812

@@ -11791,7 +11792,7 @@ def test_setjmp_emulated_casts(self):
1179111792
self.do_runf('src.c', 'ok\ndone\n', cflags=['-sEMULATE_FUNCTION_POINTER_CASTS'])
1179211793

1179311794
def test_no_lto(self):
11794-
# This used to fail because settings.LTO didn't reflect `-fno-lto`.
11795+
# This used to fail because options.lto didn't reflect `-fno-lto`.
1179511796
# See bug https://github.com/emscripten-core/emscripten/issues/20308
1179611797
create_file('src.c', r'''
1179711798
#include <stdio.h>

tools/building.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
from . import (
1818
cache,
19+
cmdline,
1920
config,
2021
diagnostics,
2122
js_optimizer,
@@ -190,7 +191,7 @@ def lld_flags_for_executable(external_symbols):
190191
not settings.ASYNCIFY):
191192
cmd.append('--strip-debug')
192193

193-
if settings.LTO and not settings.EXIT_RUNTIME:
194+
if cmdline.options.lto and not settings.EXIT_RUNTIME:
194195
# The WebAssembly backend can generate new references to `__cxa_atexit` at
195196
# LTO time. This `-u` flag forces the `__cxa_atexit` symbol to be
196197
# included at LTO time. For other such symbols we exclude them from LTO

tools/cache.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ def get_sysroot_dir(*parts):
110110

111111

112112
def get_lib_dir(absolute):
113+
from .cmdline import options
114+
113115
ensure_setup()
114116
path = Path(get_sysroot(absolute=absolute), 'lib')
115117
if settings.MEMORY64:
@@ -118,8 +120,8 @@ def get_lib_dir(absolute):
118120
path = Path(path, 'wasm32-emscripten')
119121
# if relevant, use a subdir of the cache
120122
subdir = []
121-
if settings.LTO:
122-
if settings.LTO == 'thin':
123+
if options.lto:
124+
if options.lto == 'thin':
123125
subdir.append('thinlto')
124126
else:
125127
subdir.append('lto')

tools/cmdline.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class EmccOptions:
7373
input_language = None
7474
js_transform = None
7575
lib_dirs: list[str] = []
76+
lto: str | None = None
7677
memory_profiler = False
7778
no_entry = False
7879
no_minify = False
@@ -315,11 +316,11 @@ def consume_arg_file():
315316
settings.OPT_LEVEL = level
316317
elif arg.startswith('-flto'):
317318
if '=' in arg:
318-
settings.LTO = arg.split('=')[1]
319+
options.lto = arg.split('=')[1]
319320
else:
320-
settings.LTO = 'full'
321+
options.lto = 'full'
321322
elif arg == "-fno-lto":
322-
settings.LTO = 0
323+
options.lto = None
323324
elif arg == "--save-temps":
324325
options.save_temps = True
325326
elif check_arg('--closure-args'):

tools/link.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3111,7 +3111,7 @@ def package_files(target):
31113111

31123112
@ToolchainProfiler.profile_block('calculate linker inputs')
31133113
def phase_calculate_linker_inputs(linker_args):
3114-
using_lld = not (options.oformat == OFormat.OBJECT and settings.LTO)
3114+
using_lld = not (options.oformat == OFormat.OBJECT and options.lto)
31153115

31163116
linker_args = filter_link_flags(linker_args, using_lld)
31173117

tools/system_libs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ def get_base_cflags(build_dir, force_object_files=False, preprocess=True):
6262
# Always build system libraries with debug information. Non-debug builds
6363
# will ignore this at link time because we link with `-strip-debug`.
6464
flags = ['-g', '-sSTRICT', '-Werror']
65-
if settings.LTO and not force_object_files:
66-
flags += ['-flto=' + settings.LTO]
65+
if options.lto and not force_object_files:
66+
flags += ['-flto=' + options.lto]
6767
if settings.MAIN_MODULE or settings.SIDE_MODULE:
6868
# Explicitly include `-sMAIN_MODULE` when building system libraries.
6969
# `-fPIC` alone is not enough to configure trigger the building and

0 commit comments

Comments
 (0)