# Freedom Studio Qemu stack limit for function local array

**URL:** <https://forums.sifive.com/t/freedom-studio-qemu-stack-limit-for-function-local-array/5436>\
**Category:** HiFive Unmatched\
**Created:** [November 19, 2021, 8:35pm UTC](https://forums.sifive.com/t/freedom-studio-qemu-stack-limit-for-function-local-array/5436 "2021-11-19T20:35:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![abirtz](https://avatars.discourse-cdn.com/v4/letter/a/71e660/32.png) [@abirtz](https://forums.sifive.com/u/abirtz)\
**Post date:** [November 19, 2021, 8:35pm UTC](https://forums.sifive.com/t/freedom-studio-qemu-stack-limit-for-function-local-array/5436/1 "2021-11-19T20:35:56Z")

</div>

1. The function use a local array. When the size of the array increase  
Freedom Studio (Qemu wlthout board) crash. If I use the same array as global  
every thing work fine. What is the Freedom Studio stack limit for local variables ?  
The same code (with local array) work correctly using gcc on SiFive board.

2. Any way to remove the break point at the first instruction of main() in Freedom Studio Qemu ?

---

<div class="post-metadata">

**Author:** ![kevin](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.sifive.com/kevin/32/1140_2.png) [@kevin](https://forums.sifive.com/u/kevin)\
**Post date:** [November 19, 2021, 10:06pm UTC](https://forums.sifive.com/t/freedom-studio-qemu-stack-limit-for-function-local-array/5436/2 "2021-11-19T22:06:03Z")

</div>

Hi Alain,

Regarding #1: Stack Size. Try editing the bps/metal.default.lds file (that is the default linker script used to build the ELF, if you are using a different one, you’ll want to edit it instead, or as well). The stack size is defined by the `_stack_size` variable. In the QEMU BSP this defaults to 0x400 (1024) bytes. I see the Unmatched BSP defaults to 0x800 (2048) bytes. Change the QEMU linker script to match, rebuild, and you should be good to go.

Regarding #2: Look at the Debug Configuration Dialog for your launch configuration. On the Startup tab there is a check labeled “Set breakpoint at [main]”. Uncheck it.

-Kevin

---

<div class="post-metadata">

**Author:** ![abirtz](https://avatars.discourse-cdn.com/v4/letter/a/71e660/32.png) [@abirtz](https://forums.sifive.com/u/abirtz)\
**Post date:** [November 20, 2021, 7:47pm UTC](https://forums.sifive.com/t/freedom-studio-qemu-stack-limit-for-function-local-array/5436/3 "2021-11-20T19:47:12Z")

</div>

> [@kevin](#):
>
> The stack size is defined by the `_stack_size` variable. In the QEMU BSP this defaults to 0x400 (1024) bytes. I see the Unmatched BSP defaults to 0x800 (2048) bytes. Change the QEMU linker script to match, rebuild, and you should be good to go

Grow from 0x400 to 0x4000 and now everything work well.  
Why default is so low ? Stack size for OS count in MB…

> [@kevin](#):
>
> “Set breakpoint at [main]”. Uncheck it.

Yes! Make more easy to run/debug…

I really appreciate your help.  
Thank you.

---

<div class="post-metadata">

**Author:** ![tgm](https://avatars.discourse-cdn.com/v4/letter/t/c68b51/32.png) [@tgm](https://forums.sifive.com/u/tgm)\
**Post date:** [November 26, 2021, 12:54pm UTC](https://forums.sifive.com/t/freedom-studio-qemu-stack-limit-for-function-local-array/5436/4 "2021-11-26T12:54:03Z")

</div>

> Why default is so low ? Stack size for OS count in MB…

It’s impossible to come up with a one size fits all default for all possible uses. It’s common practice for users/developers to have to tune linker scripts for their specific needs.

Which toolchain were you using? Bare metal or Linux? The former will generally have a small default stack size specified in the example linker scripts because it’s generally targeting resource constrained embedded systems.
