emcc.py: consistent use of `user_settings` variable name. NFC (#16366)
This map was being used in a few different places under different
names.
Also, remove duplicate definition of `default_setting`.
Sam Clegg authored 2 years ago
GitHub committed 2 years ago
339 | 339 | return value |
340 | 340 | |
341 | 341 | |
342 | def apply_settings(changes): | |
342 | def default_setting(user_settings, name, new_default): | |
343 | if name not in user_settings: | |
344 | setattr(settings, name, new_default) | |
345 | ||
346 | ||
347 | def apply_settings(user_settings): | |
343 | 348 | """Take a map of users settings {NAME: VALUE} and apply them to the global |
344 | 349 | settings object. |
345 | 350 | """ |
357 | 362 | value = str(1 - int(value)) |
358 | 363 | return key, value |
359 | 364 | |
360 | for key, value in changes.items(): | |
365 | for key, value in user_settings.items(): | |
361 | 366 | key, value = standardize_setting_change(key, value) |
362 | 367 | |
363 | 368 | if key in settings.internal_settings: |
1121 | 1126 | |
1122 | 1127 | ## Process argument and setup the compiler |
1123 | 1128 | state = EmccState(args) |
1124 | options, newargs, settings_map = phase_parse_arguments(state) | |
1129 | options, newargs, user_settings = phase_parse_arguments(state) | |
1125 | 1130 | |
1126 | 1131 | if 'EMMAKEN_NO_SDK' in os.environ: |
1127 | 1132 | exit_with_error('EMMAKEN_NO_SDK is no longer supported. The standard -nostdlib and -nostdinc flags should be used instead') |
1137 | 1142 | # settings until we reach the linking phase. |
1138 | 1143 | settings.limit_settings(COMPILE_TIME_SETTINGS) |
1139 | 1144 | |
1140 | newargs, input_files = phase_setup(options, state, newargs, settings_map) | |
1145 | newargs, input_files = phase_setup(options, state, newargs, user_settings) | |
1141 | 1146 | |
1142 | 1147 | if state.mode == Mode.POST_LINK_ONLY: |
1143 | 1148 | settings.limit_settings(None) |
1144 | target, wasm_target = phase_linker_setup(options, state, newargs, settings_map) | |
1149 | target, wasm_target = phase_linker_setup(options, state, newargs, user_settings) | |
1145 | 1150 | process_libraries(state, []) |
1146 | 1151 | if len(input_files) != 1: |
1147 | 1152 | exit_with_error('--post-link requires a single input file') |
1166 | 1171 | if options.output_file and options.output_file.startswith('-'): |
1167 | 1172 | exit_with_error(f'invalid output filename: `{options.output_file}`') |
1168 | 1173 | |
1169 | target, wasm_target = phase_linker_setup(options, state, newargs, settings_map) | |
1174 | target, wasm_target = phase_linker_setup(options, state, newargs, user_settings) | |
1170 | 1175 | |
1171 | 1176 | # Link object files using wasm-ld or llvm-link (for bitcode linking) |
1172 | 1177 | linker_arguments = phase_calculate_linker_inputs(options, state, linker_inputs) |
1276 | 1281 | |
1277 | 1282 | |
1278 | 1283 | @ToolchainProfiler.profile_block('setup') |
1279 | def phase_setup(options, state, newargs, settings_map): | |
1284 | def phase_setup(options, state, newargs, user_settings): | |
1280 | 1285 | """Second phase: configure and setup the compiler based on the specified settings and arguments. |
1281 | 1286 | """ |
1282 | 1287 | |
1284 | 1289 | diagnostics.warning('deprecated', 'RUNTIME_LINKED_LIBS is deprecated; you can simply list the libraries directly on the commandline now') |
1285 | 1290 | newargs += settings.RUNTIME_LINKED_LIBS |
1286 | 1291 | |
1287 | def default_setting(name, new_default): | |
1288 | if name not in settings_map: | |
1289 | setattr(settings, name, new_default) | |
1290 | ||
1291 | 1292 | if settings.STRICT: |
1292 | default_setting('DEFAULT_TO_CXX', 0) | |
1293 | default_setting(user_settings, 'DEFAULT_TO_CXX', 0) | |
1293 | 1294 | |
1294 | 1295 | # Find input files |
1295 | 1296 | |
1397 | 1398 | state.mode = Mode.COMPILE_ONLY |
1398 | 1399 | |
1399 | 1400 | if state.mode in (Mode.COMPILE_ONLY, Mode.PREPROCESS_ONLY): |
1400 | for key in settings_map: | |
1401 | for key in user_settings: | |
1401 | 1402 | if key not in COMPILE_TIME_SETTINGS: |
1402 | 1403 | diagnostics.warning( |
1403 | 1404 | 'unused-command-line-argument', |
1433 | 1434 | if settings.USE_PTHREADS and '-pthread' not in newargs: |
1434 | 1435 | newargs += ['-pthread'] |
1435 | 1436 | |
1436 | if 'DISABLE_EXCEPTION_CATCHING' in settings_map and 'EXCEPTION_CATCHING_ALLOWED' in settings_map: | |
1437 | if 'DISABLE_EXCEPTION_CATCHING' in user_settings and 'EXCEPTION_CATCHING_ALLOWED' in user_settings: | |
1437 | 1438 | # If we get here then the user specified both DISABLE_EXCEPTION_CATCHING and EXCEPTION_CATCHING_ALLOWED |
1438 | 1439 | # on the command line. This is no longer valid so report either an error or a warning (for |
1439 | 1440 | # backwards compat with the old `DISABLE_EXCEPTION_CATCHING=2` |
1440 | if settings_map['DISABLE_EXCEPTION_CATCHING'] in ('0', '2'): | |
1441 | if user_settings['DISABLE_EXCEPTION_CATCHING'] in ('0', '2'): | |
1441 | 1442 | diagnostics.warning('deprecated', 'DISABLE_EXCEPTION_CATCHING=X is no longer needed when specifying EXCEPTION_CATCHING_ALLOWED') |
1442 | 1443 | else: |
1443 | 1444 | exit_with_error('DISABLE_EXCEPTION_CATCHING and EXCEPTION_CATCHING_ALLOWED are mutually exclusive') |
1459 | 1460 | # Wasm SjLj cannot be used with Emscripten EH. We error out if |
1460 | 1461 | # DISABLE_EXCEPTION_THROWING=0 is explicitly requested by the user; |
1461 | 1462 | # otherwise we disable it here. |
1462 | default_setting('DISABLE_EXCEPTION_THROWING', 1) | |
1463 | default_setting(user_settings, 'DISABLE_EXCEPTION_THROWING', 1) | |
1463 | 1464 | if not settings.DISABLE_EXCEPTION_THROWING: |
1464 | 1465 | exit_with_error('SUPPORT_LONGJMP=wasm cannot be used with DISABLE_EXCEPTION_CATCHING=0') |
1465 | 1466 | # We error out for DISABLE_EXCEPTION_CATCHING=0, because it is 1 by default |
1471 | 1472 | |
1472 | 1473 | |
1473 | 1474 | @ToolchainProfiler.profile_block('linker_setup') |
1474 | def phase_linker_setup(options, state, newargs, settings_map): | |
1475 | def phase_linker_setup(options, state, newargs, user_settings): | |
1475 | 1476 | autoconf = os.environ.get('EMMAKEN_JUST_CONFIGURE') or 'conftest.c' in state.orig_args |
1476 | 1477 | if autoconf: |
1477 | 1478 | # configure tests want a more shell-like style, where we emit return codes on exit() |
1485 | 1486 | for f in ldflags: |
1486 | 1487 | add_link_flag(state, sys.maxsize, f) |
1487 | 1488 | |
1488 | def default_setting(name, new_default): | |
1489 | if name not in settings_map: | |
1490 | setattr(settings, name, new_default) | |
1491 | ||
1492 | 1489 | if settings.OPT_LEVEL >= 1: |
1493 | default_setting('ASSERTIONS', 0) | |
1490 | default_setting(user_settings, 'ASSERTIONS', 0) | |
1494 | 1491 | |
1495 | 1492 | if options.emrun: |
1496 | 1493 | options.pre_js.append(utils.path_from_root('src/emrun_prejs.js')) |
1626 | 1623 | # reactor. |
1627 | 1624 | # 2. If the user doesn't export anything we default to exporting `_main` (unless `--no-entry` |
1628 | 1625 | # is specified (see above). |
1629 | if 'EXPORTED_FUNCTIONS' in settings_map: | |
1626 | if 'EXPORTED_FUNCTIONS' in user_settings: | |
1630 | 1627 | if '_main' not in settings.USER_EXPORTED_FUNCTIONS: |
1631 | 1628 | settings.EXPECT_MAIN = 0 |
1632 | 1629 | else: |
1638 | 1635 | # See https://github.com/WebAssembly/WASI/blob/main/design/application-abi.md |
1639 | 1636 | # For a command we always want EXIT_RUNTIME=1 |
1640 | 1637 | # For a reactor we always want EXIT_RUNTIME=0 |
1641 | if 'EXIT_RUNTIME' in settings_map: | |
1638 | if 'EXIT_RUNTIME' in user_settings: | |
1642 | 1639 | exit_with_error('Explictly setting EXIT_RUNTIME not compatible with STANDALONE_WASM. EXIT_RUNTIME will always be True for programs (with a main function) and False for reactors (not main function).') |
1643 | 1640 | settings.EXIT_RUNTIME = settings.EXPECT_MAIN |
1644 | 1641 | |
1652 | 1649 | # libraries because STACK_OVERFLOW_CHECK depends on emscripten_stack_get_end which is defined |
1653 | 1650 | # in libcompiler-rt. |
1654 | 1651 | if not settings.PURE_WASI and '-nostdlib' not in newargs and '-nodefaultlibs' not in newargs: |
1655 | default_setting('STACK_OVERFLOW_CHECK', max(settings.ASSERTIONS, settings.STACK_OVERFLOW_CHECK)) | |
1652 | default_setting(user_settings, 'STACK_OVERFLOW_CHECK', max(settings.ASSERTIONS, settings.STACK_OVERFLOW_CHECK)) | |
1656 | 1653 | |
1657 | 1654 | if settings.LLD_REPORT_UNDEFINED or settings.STANDALONE_WASM: |
1658 | 1655 | # Reporting undefined symbols at wasm-ld time requires us to know if we have a `main` function |
1662 | 1659 | |
1663 | 1660 | # For users that opt out of WARN_ON_UNDEFINED_SYMBOLS we assume they also |
1664 | 1661 | # want to opt out of ERROR_ON_UNDEFINED_SYMBOLS. |
1665 | if settings_map.get('WARN_ON_UNDEFINED_SYMBOLS') == '0': | |
1666 | default_setting('ERROR_ON_UNDEFINED_SYMBOLS', 0) | |
1662 | if user_settings.get('WARN_ON_UNDEFINED_SYMBOLS') == '0': | |
1663 | default_setting(user_settings, 'ERROR_ON_UNDEFINED_SYMBOLS', 0) | |
1667 | 1664 | |
1668 | 1665 | # It is unlikely that developers targeting "native web" APIs with MINIMAL_RUNTIME need |
1669 | 1666 | # errno support by default. |
1670 | 1667 | if settings.MINIMAL_RUNTIME: |
1671 | default_setting('SUPPORT_ERRNO', 0) | |
1668 | default_setting(user_settings, 'SUPPORT_ERRNO', 0) | |
1672 | 1669 | # Require explicit -lfoo.js flags to link with JS libraries. |
1673 | default_setting('AUTO_JS_LIBRARIES', 0) | |
1670 | default_setting(user_settings, 'AUTO_JS_LIBRARIES', 0) | |
1674 | 1671 | |
1675 | 1672 | if settings.STRICT: |
1676 | default_setting('STRICT_JS', 1) | |
1677 | default_setting('AUTO_JS_LIBRARIES', 0) | |
1678 | default_setting('AUTO_NATIVE_LIBRARIES', 0) | |
1679 | default_setting('AUTO_ARCHIVE_INDEXES', 0) | |
1680 | default_setting('IGNORE_MISSING_MAIN', 0) | |
1681 | default_setting('ALLOW_UNIMPLEMENTED_SYSCALLS', 0) | |
1673 | default_setting(user_settings, 'STRICT_JS', 1) | |
1674 | default_setting(user_settings, 'AUTO_JS_LIBRARIES', 0) | |
1675 | default_setting(user_settings, 'AUTO_NATIVE_LIBRARIES', 0) | |
1676 | default_setting(user_settings, 'AUTO_ARCHIVE_INDEXES', 0) | |
1677 | default_setting(user_settings, 'IGNORE_MISSING_MAIN', 0) | |
1678 | default_setting(user_settings, 'ALLOW_UNIMPLEMENTED_SYSCALLS', 0) | |
1682 | 1679 | |
1683 | 1680 | if not settings.AUTO_JS_LIBRARIES: |
1684 | default_setting('USE_SDL', 0) | |
1681 | default_setting(user_settings, 'USE_SDL', 0) | |
1685 | 1682 | |
1686 | 1683 | # Default to TEXTDECODER=2 (always use TextDecoder to decode UTF-8 strings) |
1687 | 1684 | # in -Oz builds, since custom decoder for UTF-8 takes up space. |
1691 | 1688 | # widely supported there. |
1692 | 1689 | if settings.SHRINK_LEVEL >= 2 and not settings.USE_PTHREADS and \ |
1693 | 1690 | not settings.ENVIRONMENT_MAY_BE_SHELL: |
1694 | default_setting('TEXTDECODER', 2) | |
1691 | default_setting(user_settings, 'TEXTDECODER', 2) | |
1695 | 1692 | |
1696 | 1693 | # If set to 1, we will run the autodebugger (the automatic debugging tool, see |
1697 | 1694 | # tools/autodebugger). Note that this will disable inclusion of libraries. This |
1745 | 1742 | # If we are including the entire JS library then we know for sure we will, by definition, |
1746 | 1743 | # require all the reverse dependencies. |
1747 | 1744 | if settings.INCLUDE_FULL_LIBRARY: |
1748 | default_setting('REVERSE_DEPS', 'all') | |
1745 | default_setting(user_settings, 'REVERSE_DEPS', 'all') | |
1749 | 1746 | |
1750 | 1747 | if settings.MAIN_MODULE == 1 or settings.SIDE_MODULE == 1: |
1751 | 1748 | settings.LINKABLE = 1 |
1910 | 1907 | |
1911 | 1908 | # MIN_WEBGL_VERSION=2 implies MAX_WEBGL_VERSION=2 |
1912 | 1909 | if settings.MIN_WEBGL_VERSION == 2: |
1913 | default_setting('MAX_WEBGL_VERSION', 2) | |
1910 | default_setting(user_settings, 'MAX_WEBGL_VERSION', 2) | |
1914 | 1911 | |
1915 | 1912 | if settings.MIN_WEBGL_VERSION > settings.MAX_WEBGL_VERSION: |
1916 | 1913 | exit_with_error('MIN_WEBGL_VERSION must be smaller or equal to MAX_WEBGL_VERSION!') |
1969 | 1966 | if settings.RELOCATABLE and not settings.DYNAMIC_EXECUTION: |
1970 | 1967 | exit_with_error('cannot have both DYNAMIC_EXECUTION=0 and RELOCATABLE enabled at the same time, since RELOCATABLE needs to eval()') |
1971 | 1968 | |
1972 | if settings.SIDE_MODULE and 'GLOBAL_BASE' in settings_map: | |
1969 | if settings.SIDE_MODULE and 'GLOBAL_BASE' in user_settings: | |
1973 | 1970 | exit_with_error('Cannot set GLOBAL_BASE when building SIDE_MODULE') |
1974 | 1971 | |
1975 | 1972 | # When building a side module we currently have to assume that any undefined |
1976 | 1973 | # symbols that exist at link time will be satisfied by the main module or JS. |
1977 | 1974 | if settings.SIDE_MODULE: |
1978 | default_setting('ERROR_ON_UNDEFINED_SYMBOLS', 0) | |
1979 | default_setting('WARN_ON_UNDEFINED_SYMBOLS', 0) | |
1975 | default_setting(user_settings, 'ERROR_ON_UNDEFINED_SYMBOLS', 0) | |
1976 | default_setting(user_settings, 'WARN_ON_UNDEFINED_SYMBOLS', 0) | |
1980 | 1977 | |
1981 | 1978 | if options.use_preload_plugins or len(options.preload_files) or len(options.embed_files): |
1982 | 1979 | if settings.NODERAWFS: |
2028 | 2025 | # the behavior of trying to grow and returning 0 from malloc on failure, like |
2029 | 2026 | # a standard system would. However, if the user sets the flag it |
2030 | 2027 | # overrides that. |
2031 | default_setting('ABORTING_MALLOC', 0) | |
2028 | default_setting(user_settings, 'ABORTING_MALLOC', 0) | |
2032 | 2029 | |
2033 | 2030 | if settings.USE_PTHREADS: |
2034 | 2031 | if settings.USE_PTHREADS == 2: |
2160 | 2157 | if settings.MEMORY_GROWTH_LINEAR_STEP != -1: |
2161 | 2158 | check_memory_setting('MEMORY_GROWTH_LINEAR_STEP') |
2162 | 2159 | |
2163 | if 'MAXIMUM_MEMORY' in settings_map and not settings.ALLOW_MEMORY_GROWTH: | |
2160 | if 'MAXIMUM_MEMORY' in user_settings and not settings.ALLOW_MEMORY_GROWTH: | |
2164 | 2161 | diagnostics.warning('unused-command-line-argument', 'MAXIMUM_MEMORY is only meaningful with ALLOW_MEMORY_GROWTH') |
2165 | 2162 | |
2166 | 2163 | if settings.EXPORT_ES6 and not settings.MODULARIZE: |
2167 | 2164 | # EXPORT_ES6 requires output to be a module |
2168 | if 'MODULARIZE' in settings_map: | |
2165 | if 'MODULARIZE' in user_settings: | |
2169 | 2166 | exit_with_error('EXPORT_ES6 requires MODULARIZE to be set') |
2170 | 2167 | settings.MODULARIZE = 1 |
2171 | 2168 | |
2253 | 2250 | if options.use_closure_compiler == 2 and not settings.WASM2JS: |
2254 | 2251 | exit_with_error('closure compiler mode 2 assumes the code is asm.js, so not meaningful for wasm') |
2255 | 2252 | |
2256 | if 'MEM_INIT_METHOD' in settings_map: | |
2253 | if 'MEM_INIT_METHOD' in user_settings: | |
2257 | 2254 | exit_with_error('MEM_INIT_METHOD is not supported in wasm. Memory will be embedded in the wasm binary if threads are not used, and included in a separate file if threads are used.') |
2258 | 2255 | |
2259 | 2256 | if settings.WASM2JS: |
2315 | 2312 | |
2316 | 2313 | if 'leak' in sanitize: |
2317 | 2314 | settings.USE_LSAN = 1 |
2318 | default_setting('EXIT_RUNTIME', 1) | |
2315 | default_setting(user_settings, 'EXIT_RUNTIME', 1) | |
2319 | 2316 | |
2320 | 2317 | if settings.RELOCATABLE: |
2321 | 2318 | exit_with_error('LSan does not support dynamic linking') |
2322 | 2319 | |
2323 | 2320 | if 'address' in sanitize: |
2324 | 2321 | settings.USE_ASAN = 1 |
2325 | default_setting('EXIT_RUNTIME', 1) | |
2322 | default_setting(user_settings, 'EXIT_RUNTIME', 1) | |
2326 | 2323 | if not settings.UBSAN_RUNTIME: |
2327 | 2324 | settings.UBSAN_RUNTIME = 2 |
2328 | 2325 | |
2357 | 2354 | if settings.ASAN_SHADOW_SIZE != -1: |
2358 | 2355 | diagnostics.warning('emcc', 'ASAN_SHADOW_SIZE is ignored and will be removed in a future release') |
2359 | 2356 | |
2360 | if 'GLOBAL_BASE' in settings_map: | |
2357 | if 'GLOBAL_BASE' in user_settings: | |
2361 | 2358 | exit_with_error("ASan does not support custom GLOBAL_BASE") |
2362 | 2359 | |
2363 | 2360 | # Increase the TOTAL_MEMORY and shift GLOBAL_BASE to account for |
2503 | 2500 | # Any "pointers" passed to JS will now be i64's, in both modes. |
2504 | 2501 | # Also turn off minifying, which clashes with instrumented functions in preamble.js |
2505 | 2502 | if settings.MEMORY64: |
2506 | if settings_map.get('WASM_BIGINT') == '0': | |
2503 | if user_settings.get('WASM_BIGINT') == '0': | |
2507 | 2504 | exit_with_error('MEMORY64 is not compatible with WASM_BIGINT=0') |
2508 | 2505 | settings.WASM_BIGINT = 1 |
2509 | 2506 | settings.MINIFY_WASM_IMPORTS_AND_EXPORTS = 0 |