gbl-ctors.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /* Definitions relating to the special __do_global_init function used
  2. for getting g++ file-scope static objects constructed. This file
  3. will get included either by libgcc2.c (for systems that don't support
  4. a .init section) or by crtstuff.c (for those that do).
  5. Copyright (C) 1991-2022 Free Software Foundation, Inc.
  6. Contributed by Ron Guilmette (rfg@segfault.us.com)
  7. This file is part of GCC.
  8. GCC is free software; you can redistribute it and/or modify it under
  9. the terms of the GNU General Public License as published by the Free
  10. Software Foundation; either version 3, or (at your option) any later
  11. version.
  12. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  13. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  15. for more details.
  16. Under Section 7 of GPL version 3, you are granted additional
  17. permissions described in the GCC Runtime Library Exception, version
  18. 3.1, as published by the Free Software Foundation.
  19. You should have received a copy of the GNU General Public License and
  20. a copy of the GCC Runtime Library Exception along with this program;
  21. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  22. <http://www.gnu.org/licenses/>. */
  23. /* This file contains definitions and declarations of things
  24. relating to the normal start-up-time invocation of C++
  25. file-scope static object constructors. These declarations
  26. and definitions are used by *both* libgcc2.c and by crtstuff.c.
  27. Note that this file should only be compiled with GCC.
  28. */
  29. #ifndef GCC_GBL_CTORS_H
  30. #define GCC_GBL_CTORS_H
  31. /* Declare a pointer to void function type. */
  32. typedef void (*func_ptr) (void);
  33. /* Declare the set of symbols use as begin and end markers for the lists
  34. of global object constructors and global object destructors. */
  35. extern func_ptr __CTOR_LIST__[];
  36. extern func_ptr __DTOR_LIST__[];
  37. /* Declare the routine which needs to get invoked at program start time. */
  38. extern void __do_global_ctors (void);
  39. /* Declare the routine which needs to get invoked at program exit time. */
  40. extern void __do_global_dtors (void);
  41. /* Define a macro with the code which needs to be executed at program
  42. start-up time. This macro is used in two places in crtstuff.c (for
  43. systems which support a .init section) and in one place in libgcc2.c
  44. (for those system which do *not* support a .init section). For all
  45. three places where this code might appear, it must be identical, so
  46. we define it once here as a macro to avoid various instances getting
  47. out-of-sync with one another. */
  48. /* Some systems place the number of pointers
  49. in the first word of the table.
  50. On other systems, that word is -1.
  51. In all cases, the table is null-terminated.
  52. If the length is not recorded, count up to the null. */
  53. /* Some systems use a different strategy for finding the ctors.
  54. For example, svr3. */
  55. #ifndef DO_GLOBAL_CTORS_BODY
  56. #define DO_GLOBAL_CTORS_BODY \
  57. do { \
  58. __SIZE_TYPE__ nptrs = (__SIZE_TYPE__) __CTOR_LIST__[0]; \
  59. unsigned i; \
  60. if (nptrs == (__SIZE_TYPE__)-1) \
  61. for (nptrs = 0; __CTOR_LIST__[nptrs + 1] != 0; nptrs++); \
  62. for (i = nptrs; i >= 1; i--) \
  63. __CTOR_LIST__[i] (); \
  64. } while (0)
  65. #endif
  66. #endif /* GCC_GBL_CTORS_H */