@@ -879,14 +879,6 @@ def phase_linker_setup(options, state, newargs):
879879 else :
880880 default_setting ('INCOMING_MODULE_JS_API' , [])
881881
882- if 'GLOBAL_BASE' not in user_settings and not settings .SHRINK_LEVEL and not settings .OPT_LEVEL :
883- # When optimizing for size it helps to put static data first before
884- # the stack (since this makes instructions for accessing this data
885- # use a smaller LEB encoding).
886- # However, for debugability is better to have the stack come first
887- # (because stack overflows will trap rather than corrupting data).
888- settings .STACK_FIRST = True
889-
890882 # Default to TEXTDECODER=2 (always use TextDecoder to decode UTF-8 strings)
891883 # in -Oz builds, since custom decoder for UTF-8 takes up space.
892884 # In pthreads enabled builds, TEXTDECODER==2 may not work, see
@@ -1592,7 +1584,6 @@ def check_memory_setting(setting):
15921584 # We start our global data after the shadow memory.
15931585 # We don't need to worry about alignment here. wasm-ld will take care of that.
15941586 settings .GLOBAL_BASE = shadow_size
1595- settings .STACK_FIRST = False
15961587
15971588 if not settings .ALLOW_MEMORY_GROWTH :
15981589 settings .INITIAL_MEMORY = total_mem
@@ -1615,6 +1606,21 @@ def check_memory_setting(setting):
16151606 if sanitize and settings .GENERATE_SOURCE_MAP :
16161607 settings .LOAD_SOURCE_MAP = 1
16171608
1609+ if 'GLOBAL_BASE' not in user_settings and not settings .SHRINK_LEVEL and not settings .OPT_LEVEL and not settings .USE_ASAN :
1610+ # When optimizing for size it helps to put static data first before
1611+ # the stack (since this makes instructions for accessing this data
1612+ # use a smaller LEB encoding).
1613+ # However, for debugability is better to have the stack come first
1614+ # (because stack overflows will trap rather than corrupting data).
1615+ settings .STACK_FIRST = True
1616+
1617+ if '--stack-first' in [x for _ , x in state .link_flags ]:
1618+ settings .STACK_FIRST = True
1619+ if settings .USE_ASAN :
1620+ exit_with_error ('--stack-first is not compatible with asan' )
1621+ if 'GLOBAL_BASE' in user_settings :
1622+ exit_with_error ('--stack-first is not compatible with -sGLOBAL_BASE' )
1623+
16181624 set_max_memory ()
16191625
16201626 # check if we can address the 2GB mark and higher.
0 commit comments