0

I am working on an ARM firmware that has tight memory allocation, and I am continually tweaking the size of a given array (used for dynamic allocation inside my application) in order to use all remaining RAM that is not used by the .bss section. Is there any way to declare or section-locate the array in a way that it is automatically sized to consume all remaining space in the memory region? (Specifically, I am using Rowley CrossWorks for ARM as well as the GCC built into ESP-IDF, but the question is more general to the GCC ARM compiler).

Nathan Wiebe
  • 794
  • 5
  • 12
  • This is the 'heap'. Of course this is possible. If you have a gnu ld file and post relevant sections of it, there are many people who could tell you how to do this. – artless noise Feb 28 '23 at 18:42
  • No, this is definitely not the heap. Typically the heap and main/idle thread task stack have a fixed size (at least they do on all the platforms I've used) - fixed at compile time and allocated in a linker section like everything else. If some other platforms have a mechanism for the compiler's heap to automatically expand to fill a memory region defined in the linker script, then I guess what I am looking for is any documentation on how this mechanism works and how to utilize this mechanism for an array of my choosing (rather than the compiler's heap). – Nathan Wiebe Feb 28 '23 at 19:28
  • Specifically, I am looking for a way to determine (from my C code) what the base address and size of this region is so it can be safely used in my C code. – Nathan Wiebe Feb 28 '23 at 19:36
  • What I am saying is that the mechanics in the linker for the heap are exactly like you describe. Generally the heap/stack take all left over address space on a platform without an MMU. The way the 'heap' is used is different than a global of course, but the reservation of space in a linker file is the same. But I still don't see a linker file. – artless noise Feb 28 '23 at 21:39
  • I am not quite seeing the point of posting a linker file as my linker script does not currently contain a heap or stack section that expands to fill available space. If you can refer me to a linker script somewhere that does include such a section, I would be eternally grateful. (or better yet, a keyword or syntax within a gcc ARM linker script that can point me in the right direction for hunting through the docs, as per the OP). – Nathan Wiebe Mar 01 '23 at 15:33
  • My other reason for hesitancy posting the linker script is that Crossworks uses a pair of files (flash placement and memory regions) that it uses to auto-generate the linker script, so the linker script I do have is long and full of boilerplate and not directly editable, and generally a lot longer than I could post as text in Stack Overflow. – Nathan Wiebe Mar 01 '23 at 15:34
  • [This post](https://stackoverflow.com/questions/8458084/align-in-linker-scripts/72942905#72942905) gives some gotcha's of manipulating '.' as it has an absolute meaning outside a section and is 'relative' inside a section. It may be relevant to you (just to get whatever alignment the array type is correct). – artless noise Mar 01 '23 at 16:09
  • 1
    If you have a '.bss' section, at the end of the section, you create `array_size = sizeof(RAM) - .`. Then create a label `array = .` and `. += (sizeof(RAM) - .);` These symbols can be used in the source. Ie, you just manually adjust '.' to reserve space. All ideas are in the manual. For example [Output section LMA](https://sourceware.org/binutils/docs/ld/Output-Section-LMA.html) show use of linker symbols with 'C' code. Some details will be wrong as I have no idea exactly what you are doing, but the principles should apply. – artless noise Mar 01 '23 at 16:16
  • Awesome. Thank-you! If you care to post this comment as an answer, I will happy mark it as accepted. – Nathan Wiebe Mar 01 '23 at 16:51

0 Answers0