Skip to content

Commit

Permalink
script.ld/Makefile: Use the maximum ram size available for the stack
Browse files Browse the repository at this point in the history
  • Loading branch information
Xavier Chapron committed Nov 7, 2023
1 parent e54fb1b commit 5da7897
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 21 deletions.
9 changes: 8 additions & 1 deletion Makefile.rules_generic
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,14 @@ debug/app.map debug/app.asm: debug/app.%: $(DBG_DIR)/app.%
# link_cmdline(objects,dest) Macro that is used to format arguments for the linker
link_cmdline = $(LD) $(LDFLAGS) -o $(2) $(1)
ifneq ($(APP_STACK_SIZE),)
link_cmdline += -Wl,--defsym=stack_size=$(APP_STACK_SIZE)
ifneq ($(ENABLE_SDK_WERROR),0)
$(error Deprecated APP_STACK_SIZE define, use APP_STACK_MIN_SIZE if really needed)
else
$(info Deprecated APP_STACK_SIZE define, use APP_STACK_MIN_SIZE if really needed)
endif
endif
ifneq ($(APP_STACK_MIN_SIZE),)
link_cmdline += -Wl,--defsym=stack_min_size=$(APP_STACK_MIN_SIZE)
endif

# cc_cmdline(include,defines,src,dest) Macro that is used to format arguments for the compiler
Expand Down
9 changes: 4 additions & 5 deletions target/nanos/script.ld
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ MEMORY
}

PAGE_SIZE = 64;
STACK_SIZE = DEFINED(stack_size) ? stack_size : 1024;
STACK_MIN_SIZE = DEFINED(stack_min_size) ? stack_min_size : 1024;
END_STACK = ORIGIN(SRAM) + LENGTH(SRAM);

/*
Expand Down Expand Up @@ -125,15 +125,14 @@ SECTIONS
app_stack_canary = .;
PROVIDE(app_stack_canary = .);
. += 4;
_stack_validation = .;
. = _stack_validation + STACK_SIZE;
_stack = ABSOLUTE(END_STACK) - STACK_SIZE;
PROVIDE( _stack = ABSOLUTE(END_STACK) - STACK_SIZE);
_stack = .;
PROVIDE( _stack = .);
_estack = ABSOLUTE(END_STACK);
PROVIDE( _estack = ABSOLUTE(END_STACK) );

} > SRAM = 0x00

ASSERT( (_estack - _stack) >= STACK_MIN_SIZE, "stack section too small" )


/****************************************************************/
Expand Down
10 changes: 5 additions & 5 deletions target/nanos2/script.ld
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ MEMORY
}

PAGE_SIZE = 512;
STACK_SIZE = 1500;
STACK_MIN_SIZE = DEFINED(stack_min_size) ? stack_min_size : 1500;
END_STACK = ORIGIN(SRAM) + LENGTH(SRAM);

ENTRY(main);
Expand Down Expand Up @@ -113,15 +113,15 @@ SECTIONS
app_stack_canary = .;
PROVIDE(app_stack_canary = .);
. += 4;
_stack_validation = .;
. = _stack_validation + STACK_SIZE;
_stack = ABSOLUTE(END_STACK) - STACK_SIZE;
PROVIDE( _stack = ABSOLUTE(END_STACK) - STACK_SIZE);
_stack = .;
PROVIDE( _stack = .);
_estack = ABSOLUTE(END_STACK);
PROVIDE( _estack = ABSOLUTE(END_STACK) );

} > SRAM = 0x00

ASSERT( (_estack - _stack) >= STACK_MIN_SIZE, "stack section too small" )

/****************************************************************/
/* DEBUG */
/****************************************************************/
Expand Down
10 changes: 5 additions & 5 deletions target/nanox/script.ld
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ MEMORY
}

PAGE_SIZE = 256;
STACK_SIZE = 1500;
STACK_MIN_SIZE = DEFINED(stack_min_size) ? stack_min_size : 1500;
END_STACK = ORIGIN(SRAM) + LENGTH(SRAM);

ENTRY(main);
Expand Down Expand Up @@ -124,15 +124,15 @@ SECTIONS
app_stack_canary = .;
PROVIDE(app_stack_canary = .);
. += 4;
_stack_validation = .;
. = _stack_validation + STACK_SIZE;
_stack = ABSOLUTE(END_STACK) - STACK_SIZE;
PROVIDE( _stack = ABSOLUTE(END_STACK) - STACK_SIZE);
_stack = .;
PROVIDE( _stack = .);
_estack = ABSOLUTE(END_STACK);
PROVIDE( _estack = ABSOLUTE(END_STACK) );

} > SRAM

ASSERT( (_estack - _stack) >= STACK_MIN_SIZE, "stack section too small" )

/****************************************************************/
/* DEBUG */
/****************************************************************/
Expand Down
10 changes: 5 additions & 5 deletions target/stax/script.ld
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ MEMORY
}

PAGE_SIZE = 512;
STACK_SIZE = 1500;
STACK_MIN_SIZE = DEFINED(stack_min_size) ? stack_min_size : 1500;
END_STACK = ORIGIN(SRAM) + LENGTH(SRAM);

ENTRY(main);
Expand Down Expand Up @@ -114,15 +114,15 @@ SECTIONS
app_stack_canary = .;
PROVIDE(app_stack_canary = .);
. += 4;
_stack_validation = .;
. = _stack_validation + STACK_SIZE;
_stack = ABSOLUTE(END_STACK) - STACK_SIZE;
PROVIDE( _stack = ABSOLUTE(END_STACK) - STACK_SIZE);
_stack = .;
PROVIDE( _stack = .);
_estack = ABSOLUTE(END_STACK);
PROVIDE( _estack = ABSOLUTE(END_STACK) );

} > SRAM = 0x00

ASSERT( (_estack - _stack) >= STACK_MIN_SIZE, "stack section too small" )

/****************************************************************/
/* DEBUG */
/****************************************************************/
Expand Down

0 comments on commit 5da7897

Please sign in to comment.