pt-initfini.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /* Special .init and .fini section support. Linuxthread version.
  2. Copyright (C) 1995,1996,1997,2000,2001,2002 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it
  5. and/or modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2 of the License, or (at your option) any later version.
  8. In addition to the permissions in the GNU Lesser General Public
  9. License, the Free Software Foundation gives you unlimited
  10. permission to link the compiled version of this file with other
  11. programs, and to distribute those programs without any restriction
  12. coming from the use of this file. (The Library General Public
  13. License restrictions do apply in other respects; for example, they
  14. cover modification of the file, and distribution when not linked
  15. into another program.)
  16. The GNU C Library is distributed in the hope that it will be
  17. useful, but WITHOUT ANY WARRANTY; without even the implied warranty
  18. of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. GNU Lesser General Public License for more details.
  20. You should have received a copy of the GNU Lesser General Public
  21. License along with the GNU C Library; see the file COPYING.LIB. If not,
  22. see <http://www.gnu.org/licenses/>. */
  23. /* This file is compiled into assembly code which is then munged by a sed
  24. script into two files: crti.s and crtn.s.
  25. * crti.s puts a function prologue at the beginning of the
  26. .init and .fini sections and defines global symbols for
  27. those addresses, so they can be called as functions.
  28. * crtn.s puts the corresponding function epilogues
  29. in the .init and .fini sections. */
  30. #include <stdlib.h>
  31. /* We use embedded asm for .section unconditionally, as this makes it
  32. easier to insert the necessary directives into crtn.S. */
  33. #define SECTION(x) __asm__ (".section " x )
  34. /* Embed an #include to pull in the alignment and .end directives. */
  35. __asm__ ("\n#include \"defs.h\"");
  36. __asm__ ("\n#if defined __i686 && defined __ASSEMBLER__");
  37. __asm__ ("\n#undef __i686");
  38. __asm__ ("\n#define __i686 __i686");
  39. __asm__ ("\n#endif");
  40. /* The initial common code ends here. */
  41. __asm__ ("\n/*@HEADER_ENDS*/");
  42. /* To determine whether we need .end and .align: */
  43. __asm__ ("\n/*@TESTS_BEGIN*/");
  44. extern void dummy (void (*foo) (void));
  45. void
  46. dummy (void (*foo) (void))
  47. {
  48. if (foo)
  49. (*foo) ();
  50. }
  51. __asm__ ("\n/*@TESTS_END*/");
  52. /* The beginning of _init: */
  53. __asm__ ("\n/*@_init_PROLOG_BEGINS*/");
  54. static void
  55. call_initialize_minimal (void)
  56. {
  57. extern void __pthread_initialize_minimal_internal (void)
  58. __attribute ((visibility ("hidden")));
  59. __pthread_initialize_minimal_internal ();
  60. }
  61. SECTION (".init");
  62. extern void __attribute__ ((section (".init"))) _init (void);
  63. void
  64. _init (void)
  65. {
  66. /* The very first thing we must do is to set up the registers. */
  67. call_initialize_minimal ();
  68. __asm__ ("ALIGN");
  69. __asm__("END_INIT");
  70. /* Now the epilog. */
  71. __asm__ ("\n/*@_init_PROLOG_ENDS*/");
  72. __asm__ ("\n/*@_init_EPILOG_BEGINS*/");
  73. SECTION(".init");
  74. }
  75. __asm__ ("END_INIT");
  76. /* End of the _init epilog, beginning of the _fini prolog. */
  77. __asm__ ("\n/*@_init_EPILOG_ENDS*/");
  78. __asm__ ("\n/*@_fini_PROLOG_BEGINS*/");
  79. SECTION (".fini");
  80. extern void __attribute__ ((section (".fini"))) _fini (void);
  81. void
  82. _fini (void)
  83. {
  84. /* End of the _fini prolog. */
  85. __asm__ ("ALIGN");
  86. __asm__ ("END_FINI");
  87. __asm__ ("\n/*@_fini_PROLOG_ENDS*/");
  88. /* Xtensa: It doesn't really matter whether GCC thinks this is a leaf
  89. function or not, and the scripts that are supposed to remove the
  90. call don't catch the literal, resulting in an undefined symbol
  91. reference. */
  92. #if 0
  93. {
  94. /* Let GCC know that _fini is not a leaf function by having a dummy
  95. function call here. We arrange for this call to be omitted from
  96. either crt file. */
  97. extern void i_am_not_a_leaf (void);
  98. i_am_not_a_leaf ();
  99. }
  100. #endif
  101. /* Beginning of the _fini epilog. */
  102. __asm__ ("\n/*@_fini_EPILOG_BEGINS*/");
  103. SECTION (".fini");
  104. }
  105. __asm__ ("END_FINI");
  106. /* End of the _fini epilog. Any further generated assembly (e.g. .ident)
  107. is shared between both crt files. */
  108. __asm__ ("\n/*@_fini_EPILOG_ENDS*/");
  109. __asm__ ("\n/*@TRAILER_BEGINS*/");
  110. /* End of file. */