crtend.c 972 B

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