[coldfire-gnu-discuss] M52235EVB - Problem using malloc - Access Error Attempted Write to Write-Protected Space

Daniel McLean daniel.mclean at optusnet.com.au
Mon Mar 5 04:52:27 UTC 2007


Nathan,

I've tried your test case and I still get the access exception.

I've disassembled the malloc_r object file from libc, and by comparing this
output to the newlib source code (downloaded from CodeSourcery) it seems
like malloc_r is incorrectly accessing memory quite early in the piece.
0x11E from the start of malloc_r (in the disassembly).  It would seem that
this is right at the start of the bin selection logic for malloc_r.  

Being that malloc is a fairly tried and tested routine, I'm beginning to
think that the problem may be caused by my build setup whether it is the
libraries I have been using or the compiler options or similar.  

Just to make sure that my C runtime init is performed correctly, I've
written test code that checks that the .bss section is zeroed out properly
and that the .data section is correctly copied from ROM to RAM, and this
seems fine. 

I guess it is worth asking exactly what libraries I should be linking
against? There are some libraries in CodeSourcery/m68k-elf/lib and then
there are libraries underneath certain folders: eg. m5208, m5213, etc.  As
the 52235 isn't explicitly listed, does it matter which libraries I link
against? I've tried the ones in CodeSourcery/m68k-elf/lib and
CodeSourcery/m68k-elf/lib/m5213 with no success.

As newlib has been compiled with re-entrancy support is anything required to
be setup or otherwise exported form the linker file for malloc to work
correctly? It seems like malloc is not even progressing far enough through
to call sbrk, and I've tried both my own version and the one in libcf and it
makes not difference.

One other thing I did notice is that the av variable used to track the bin
allocation by malloc is originally empty.. Is this expected?

Any help you could provide would be much appreciated...

Thanks
Daniel

-----Original Message-----
From: Nathan Sidwell [mailto:nathan at codesourcery.com] 
Sent: Friday, 2 March 2007 1:44 AM
To: Daniel McLean
Cc: coldfire-gnu-discuss at codesourcery.com
Subject: Re: [coldfire-gnu-discuss] M52235EVB - Problem using malloc -
Access Error Attempted Write to Write-Protected Space

Daniel McLean wrote:
> Thanks for the quick response Nathan..
> 
> What test would you like in terms of a test case?

I've tried a simple program:

int main ()
{
   printf ("boo\n");
   malloc (5);
   printf ("ya\n");
   return 0;
}

and it works fine for me from ROM on a 5208 board.  I didn't have a 52235
board 
I could run this on.

nathan

-- 
Nathan Sidwell    ::   http://www.codesourcery.com   ::         CodeSourcery
nathan at codesourcery.com    ::     http://www.planetfall.pwp.blueyonder.co.uk



-- 
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.446 / Virus Database: 268.18.5/707 - Release Date: 1/03/2007
2:43 PM





More information about the coldfire-gnu-discuss mailing list