Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions lld/test/wasm/stack-first.test
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

2 changes: 1 addition & 1 deletion lld/wasm/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
5 changes: 3 additions & 2 deletions lld/wasm/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -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)">;
Copy link

@bakkot bakkot Nov 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"Place the stack after static data refion (default)">;
"Place the stack after static data region (default)">;

(I assume)


def table_base: JJ<"table-base=">,
HelpText<"Table offset at which to place address taken functions (Defaults to 1)">;
Expand Down