crt0.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* Copyright (C) 2017-2022 Free Software Foundation, Inc.
  2. This file is free software; you can redistribute it and/or modify it
  3. under the terms of the GNU General Public License as published by the
  4. Free Software Foundation; either version 3, or (at your option) any
  5. later version.
  6. This file is distributed in the hope that it will be useful, but
  7. WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  9. General Public License for more details.
  10. Under Section 7 of GPL version 3, you are granted additional
  11. permissions described in the GCC Runtime Library Exception, version
  12. 3.1, as published by the Free Software Foundation.
  13. You should have received a copy of the GNU General Public License and
  14. a copy of the GCC Runtime Library Exception along with this program;
  15. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  16. <http://www.gnu.org/licenses/>. */
  17. typedef long long size_t;
  18. /* Provide an entry point symbol to silence a linker warning. */
  19. void _start() {}
  20. #ifdef USE_NEWLIB_INITFINI
  21. extern void __libc_init_array (void) __attribute__((weak));
  22. extern void __libc_fini_array (void) __attribute__((weak));
  23. __attribute__((amdgpu_hsa_kernel ()))
  24. void _init_array()
  25. {
  26. __libc_init_array ();
  27. }
  28. __attribute__((amdgpu_hsa_kernel ()))
  29. void _fini_array()
  30. {
  31. __libc_fini_array ();
  32. }
  33. #endif
  34. /* These magic symbols are provided by the linker. */
  35. extern void (*__preinit_array_start []) (void) __attribute__((weak));
  36. extern void (*__preinit_array_end []) (void) __attribute__((weak));
  37. extern void (*__init_array_start []) (void) __attribute__((weak));
  38. extern void (*__init_array_end []) (void) __attribute__((weak));
  39. extern void (*__fini_array_start []) (void) __attribute__((weak));
  40. extern void (*__fini_array_end []) (void) __attribute__((weak));
  41. __attribute__((amdgpu_hsa_kernel ()))
  42. void _init_array()
  43. {
  44. /* Iterate over all the init routines. */
  45. size_t count;
  46. size_t i;
  47. count = __preinit_array_end - __preinit_array_start;
  48. for (i = 0; i < count; i++)
  49. __preinit_array_start[i] ();
  50. count = __init_array_end - __init_array_start;
  51. for (i = 0; i < count; i++)
  52. __init_array_start[i] ();
  53. }
  54. __attribute__((amdgpu_hsa_kernel ()))
  55. void _fini_array()
  56. {
  57. size_t count;
  58. size_t i;
  59. count = __fini_array_end - __fini_array_start;
  60. for (i = count; i > 0; i--)
  61. __fini_array_start[i-1] ();
  62. }