This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Strange linker behavoir with 'heap' and 'stack' sections


Hi everyone,

I am trying to find out, where my program data ends and encountered a behavoir I can not explain.

Here is what I did so far.

I set some symbols in the linker script which I am able to access in the C-source (all the symbols startXyz and endXyz).

Part of the linker script:
**************************

  .heap    :
  {
    PROVIDE( startHeap = . );
    PROVIDE (end = .);PROVIDE (__end__ = .);
    *(.heap)
    . += 0x100000;
    PROVIDE (heap_limit = . );
    PROVIDE( endHeap = . );
  } > ram_data
  .netosstack    :
  {
    PROVIDE( startNetOsStack = . );
    *(.netosstack)
    . += 0x3000;
    netosstack_end = . ;
    PROVIDE( endNetOsStack = . );
  } > ram_data
  .stack    :
  {
    PROVIDE( startStack = . );
    *(.stack)
    . += 0x2000;
    stack_end = . ;
    PROVIDE( endStack = . );
  } > ram_data
  .free_mem    :
  {
    free_mem_begin = . ;
    *(.free_mem)
    PROVIDE( endRamData = . );
  } > ram_data

The corresponding part of the map-file produced looks like that:
****************************************************************

.heap           0x00056aa0   0x100000
                0x00056aa0                PROVIDE (startHeap, .)
                0x00056aa0                PROVIDE (end, .)
                0x00056aa0                PROVIDE (__end__, .)
 *(.heap)
 *fill*         0x00056aa0   0x100000
                0x00256aa0                .=(.+0x100000)
                0x00156aa0                PROVIDE (heap_limit, .)
                0x00156aa0                PROVIDE (endHeap, .)

.netosstack     0x00156aa0     0x3000
                0x00156aa0                PROVIDE (startNetOsStack, .)
 *(.netosstack)
 *fill*         0x00156aa0     0x3000
                0x0015caa0                .=(.+0x3000)
                0x00159aa0                netosstack_end=.
                0x00159aa0                PROVIDE (endNetOsStack, .)

.stack          0x00159aa0     0x2000
                0x00159aa0                PROVIDE (startStack, .)
 *(.stack)
 *fill*         0x00159aa0     0x2000
                0x0015daa0                .=(.+0x2000)
                0x0015baa0                stack_end=.
                0x0015baa0                PROVIDE (endStack, .)

.free_mem       0x0015baa0        0x0
                0x0015baa0                free_mem_begin=.
 *(.free_mem)
                0x0015baa0                PROVIDE (endRamData, .)

In the program I checked the addresses of my symblos:
*****************************************************

address of startHeap: 0x00056aa0
address of endHeap: 0x00156aa0

address of startNetOsStack: 0x00156aa0
address of endNetOsStack: 0x00159aa0

address of startStack: 0x00159aa0
address of endStack: 0x0015baa0

address of endRamData: 0x0015baa0

address of local variable 'start' in function HardwareTest: 0x0015cc2c

sp (stack pointer): 0x0015cc24


Here are the questions: ***********************

1. What are the lines (heap, netosstack, stack)

0x00256aa0 .=(.+0x100000)

0x0015caa0 .=(.+0x3000)

0x0015daa0 .=(.+0x2000)

in the map file and why are they behind the endRamData symbol?

2. Why is the local variable 'start' located at address 0x0015cc2c and not somewhere between startStack and endStack resp. startNetOsStack and endNetOsStack?

3. Why is the stackpointer set to 0x0015cc24 which is neither netosstack nor stack?

Cheers for any help.

Roman


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]