<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>Arm-linux-gcc malloc get failure while arm-elf-gcc ok</TITLE>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.2900.3020" name=GENERATOR></HEAD>
<BODY>
<DIV dir=ltr align=left><SPAN class=596183411-27012007><FONT face=Arial
color=#800080 size=2>hi there</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=596183411-27012007><FONT face=Arial
color=#800080 size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=596183411-27012007><FONT face=Arial
color=#800080 size=2>after modifing some codes(forget what's the codes:()
arm-elf-gcc also get malloc failure,I have to think about my program has
something wrong</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=596183411-27012007><FONT face=Arial
color=#800080 size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=596183411-27012007><FONT face=Arial
color=#800080 size=2>actually malloc have got failure in the
lib_arm/board.c:</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=596183411-27012007><FONT face=Arial
color=#800080 size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=596183411-27012007><FONT face=Arial
color=#800080 size=2>a malloc will trigger *sbrk twice(why?)</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=596183411-27012007><FONT face=Arial
color=#800080 size=2>test code in start_armboot()</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=596183411-27012007><FONT face=Arial
color=#800080 size=2>...</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=596183411-27012007><FONT face=Arial
color=#800080 size=2>void *testptr;</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=596183411-27012007><FONT face=Arial
color=#800080 size=2>testptr=malloc(10);</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=596183411-27012007><FONT face=Arial
color=#800080 size=2>...</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=596183411-27012007><FONT face=Arial
color=#800080 size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=596183411-27012007><FONT face=Arial
color=#800080 size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=596183411-27012007><FONT face=Arial
color=#800080 size=2>in the void *sbrk (ptrdiff_t increment)<BR>{<BR> ulong
old = mem_malloc_brk;<BR> ulong new = old + increment;</FONT></SPAN></DIV>
<DIV><FONT face=Arial color=#800080 size=2></FONT> </DIV>
<DIV dir=ltr align=left><SPAN class=596183411-27012007><FONT face=Arial
color=#800080 size=2> if ((new < mem_malloc_start) || (new >
mem_malloc_end)) {<BR> return
(NULL);<BR> }<BR> mem_malloc_brk = new;</FONT></SPAN></DIV>
<DIV><FONT face=Arial color=#800080 size=2></FONT> </DIV>
<DIV dir=ltr align=left><SPAN class=596183411-27012007><FONT face=Arial
color=#800080 size=2> return ((void *) old);<BR>}</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=596183411-27012007><FONT face=Arial
color=#800080 size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=596183411-27012007><FONT face=Arial
color=#800080 size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=596183411-27012007><FONT face=Arial
color=#800080 size=2>I print out the debug information:</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=596183411-27012007><FONT face=Arial
color=#800080 size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=596183411-27012007><FONT face=Arial
color=#800080 size=2>1st trigger:</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=596183411-27012007><FONT face=Arial
color=#800080 size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=596183411-27012007><FONT face=Arial
color=#800080
size=2>increment:
a2e2e4e?(so big?)</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=596183411-27012007><FONT face=Arial
color=#800080
size=2>old:
c6dfc00</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=596183411-27012007><FONT face=Arial
color=#800080
size=2>new:
169c2a4e</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=596183411-27012007><FONT face=Arial
color=#800080 size=2>mem_malloc_start:
c6dfc00</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=596183411-27012007><FONT face=Arial
color=#800080 size=2>mem_malloc_end:
c700000</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=596183411-27012007><FONT face=Arial
color=#800080 size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=596183411-27012007><FONT face=Arial
color=#800080 size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=596183411-27012007><FONT face=Arial
color=#800080 size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=596183411-27012007><FONT face=Arial
color=#800080 size=2>2nd:</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=596183411-27012007><FONT face=Arial
color=#800080 size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=596183411-27012007>
<DIV dir=ltr align=left><SPAN class=596183411-27012007><FONT face=Arial
color=#800080
size=2>increment:
1b2</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=596183411-27012007><FONT face=Arial
color=#800080
size=2>old:
c6dfc00</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=596183411-27012007><FONT face=Arial
color=#800080
size=2>new:
c6dfdb2</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=596183411-27012007></SPAN><SPAN
class=596183411-27012007><FONT face=Arial color=#800080
size=2>mem_malloc_start: c6dfc00</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=596183411-27012007><FONT face=Arial
color=#800080 size=2>mem_malloc_end:
c700000</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=596183411-27012007><FONT face=Arial
color=#800080 size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=596183411-27012007><FONT face=Arial
color=#800080 size=2>seems the 2nd is ok</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=596183411-27012007><FONT face=Arial
color=#800080 size=2>but testptr still =0</FONT></SPAN></DIV></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=596183411-27012007><FONT face=Arial
color=#800080 size=2></FONT></SPAN> </DIV>
<DIV><FONT face=Arial color=#800080 size=2><SPAN
class=596183411-27012007>*****************</SPAN></FONT></DIV>
<DIV><FONT face=Arial color=#800080 size=2><SPAN class=596183411-27012007>in the
cpu/s3c44b0/start.S I create stack like that:</SPAN></FONT></DIV>
<DIV><FONT face=Arial color=#800080 size=2><SPAN
class=596183411-27012007></SPAN></FONT> </DIV>
<DIV><FONT face=Arial color=#800080 size=2><SPAN
class=596183411-27012007>stack_setup:</SPAN></FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial color=#800080 size=2><SPAN
class=596183411-27012007>ldr r0,=0xc700000 /* upper 128
KiB: relocated uboot */<BR>sub r0, r0, #CFG_MALLOC_LEN /*
malloc area 1024+128*1024
=1227204bytes
*/<BR>sub r0, r0, #CFG_GBL_DATA_SIZE /* bdinfo
128
*/<BR>sub sp, r0, #12 /* leave 3 words for
abort-stack */</SPAN></FONT></DIV>
<DIV><FONT face=Arial color=#800080 size=2><SPAN
class=596183411-27012007></SPAN></FONT> </DIV>
<DIV><FONT face=Arial color=#800080 size=2><SPAN class=596183411-27012007>i
think it should be ok</SPAN></FONT></DIV>
<DIV><FONT face=Arial color=#800080 size=2><SPAN
class=596183411-27012007>******************</SPAN></FONT></DIV>
<DIV><FONT face=Arial color=#800080 size=2><SPAN
class=596183411-27012007></SPAN></FONT> </DIV>
<DIV><SPAN class=596183411-27012007><FONT face=Arial color=#800080
size=2>regards,</FONT></SPAN></DIV>
<DIV><SPAN class=596183411-27012007><FONT face=Arial color=#800080
size=2>rui</FONT></SPAN></DIV>
<DIV><SPAN class=596183411-27012007><FONT face=Arial color=#800080
size=2></FONT></SPAN> </DIV>
<DIV><BR></DIV>
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> u-boot-users-bounces@lists.sourceforge.net
[mailto:u-boot-users-bounces@lists.sourceforge.net] <BR><B>Sent:</B> Saturday,
January 27, 2007 12:11 PM<BR><B>To:</B>
u-boot-users@lists.sourceforge.net<BR><B>Subject:</B> [U-Boot-Users]
Arm-linux-gcc malloc get failure while arm-elf-gcc ok<BR></FONT><BR></DIV>
<DIV></DIV><!-- Converted from text/rtf format -->
<P><SPAN lang=zh-cn><FONT face=Simsun size=2> hi there</FONT></SPAN> </P>
<P><SPAN lang=zh-cn><FONT face=Simsun size=2>I wonder if I am the first one to
get this problem</FONT></SPAN> </P>
<P><SPAN lang=zh-cn><FONT face=Simsun size=2>In common\lists.c</FONT></SPAN>
</P>
<P><SPAN lang=zh-cn><FONT face=Simsun size=2>Handle NewHandle (unsigned int
numBytes)</FONT></SPAN> <BR><SPAN lang=zh-cn><FONT face=Simsun
size=2>{</FONT></SPAN> <BR><SPAN
lang=zh-cn> <FONT face=Simsun
size=2>void *memPtr;</FONT></SPAN> <BR><SPAN
lang=zh-cn> <FONT face=Simsun
size=2>HandleRecord *hanPtr;</FONT></SPAN> </P>
<P><SPAN lang=zh-cn> <FONT face=Simsun
size=2>memPtr = calloc (numBytes, 1);</FONT></SPAN> <BR><SPAN
lang=zh-cn> <FONT face=Simsun
size=2>hanPtr = (HandleRecord *) calloc (sizeof (HandleRecord),
1);</FONT></SPAN> </P>
<P><SPAN lang=zh-cn><FONT face=Simsun color=#ff0000 size=2>Debug("memPtr:%d
hanPtr:%d\n",memPtr ,hanPtr ); //</FONT></SPAN><SPAN lang=en-us><FONT
face=Simsun color=#ff0000 size=2>arm-linux-gcc get 0 for both of the Ptr while
arm-elf-gcc can malloc successfully</FONT></SPAN><SPAN lang=zh-cn></SPAN></P>
<P><SPAN lang=zh-cn> <FONT face=Simsun
size=2>if (hanPtr && (memPtr || numBytes == 0)) {</FONT></SPAN>
<BR><SPAN lang=zh-cn>
<FONT face=Simsun
size=2>hanPtr->ptr = memPtr;</FONT></SPAN> <BR><SPAN
lang=zh-cn>
<FONT face=Simsun
size=2>hanPtr->size = numBytes;</FONT></SPAN> <BR><SPAN
lang=zh-cn>
<FONT face=Simsun size=2>return
(Handle) hanPtr;</FONT></SPAN> <BR><SPAN
lang=zh-cn> <FONT face=Simsun size=2>}
else {</FONT></SPAN> <BR><SPAN
lang=zh-cn>
<FONT face=Simsun size=2>free
(memPtr);</FONT></SPAN> <BR><SPAN
lang=zh-cn>
<FONT face=Simsun size=2>free
(hanPtr);</FONT></SPAN> <BR><SPAN
lang=zh-cn>
<FONT face=Simsun size=2>return
NULL;</FONT></SPAN> <BR><SPAN
lang=zh-cn> <FONT face=Simsun
size=2>}</FONT></SPAN> </P>
<P><SPAN lang=zh-cn><FONT face=Simsun size=2>}</FONT></SPAN> </P>
<P><SPAN lang=en-us><FONT face=Simsun size=2>Arm-elf-gcc is 3.4.0</FONT></SPAN>
<BR><SPAN lang=en-us><FONT face=Simsun size=2>Arm-linux-gcc is 3.3.2 (heard
there are most problems in this version??)</FONT></SPAN><SPAN lang=zh-cn></SPAN>
</P>
<P><SPAN lang=en-us><FONT face=Simsun size=2>Regards</FONT></SPAN> <BR><SPAN
lang=en-us><FONT face=Simsun size=2>Zhou rui</FONT></SPAN><SPAN
lang=zh-cn></SPAN> </P></BODY></HTML>