This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Heap region gets removed when scatter-loading

I'm playing around with scatter-loading in Keil 5.25 with armcc compiler.
Now I have a dummy project that allocates stack and heap in 'default' startup assembly file:

Stack_Size      EQU     0x00000400

                AREA    STACK, NOINIT, READWRITE, ALIGN=3
Stack_Mem       SPACE   Stack_Size
__initial_sp


; <h> Heap Configuration
;   <o>  Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>

Heap_Size       EQU     0x00000200

                AREA    HEAP, NOINIT, READWRITE, ALIGN=3
__heap_base
Heap_Mem        SPACE   Heap_Size
__heap_limit

                PRESERVE8
                THUMB

I'm trying to use scatter file to place stack and heap at some specific memory regions. I do it like this:

LR_IROM1 0x8000000 0x4000  {    ; load region size_region
  ER_IROM1 0x8000000 0x4000  {  ; load address = execution address
    *.o (RESET, +First)
    *(InRoot$$Sections)
    .ANY (+RO)
  }

  ARM_LIB_STACK 0x20000000 {
    *(STACK)
  }

  ARM_LIB_HEAP 0x20004000 {
    *(HEAP)
  }

  RW_IRAM1 0x20006000  {
    *(+RW +ZI)
  }
}

And in main I call malloc to allocate some memory.

When I build the project, linker gives me this warning: "./dummy.sct(34): warning: L6329W: Pattern *(HEAP) only matches removed unused sections."

But I use malloc, so I should be using heap memory.
In debugger I can see that memory that I allocated by malloc was already taken by some global variable, which I presume means that heap region is indeed removed by the linker.

But why is it happening? What am I doing wrong?

I was able to force linker not to remove heap by --keep option but I still want to know what is wrong.

Parents
  • IF you use ARM_LIB_HEAP and ARM_LIB_STACK regions, you do not define ANYTHING for them in the assembly language files (Save putting Image$$ARM_LIB_STACK$$ZI$$Limit in the 1st location of the vector table) . Everything goes in the scatter file. You specify the size and location in the scatter file. IF Keil's startup code sees these regions defined, it will use them for stack and heap.

Reply
  • IF you use ARM_LIB_HEAP and ARM_LIB_STACK regions, you do not define ANYTHING for them in the assembly language files (Save putting Image$$ARM_LIB_STACK$$ZI$$Limit in the 1st location of the vector table) . Everything goes in the scatter file. You specify the size and location in the scatter file. IF Keil's startup code sees these regions defined, it will use them for stack and heap.

Children