atexit in newlib

J. Johnston jjohnstn@redhat.com
Fri Aug 16 16:03:00 GMT 2002


Mark Yang wrote:
> 
> I am stepping through newlib for arm and my code
> crashes at newlib function "atexit". here is the dump
> code I have, at address 328, I got ffff in r1, then
> the program crashed at 33c.
> looks like the pointer is not initialized or something
> wrong with it, I tried newlib 1.10.0 instead of 1.9.0,
> still doesn't work, anyone has suggestions?
>   thanks!
> Mark
> 

You're going to have to do some debugging. It looks like a piece of
code has corrupted the reentrancy structure.
If you look at libc/reent/impure.c, you will see that
the _impure_ptr variable is statically initialized.  The
_REENT pointer is in reality _impure_ptr.  

At startup, the value of _REENT->_atexit will be NULL.
After that, atexit will use _REENT->_atexit0 and will
allocate additional atexit structures when needed.

I would suggest you start by looking at the _impure_ptr
storage at the start of your program, then set a watch
point whenever the _impure_ptr->_atexit storage gets
altered and see who the culprit is.

-- Jeff J.

> 00000314 <atexit>:
>      314:       e1a0c00d        mov     ip, sp
>      318:       e92dd830        stmdb   sp!, {r4, r5,
> fp, ip, lr, pc}
>         _VOID _EXFUN ((*fn), (_VOID)))
> {
>   register struct _atexit *p;
> 
>   if ((p = _REENT->_atexit) == NULL)
>      31c:       e59f506c        ldr     r5, [pc, #6c]
>  ; 390 <atexit+0x7c>
>      320:       e5953000        ldr     r3, [r5]
>      324:       e24cb004        sub     fp, ip, #4
>  ; 0x4
>      328:       e5931148        ldr     r1, [r3, #328]
>      32c:       e1a04000        mov     r4, r0
>      330:       e3510000        cmp     r1, #0  ; 0x0
>     _REENT->_atexit = p = &_REENT->_atexit0;
>      334:       02831f53        addeq   r1, r3, #332
>  ; 0x14c
>      338:       05831148        streq   r1, [r3, #328]
>   if (p->_ind >= _ATEXIT_SIZE)
>      33c:       e5913004        ldr     r3, [r1, #4]
>      340:       e353001f        cmp     r3, #31 ; 0x1f
>      344:       da00000a        ble     374
> <atexit+0x60>
>     {
>       if ((p = (struct _atexit *) malloc (sizeof *p))
> == NULL)
> 
> __________________________________________________
> Do You Yahoo!?
> HotJobs - Search Thousands of New Jobs
> http://www.hotjobs.com



More information about the Newlib mailing list