[lld] e29ee27 - [lld][WebAssembly] Allow `--no-stack-first` in addition to `--stack-first` (#166384)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 4 10:40:51 PST 2025
Author: Sam Clegg
Date: 2025-11-04T18:40:46Z
New Revision: e29ee270615f3c8e3c9a0a657c0be43f9d76f441
URL: https://github.com/llvm/llvm-project/commit/e29ee270615f3c8e3c9a0a657c0be43f9d76f441
DIFF: https://github.com/llvm/llvm-project/commit/e29ee270615f3c8e3c9a0a657c0be43f9d76f441.diff
LOG: [lld][WebAssembly] Allow `--no-stack-first` in addition to `--stack-first` (#166384)
This paves the way to make `--stack-first` the default.
See: #151015
Added:
Modified:
lld/test/wasm/stack-first.test
lld/wasm/Driver.cpp
lld/wasm/Options.td
Removed:
################################################################################
diff --git a/lld/test/wasm/stack-first.test b/lld/test/wasm/stack-first.test
index 72e1a006d5700..46e8c6ebc2381 100644
--- a/lld/test/wasm/stack-first.test
+++ b/lld/test/wasm/stack-first.test
@@ -8,6 +8,15 @@ RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown %p/Inputs/stack-first.
RUN: wasm-ld -z stack-size=512 --stack-first --export=__data_end --export=__heap_base --export=someByte -o %t.wasm %t.o
RUN: obj2yaml %t.wasm | FileCheck %s
+; Check `--no-stack-first`
+RUN: wasm-ld -z stack-size=512 --stack-first --no-stack-first --export=__data_end --export=__heap_base --export=someByte -o %t.wasm %t.o
+RUN: obj2yaml %t.wasm | FileCheck %s --check-prefix=NOT-FIRST
+
+; Check that the default is no-stack-first
+RUN: wasm-ld -z stack-size=512 --export=__data_end --export=__heap_base --export=someByte -o %t.wasm %t.o
+RUN: obj2yaml %t.wasm | FileCheck %s --check-prefix=NOT-FIRST
+
+
CHECK: - Type: GLOBAL
CHECK-NEXT: Globals:
CHECK-NEXT: - Index: 0
@@ -51,3 +60,19 @@ CHECK-NEXT: Index: 2
CHECK-NEXT: - Name: __heap_base
CHECK-NEXT: Kind: GLOBAL
CHECK-NEXT: Index: 3
+
+NOT-FIRST: - Type: GLOBAL
+NOT-FIRST-NEXT: Globals:
+NOT-FIRST-NEXT: - Index: 0
+NOT-FIRST-NEXT: Type: I32
+NOT-FIRST-NEXT: Mutable: true
+NOT-FIRST-NEXT: InitExpr:
+NOT-FIRST-NEXT: Opcode: I32_CONST
+NOT-FIRST-NEXT: Value: 1552
+NOT-FIRST-NEXT: - Index: 1
+NOT-FIRST-NEXT: Type: I32
+NOT-FIRST-NEXT: Mutable: false
+NOT-FIRST-NEXT: InitExpr:
+NOT-FIRST-NEXT: Opcode: I32_CONST
+NOT-FIRST-NEXT: Value: 1024
+
diff --git a/lld/wasm/Driver.cpp b/lld/wasm/Driver.cpp
index 9c0e1b58e62f9..aad8095881bba 100644
--- a/lld/wasm/Driver.cpp
+++ b/lld/wasm/Driver.cpp
@@ -595,7 +595,7 @@ static void readConfigs(opt::InputArgList &args) {
ctx.arg.shlibSigCheck = !args.hasArg(OPT_no_shlib_sigcheck);
ctx.arg.stripAll = args.hasArg(OPT_strip_all);
ctx.arg.stripDebug = args.hasArg(OPT_strip_debug);
- ctx.arg.stackFirst = args.hasArg(OPT_stack_first);
+ ctx.arg.stackFirst = args.hasFlag(OPT_stack_first, OPT_no_stack_first, false);
ctx.arg.trace = args.hasArg(OPT_trace);
ctx.arg.thinLTOCacheDir = args.getLastArgValue(OPT_thinlto_cache_dir);
ctx.arg.thinLTOCachePolicy = CHECK(
diff --git a/lld/wasm/Options.td b/lld/wasm/Options.td
index 2f699e2f68350..0ed69258d99aa 100644
--- a/lld/wasm/Options.td
+++ b/lld/wasm/Options.td
@@ -250,8 +250,9 @@ def no_entry: FF<"no-entry">,
def no_shlib_sigcheck: FF<"no-shlib-sigcheck">,
HelpText<"Do not check signatures of functions defined in shared libraries.">;
-def stack_first: FF<"stack-first">,
- HelpText<"Place stack at start of linear memory rather than after data">;
+defm stack_first: B<"stack-first",
+ "Place stack at start of linear memory",
+ "Place the stack after static data refion (default)">;
def table_base: JJ<"table-base=">,
HelpText<"Table offset at which to place address taken functions (Defaults to 1)">;
More information about the llvm-commits
mailing list