@@ -879,14 +879,6 @@ def phase_linker_setup(options, state, newargs):
879
879
else :
880
880
default_setting ('INCOMING_MODULE_JS_API' , [])
881
881
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
-
890
882
# Default to TEXTDECODER=2 (always use TextDecoder to decode UTF-8 strings)
891
883
# in -Oz builds, since custom decoder for UTF-8 takes up space.
892
884
# In pthreads enabled builds, TEXTDECODER==2 may not work, see
@@ -1592,7 +1584,6 @@ def check_memory_setting(setting):
1592
1584
# We start our global data after the shadow memory.
1593
1585
# We don't need to worry about alignment here. wasm-ld will take care of that.
1594
1586
settings .GLOBAL_BASE = shadow_size
1595
- settings .STACK_FIRST = False
1596
1587
1597
1588
if not settings .ALLOW_MEMORY_GROWTH :
1598
1589
settings .INITIAL_MEMORY = total_mem
@@ -1615,6 +1606,21 @@ def check_memory_setting(setting):
1615
1606
if sanitize and settings .GENERATE_SOURCE_MAP :
1616
1607
settings .LOAD_SOURCE_MAP = 1
1617
1608
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
+
1618
1624
set_max_memory ()
1619
1625
1620
1626
# check if we can address the 2GB mark and higher.
0 commit comments