@@ -1814,6 +1814,14 @@ def phase_linker_setup(options, state, newargs):
18141814 if not settings .AUTO_JS_LIBRARIES :
18151815 default_setting ('USE_SDL' , 0 )
18161816
1817+ if 'GLOBAL_BASE' not in user_settings and not settings .SHRINK_LEVEL and not settings .OPT_LEVEL :
1818+ # When optimizing for size it helps to put static data first before
1819+ # the stack (sincs this makes instructions for accessing this data
1820+ # use a smaller LEB encoding).
1821+ # However, for debugability is better to have the stack come first
1822+ # (becuase stack overflows will trap rather than corrupting data).
1823+ settings .STACK_FIRST = True
1824+
18171825 # Default to TEXTDECODER=2 (always use TextDecoder to decode UTF-8 strings)
18181826 # in -Oz builds, since custom decoder for UTF-8 takes up space.
18191827 # In pthreads enabled builds, TEXTDECODER==2 may not work, see
@@ -2150,7 +2158,7 @@ def phase_linker_setup(options, state, newargs):
21502158 exit_with_error ('cannot have both DYNAMIC_EXECUTION=0 and RELOCATABLE enabled at the same time, since RELOCATABLE needs to eval()' )
21512159
21522160 if settings .SIDE_MODULE and 'GLOBAL_BASE' in user_settings :
2153- exit_with_error ('Cannot set GLOBAL_BASE when building SIDE_MODULE' )
2161+ exit_with_error ('GLOBAL_BASE is not compatible with SIDE_MODULE' )
21542162
21552163 if options .use_preload_plugins or len (options .preload_files ) or len (options .embed_files ):
21562164 if settings .NODERAWFS :
@@ -2498,6 +2506,7 @@ def check_memory_setting(setting):
24982506 # We start our global data after the shadow memory.
24992507 # We don't need to worry about alignment here. wasm-ld will take care of that.
25002508 settings .GLOBAL_BASE = shadow_size
2509+ settings .STACK_FIRST = False
25012510
25022511 if not settings .ALLOW_MEMORY_GROWTH :
25032512 settings .INITIAL_MEMORY = total_mem
0 commit comments