This is the mail archive of the crossgcc@cygnus.com mailing list for the crossgcc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Newlib problems with atexit()


I am trying to use RTEMS-4.0.0 (with egcs-1.1b, binutils-2.9.1 and
newlib-1.8.0) on an MPC860 board.  During initialization, the rtems code
calls the libc (newlib) function atexit() to register a a routine that
closes down a clock driver.  atexit() reads a pointer to an _atexit
structure (_REENT->atexit).  It seems that this pointer is uninitialized
at runtime so it picks up random values from what ever happens to be in
memory at the time.

I assume that this value should be initialized to NULL.  Where and how
is this done ?
Is it the responsibility of newlib, rtems, gcc or the loader (note that
I am using a BDM interface to download the elf file into DRAM).  My
board support package clears the BSS but I believe that the _REENT
structure lives in the .data section.

Where is the best place to discuss newlib related questions ?
Thanks for any help,
Brendan Simon.

Here is the atexit() code from newlib 1.8.0.

int
_DEFUN (atexit,
    (fn),
    _VOID _EXFUN ((*fn), (_VOID)))
{
  register struct _atexit *p;

  if ((p = _REENT->_atexit) == NULL)
    _REENT->_atexit = p = &_REENT->_atexit0;

  if (p->_ind >= _ATEXIT_SIZE)
  {
      if ((p = (struct _atexit *) malloc (sizeof *p)) == NULL)
         return -1;
      p->_ind = 0;
      p->_next = _REENT->_atexit;
         _REENT->_atexit = p;
  }
  p->_fns[p->_ind++] = fn;
  return 0;
}


_______________________________________________
New CrossGCC FAQ: http://www.objsw.com/CrossGCC
_______________________________________________
To remove yourself from the crossgcc list, send
mail to crossgcc-request@cygnus.com with the
text 'unsubscribe' (without the quotes) in the
body of the message.