@@ -1778,6 +1778,22 @@ def include_and_export(name):
1778
1778
settings .EXPORTED_RUNTIME_METHODS += ['ExitStatus' ]
1779
1779
1780
1780
1781
+ def set_max_memory ():
1782
+ # When memory growth is disallowed set MAXIMUM_MEMORY equal to INITIAL_MEMORY
1783
+ if not settings .ALLOW_MEMORY_GROWTH :
1784
+ if 'MAXIMUM_MEMORY' in user_settings :
1785
+ diagnostics .warning ('unused-command-line-argument' , 'MAXIMUM_MEMORY is only meaningful with ALLOW_MEMORY_GROWTH' )
1786
+ settings .MAXIMUM_MEMORY = settings .INITIAL_MEMORY
1787
+
1788
+ # INITIAL_MEMORY sets a lower bound for MAXIMUM_MEMORY
1789
+ if 'MAXIMUM_MEMORY' not in user_settings :
1790
+ if settings .INITIAL_MEMORY > settings .MAXIMUM_MEMORY :
1791
+ settings .MAXIMUM_MEMORY = settings .INITIAL_MEMORY
1792
+
1793
+ if settings .MAXIMUM_MEMORY < settings .INITIAL_MEMORY :
1794
+ exit_with_error ('MAXIMUM_MEMORY cannot be less than INITIAL_MEMORY' )
1795
+
1796
+
1781
1797
@ToolchainProfiler .profile_block ('linker_setup' )
1782
1798
def phase_linker_setup (options , state , newargs ):
1783
1799
autoconf = os .environ .get ('EMMAKEN_JUST_CONFIGURE' ) or 'conftest.c' in state .orig_args or 'conftest.cpp' in state .orig_args
@@ -2522,12 +2538,6 @@ def check_memory_setting(setting):
2522
2538
if settings .MEMORY_GROWTH_LINEAR_STEP != - 1 :
2523
2539
check_memory_setting ('MEMORY_GROWTH_LINEAR_STEP' )
2524
2540
2525
- if settings .ALLOW_MEMORY_GROWTH and settings .MAXIMUM_MEMORY < settings .INITIAL_MEMORY :
2526
- exit_with_error ('MAXIMUM_MEMORY must be larger then INITIAL_MEMORY' )
2527
-
2528
- if 'MAXIMUM_MEMORY' in user_settings and not settings .ALLOW_MEMORY_GROWTH :
2529
- diagnostics .warning ('unused-command-line-argument' , 'MAXIMUM_MEMORY is only meaningful with ALLOW_MEMORY_GROWTH' )
2530
-
2531
2541
if settings .EXPORT_ES6 :
2532
2542
if not settings .MODULARIZE :
2533
2543
# EXPORT_ES6 requires output to be a module
@@ -2774,6 +2784,12 @@ def check_memory_setting(setting):
2774
2784
if sanitize and settings .GENERATE_SOURCE_MAP :
2775
2785
settings .LOAD_SOURCE_MAP = 1
2776
2786
2787
+ set_max_memory ()
2788
+
2789
+ # check if we can address the 2GB mark and higher.
2790
+ if not settings .MEMORY64 and settings .MAXIMUM_MEMORY > 2 * 1024 * 1024 * 1024 :
2791
+ settings .CAN_ADDRESS_2GB = 1
2792
+
2777
2793
if settings .MINIMAL_RUNTIME :
2778
2794
if settings .EXIT_RUNTIME :
2779
2795
settings .DEFAULT_LIBRARY_FUNCS_TO_INCLUDE += ['proc_exit' , '$callRuntimeCallbacks' ]
@@ -2874,14 +2890,6 @@ def get_full_import_name(name):
2874
2890
'emscripten_stack_get_base' ,
2875
2891
'emscripten_stack_get_end' ]
2876
2892
2877
- # check if we can address the 2GB mark and higher: either if we start at
2878
- # 2GB, or if we allow growth to either any amount or to 2GB or more.
2879
- if not settings .MEMORY64 and (settings .INITIAL_MEMORY > 2 * 1024 * 1024 * 1024 or
2880
- (settings .ALLOW_MEMORY_GROWTH and
2881
- (settings .MAXIMUM_MEMORY < 0 or
2882
- settings .MAXIMUM_MEMORY > 2 * 1024 * 1024 * 1024 ))):
2883
- settings .CAN_ADDRESS_2GB = 1
2884
-
2885
2893
settings .EMSCRIPTEN_VERSION = shared .EMSCRIPTEN_VERSION
2886
2894
settings .SOURCE_MAP_BASE = options .source_map_base or ''
2887
2895
0 commit comments