> .text [00000000 -> 0000360f] overlaps section .rodata [00000000 -> 00000318]> .data [0000031c -> 00000333] overlaps section .text [00000000 -> 0000360f]> .text lma 0x0 overlaps previous sections
See that your .text section occupies the same address space as .rodata
and .data. It is likely that your linker script (AT91SAM7S256-RAM.ld) is
incorrect.
Perhaps you should post the script.
Clifford
Min Ge wrote:
> I changed CODE and DATA size in "AT91SAM7S256-RAM.ld", it seems OK.
So long as your memory usage is modest, that will work, but the script
dictates the exact locations and sizes of the STACK, CODE, and DATA
regions. This means that if either section grows beyond the set length,
the link will fail even if there is otherwise plenty of RAM available.
It is more flexible to simply create a single RAM region and place all
the sections there, the linker will automatically place them
contiguously, so there are no large unused gaps, and the maximum amount
is then available for stack and heap growth. The STACK would normally be
placed as high as possible in RAM (since it grows downward). Unless you
are reserving that upper RAM region for something else, you might
consider placing it higher.
Clifford
Clifford Slocombe wrote:
> It is more flexible to simply create a single RAM region and place all> the sections there, the linker will automatically place them> contiguously, so there are no large unused gaps, and the maximum amount> is then available for stack and heap growth. The STACK would normally be> placed as high as possible in RAM (since it grows downward).
Could you please tell me how to set RAM as flexible?
Min Ge
Min Ge wrote:
>> Could you please tell me how to set RAM as flexible?>
I am reluctant, since I'm not there with you ro debug it when it all
goes wrong! Keep a copy of your current script - just in case.
I am assuming that your sbrk() or sbrk_r() implementation places the
heap above the stack (at _end), so I propose that you place all the code
and data sections starting from zero, place the stack at some defined
position above the last code/data section (fixed size stack) leaving the
rest for heap. You choose the stack size - your current script allows
the data section to grow to the point where there would be little or no
available stack without warning!
Define the memory layout thus:
MEMORY
{
RAM (rw) : ORIGIN = 0, LENGTH = 64K
}
STACK_LENGTH = 4K ;
Now replace all the instances of >CODE or >DATA with >RAM
To set the stack top change the lines:
.int_data :
{
*(.internal_ram_top)
}> STACK
to:
. += STACK_LENGTH ;
.int_data :
{
*(.internal_ram_top)
} >RAM
I strongly suggest that you create a map file for your build to ensure
that everything is located as expected, and to determine how much heap
you will have available (everything above _end).
If you do not require much heap (used by malloc() and similar functions
as well as the C++ new operators, and internally within C++ container
classes for example), then you might want to make your stack much larger
to minimise the chance of it clashing with your static data or code.
Remember that library functions such as printf() use a considerable
amount of stack space. The 4K I have used in the example is very
conservative, but should just about support printf(). You need to
consider the requirements of your application and set it accordingly.
Clifford
Clifford Slocombe wrote:
> MEMORY> {> RAM (rw) : ORIGIN = 0, LENGTH = 64K> }> STACK_LENGTH = 4K ;>> Now replace all the instances of >CODE or >DATA with >RAM>> To set the stack top change the lines:>> .int_data :> {> *(.internal_ram_top)> }> STACK>> to:> . += STACK_LENGTH ;> .int_data :> {> *(.internal_ram_top)> } >RAM>>
I have tried. It works. Thanks a lot.
Min Ge
Min Ge wrote:
>> I have tried. It works. Thanks a lot.>
Wow, that's good luck - things usually break when I fiddle with linker
scripts! ;)
If your original script was one supplied as a WinARM sample, then
perhaps Martin might consider making this change to the distribution.
However, there may have been a good reason for it being the way it was.
Clifford
Clifford Slocombe wrote:
> Min Ge wrote:>>>>> I have tried. It works. Thanks a lot.>>>> Wow, that's good luck - things usually break when I fiddle with linker> scripts! ;)>> If your original script was one supplied as a WinARM sample, then> perhaps Martin might consider making this change to the distribution.> However, there may have been a good reason for it being the way it was.>> Clifford
Hi Clifford,
I am so sad of telling you. The file of "AT91SAM7S256-RAM.ld" I modified
does not work properly all the time. Sometimes it can not run to the
breakpoint I set. I tried on the original RAM file on the same code, it
owrks.
Must be something I have not modified correctly yet. I will check that
later and then tell you.
Thanks.
Min Ge
Min Ge wrote:
> Hi Clifford,>> I am so sad of telling you. The file of "AT91SAM7S256-RAM.ld" I modified> does not work properly all the time. Sometimes it can not run to the> breakpoint I set. I tried on the original RAM file on the same code, it> owrks.> Must be something I have not modified correctly yet. I will check that> later and then tell you.
Possibly the stack allocation is too small. If this overflows it will
corrupt the code/data space. In the previous script the stack was
probably set much higher.
Clifford