Files
semi-libc/src/exit/exit.c
T
Rich Felker 5cc1872156 remove useless infinite loop from end of exit function
this was originally added as a cheap but portable way to quell
warnings about reaching the end of a function that does not return,
but since _Exit is marked _Noreturn, it's not needed. removing it
makes the call to _Exit into a tail call and shaves off a few bytes of
code from minimal static programs.
2014-07-17 21:37:10 -04:00

35 lines
739 B
C

#include <stdlib.h>
#include <stdint.h>
#include "libc.h"
static void dummy()
{
}
/* atexit.c and __stdio_exit.c override these. the latter is linked
* as a consequence of linking either __toread.c or __towrite.c. */
weak_alias(dummy, __funcs_on_exit);
weak_alias(dummy, __stdio_exit);
#ifndef SHARED
weak_alias(dummy, _fini);
extern void (*const __fini_array_start)() __attribute__((weak));
extern void (*const __fini_array_end)() __attribute__((weak));
#endif
_Noreturn void exit(int code)
{
__funcs_on_exit();
#ifndef SHARED
uintptr_t a = (uintptr_t)&__fini_array_end;
for (; a>(uintptr_t)&__fini_array_start; a-=sizeof(void(*)()))
(*(void (**)())(a-sizeof(void(*)())))();
_fini();
#endif
__stdio_exit();
_Exit(code);
}