EmbDev.net

Forum: ARM programming with GCC/GNU tools Static variable getting overwritten by?


Author: jrmymllr jrmymllr (jrmymllr)
Posted on:

Rate this post
0 useful
not useful
I'm using two open source modules in a project, an MP3 decoder and a
TCP/IP stack.  Long story short, the TCP/IP stack contains a "static
struct" that holds the ARP table, and parts of it are being overwritten
when the MP3 decoder gets its chance to run.

I'm at a loss because I can't understand how the compiler would allow
this to happen.  There is a line in the .map file that lists the struct
that is getting overwritten:

.bss.arp_table
                0x20000ea0       0x60 ./uip-1.0/uip/uip_arp.o

Wouldn't this indicate that this section of RAM is set aside for
arp_table and won't be freed during execution?  The problem occurs
everytime, very reliably.  It's like variables in the MP3 decoder are
assigned to the same RAM address.

Any advice on tracking down this problem?  This is running on a
Cortex-M3, by the way.

Author: jrmymllr jrmymllr (jrmymllr)
Posted on:

Rate this post
0 useful
not useful
Additional information about this problem:

I have confirmed that when entering a function, the data passed into the
function, or variables local to the function are being allocated in this
section of RAM that has already been allocated to a static struct.  What
on earth could cause this problem??  I'm using CodeSourcery G++ Lite.

Author: Giovanni Di sirio (gdisirio)
Posted on:

Rate this post
0 useful
not useful
A stack overflow ?

It would be a good idea to post the map file and the linker script.

Author: jrmymllr jrmymllr (jrmymllr)
Posted on:

Rate this post
0 useful
not useful
Giovanni Di Sirio wrote:
> A stack overflow ?
>
> It would be a good idea to post the map file and the linker script.

This problem started occurring when I added a function that would make
heavy use of the stack, so that might be my problem.  As I was looking
through source files, I came across the stack allocation, and it's only
256 bytes; probably not enough.   I used a sample project to get started
so I don't fully understand how this sets the stack.

#ifndef STACK_SIZE
#define STACK_SIZE                              64
#endif
static unsigned long pulStack[STACK_SIZE];


It's obvious this makes the stack 64 32-bit words long, but the only
other instance of pulStack is where the vector table is set up.  How
exactly does the linker know to use this space for stack?  If I remember
correctly, the stack is populated from the top, down?  If this is the
case, this makes sense because the struct that is being corrupted is
very close to the bottom of the stack.  Is there a good way to determine
the required stack size, or is it not an exact science?

Author: Giovanni Di sirio (gdisirio)
Posted on:

Rate this post
0 useful
not useful
I cannot answer, it depends on how the startup file and the linker
scripts are done and the stack you are running on (process or
exception).

The linker does its work by executing a linker script, usually it has a
.ld extension but may change, you should have one in your project, it is
specified in the linker command line.

Anyway, just try to increase that value and see if something change.

Author: jrmymllr jrmymllr (jrmymllr)
Posted on:

Rate this post
0 useful
not useful
Giovanni Di Sirio wrote:
> I cannot answer, it depends on how the startup file and the linker
> scripts are done and the stack you are running on (process or
> exception).
>
> The linker does its work by executing a linker script, usually it has a
> .ld extension but may change, you should have one in your project, it is
> specified in the linker command line.
>
> Anyway, just try to increase that value and see if something change.

Thanks for your suggestion.  That fixed the problem.

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.