Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion embuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from contextlib import contextmanager

from tools import cache, ports, shared, system_libs, utils
from tools.cmdline import options
from tools.settings import settings
from tools.system_libs import USE_NINJA

Expand Down Expand Up @@ -232,7 +233,7 @@ def main():
shared.check_sanity()

if args.lto:
settings.LTO = args.lto
options.lto = args.lto

if args.verbose:
shared.PRINT_SUBPROCS = True
Expand Down
2 changes: 1 addition & 1 deletion emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ def get_clang_command_asm():
return compiler + compile.get_target_flags()

if state.mode == Mode.COMPILE_ONLY:
if options.output_file and get_file_suffix(options.output_file) == '.bc' and not settings.LTO and '-emit-llvm' not in state.orig_args:
if options.output_file and get_file_suffix(options.output_file) == '.bc' and not options.lto and '-emit-llvm' not in state.orig_args:
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')
if all(get_file_suffix(i) in ASSEMBLY_EXTENSIONS for i in options.input_files):
cmd = get_clang_command_asm() + newargs
Expand Down
2 changes: 0 additions & 2 deletions src/settings_internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,6 @@ var MINIFY_WASM_IMPORTED_MODULES = false;
// Whether to minify exports from the Wasm module.
var MINIFY_WASM_EXPORT_NAMES = true;

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

// Whether we may be accessing the address 2GB or higher. If so, then we need
// to interpret incoming i32 pointers as unsigned.
Expand Down
9 changes: 5 additions & 4 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@

from tools import building, cache, response_file, shared, utils, webassembly
from tools.building import get_building_env
from tools.cmdline import options
from tools.link import binary_encode
from tools.settings import settings
from tools.shared import (
Expand Down Expand Up @@ -753,7 +754,7 @@ def test_print_search_dirs(self, args):
libpath = output.split('libraries: =', 1)[1].strip()
libpath = libpath.split(os.pathsep)
libpath = [Path(p) for p in libpath]
settings.LTO = '-flto' in args
options.lto = 'full' if '-flto' in args else None
settings.MEMORY64 = int('-m64' in args)
expected = cache.get_lib_dir(absolute=True)
self.assertIn(expected, libpath)
Expand All @@ -768,7 +769,7 @@ def test_print_libgcc_file_name(self, args):
output = self.run_process([EMCC, '-print-libgcc-file-name'] + args, stdout=PIPE).stdout
output2 = self.run_process([EMCC, '--print-libgcc-file-name'] + args, stdout=PIPE).stdout
self.assertEqual(output, output2)
settings.LTO = '-flto' in args
options.lto = 'full' if '-flto' in args else None
settings.MEMORY64 = int('-m64' in args)
libdir = cache.get_lib_dir(absolute=True)
expected = os.path.join(libdir, 'libclang_rt.builtins.a')
Expand Down Expand Up @@ -805,7 +806,7 @@ def test_print_file_name(self, args):
output2 = self.run_process([EMCC, '--print-file-name=libc.a'] + args, stdout=PIPE).stdout.rstrip()
self.assertEqual(output, output2)
filename = Path(output)
settings.LTO = '-flto' in args
options.lto = 'full' if '-flto' in args else None
settings.MEMORY64 = int('-m64' in args)
self.assertContained(cache.get_lib_name('libc.a'), str(filename))

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

def test_no_lto(self):
# This used to fail because settings.LTO didn't reflect `-fno-lto`.
# This used to fail because options.lto didn't reflect `-fno-lto`.
# See bug https://github.com/emscripten-core/emscripten/issues/20308
create_file('src.c', r'''
#include <stdio.h>
Expand Down
3 changes: 2 additions & 1 deletion tools/building.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

from . import (
cache,
cmdline,
config,
diagnostics,
js_optimizer,
Expand Down Expand Up @@ -190,7 +191,7 @@ def lld_flags_for_executable(external_symbols):
not settings.ASYNCIFY):
cmd.append('--strip-debug')

if settings.LTO and not settings.EXIT_RUNTIME:
if cmdline.options.lto and not settings.EXIT_RUNTIME:
# The WebAssembly backend can generate new references to `__cxa_atexit` at
# LTO time. This `-u` flag forces the `__cxa_atexit` symbol to be
# included at LTO time. For other such symbols we exclude them from LTO
Expand Down
6 changes: 4 additions & 2 deletions tools/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ def get_sysroot_dir(*parts):


def get_lib_dir(absolute):
from .cmdline import options
Comment thread
sbc100 marked this conversation as resolved.

ensure_setup()
path = Path(get_sysroot(absolute=absolute), 'lib')
if settings.MEMORY64:
Expand All @@ -118,8 +120,8 @@ def get_lib_dir(absolute):
path = Path(path, 'wasm32-emscripten')
# if relevant, use a subdir of the cache
subdir = []
if settings.LTO:
if settings.LTO == 'thin':
if options.lto:
if options.lto == 'thin':
subdir.append('thinlto')
else:
subdir.append('lto')
Expand Down
7 changes: 4 additions & 3 deletions tools/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class EmccOptions:
input_language = None
js_transform = None
lib_dirs: list[str] = []
lto: str | None = None
memory_profiler = False
no_entry = False
no_minify = False
Expand Down Expand Up @@ -315,11 +316,11 @@ def consume_arg_file():
settings.OPT_LEVEL = level
elif arg.startswith('-flto'):
if '=' in arg:
settings.LTO = arg.split('=')[1]
options.lto = arg.split('=')[1]
else:
settings.LTO = 'full'
options.lto = 'full'
elif arg == "-fno-lto":
settings.LTO = 0
options.lto = None
elif arg == "--save-temps":
options.save_temps = True
elif check_arg('--closure-args'):
Expand Down
2 changes: 1 addition & 1 deletion tools/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -3111,7 +3111,7 @@ def package_files(target):

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

linker_args = filter_link_flags(linker_args, using_lld)

Expand Down
4 changes: 2 additions & 2 deletions tools/system_libs.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ def get_base_cflags(build_dir, force_object_files=False, preprocess=True):
# Always build system libraries with debug information. Non-debug builds
# will ignore this at link time because we link with `-strip-debug`.
flags = ['-g', '-sSTRICT', '-Werror']
if settings.LTO and not force_object_files:
flags += ['-flto=' + settings.LTO]
if options.lto and not force_object_files:
flags += ['-flto=' + options.lto]
if settings.MAIN_MODULE or settings.SIDE_MODULE:
# Explicitly include `-sMAIN_MODULE` when building system libraries.
# `-fPIC` alone is not enough to configure trigger the building and
Expand Down
Loading