crtend.c 952 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include <errno.h>
  2. #include <stdlib.h>
  3. /*
  4. static void (*__CTOR_END__[1]) __P((void))
  5. __attribute__((section(".ctors"))) = { (void *)-1 };
  6. static void (*__DTOR_END__[1]) __P((void))
  7. __attribute__((__unused__))
  8. __attribute__((section(".dtors"))) = { (void *)0 };
  9. */
  10. extern void (*__CTOR_END__[]) __P((void));
  11. static void __do_global_ctors_aux __P((void));
  12. static void
  13. __do_global_ctors_aux()
  14. {
  15. void (**p)(void) = __CTOR_END__ - 1;
  16. while (*p)
  17. (**p--)();
  18. }
  19. static void dummy_init(void) __attribute__((section(".trash")));
  20. void
  21. dummy_init(void)
  22. {
  23. static int initialized = 0;
  24. static void (*volatile call__ctors)(void) = __do_global_ctors_aux;
  25. /*
  26. * Call global constructors.
  27. * Arrange to call global destructors at exit.
  28. */
  29. /* prevent function pointer constant propagation */
  30. __asm__ __volatile__ (".section .init");
  31. if (!initialized) {
  32. initialized = 1;
  33. (*call__ctors)();
  34. }
  35. __asm__ __volatile__ (".section .trash");
  36. }