RFA: reducing size of _atexit structure for _REENT_SMALL

Nick Clifton nickc@redhat.com
Sat Mar 11 09:12:00 GMT 2006


Hi Jeff,

  Please could I have permission to check in the attached patch ?

  It changes the _atexit structure defined in libc/include/sys/reent.h
  so that the _fns[] array is replaced by a pointer, if the global
  define _REENT_SMALL is enabled.  If any of the atexit functions are
  used then this pointer is initialised to point to an ATEXIT_SIZE
  length array, but otherwise it is left as NULL, thus saving 31 words
  in the _reent structure.

  I checked the patch by building two toolchains - an xstormy16-elf
  toolchain which used _REENT_SMALL and an xscale-elf toolchain which
  does not.  With both toolchains successfully built and installed I
  compiled and ran a hello world program (with no exit functions) and
  this test program:

    #include <stdlib.h>
    #include <stdio.h>

    static void exit_func_1 (void) 
    { printf ("exit_func_1 called via atexit\n"); }

    static void exit_func_2 (char * arg) 
    { printf ("exit_func_2 called via __cxa_atexit with arg '%s'\n", arg); }

    static void exit_func_3 (int code, char * arg)
    { printf ("exit_func_3 called via on_exit with code %d and arg '%s'\n", code, arg); }

    int main (void)
    { printf ("main starting\n");
      atexit (exit_func_1);
      __cxa_atexit ((void (*)(void)) exit_func_2, "hi", NULL);
      on_exit ((void (*)(int,void *)) exit_func_3, "bye");
      return printf ("main ending\n");
    }

  For both toolchains the following output was produced:
  
    main starting
    main ending
    exit_func_3 called via on_exit with code 12 and arg 'bye'
    exit_func_2 called via __cxa_atexit with arg 'hi'
    exit_func_1 called via atexit

Cheers
  Nick

newlib/ChangeLog
2006-03-10  Nick Clifton  <nickc@redhat.com>

	For _REENT_SMALL...
	* libc/include/sys/reent.h (struct _atexit): Replace _fns array
	with a pointer '_fns_ptr'.
	(REENT_INIT, _REENT_INIT_PTR): Adjust initializations
	appropriately.
	* libc/reent/reent.c (_reclaim_reent): Free the _fns_ptr if it has
	been allocated.
	(_wrapup_reent): Indirect via _fns_ptr.
	* libc/stdlib/__atexit.c (__register_exitproc): If _fns_ptr is
	NULL allocate space for an array of function pointers.
	* libc/stdlib/__call_atexit.c (__call_exitprocs): Indirect via
	_fns_ptr.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: reent-small.patch
Type: text/x-patch
Size: 9379 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/newlib/attachments/20060311/bb11fa76/attachment.bin>


More information about the Newlib mailing list